Rewrite of `screen` in Rust. Feedback and advice pls.
from CameronDev@programming.dev to rust@programming.dev on 17 Feb 23:21
https://programming.dev/post/25625074

I dunno if this is appropriate for this community, so mods, please delete if not.

I have been writing a screen clone in rust.

github.com/cameroncros/…/better_screen (The main branch is how I currently use it, not at all screen-like, the better_screen branch is much closer to a screen replacement.)

It all currently works fine, albeit quite simple, and I suspect not following best practices. Please talk shit about my code so I can fix that :D

For my next stage of development, I would like to use some combo of vt100 and ratatui to wrap the shell in a border, or add a menu bar at the top or bottom to make it clear when the user is inside a “screen”. Does anyone have any thoughts on how to go about doing that? I am very unskilled at ratatui.

#rust

threaded - newest

BB_C@programming.dev on 18 Feb 01:06 next collapse

If you’re serious about creating something good/better, you should use alacritty_terminal (not to be confused with the terminal app built on top of it) for low-level (from your PoV) terminal support.

This is something zellij didn’t do. And now they have “basic functionality” bugs like this one open for years.

I also wonder what made you pick screen as a baseline to improve on instead of tmux.

CameronDev@programming.dev on 18 Feb 01:34 next collapse

I’ll look into that, I’m currently just using cross term, which was enough to pass my rudimentary tests of nyancat. I’ll have to create some form of test suite to chuck various inputs at it and confirm it all works correctly.

Its definitely not intended to replace screen or be better, that would require a lot more features and work that I just dont want to do. Its for fun/scratching an itch.

I started it originally when I had issues with screen and permissions issues. The main branch is what I actually use, and I use it for running Minecraft servers. Its just an easy way to send commands to stdin of the process. (Stdout connected to regular stdout, stdin connected directly to a Unix socket).

As for tmux, most I’m not that familiar with it, and used screen more.

CameronDev@programming.dev on 18 Feb 08:30 next collapse

Well, your point stands regarding alacritty_terminal, but right now, it actually works just fine for that test case:

<img alt="" src="https://programming.dev/pictrs/image/5b496f9b-cc0e-4530-b1d6-445c70990dfa.png">

I suspect once I stop directing the raw input/output to the shell, it might become more important.

XTL@sopuli.xyz on 18 Feb 16:08 collapse

My first thoughts was also “Don’t. Clone tmux instead.” But don’t use ctrl-b. It’s a massively awkward and annoying combo on common keyboards. And don’t make it necessary to release ctrl before the second key.

BB_C@programming.dev on 18 Feb 16:44 collapse

But don’t use ctrl-b

What migrant from screen didn’t start by adding this to tmux config? 😄

set-option -g prefix C-a
unbind-key "C-b"
bind-key "C-a" send-prefix
livingcoder@programming.dev on 18 Feb 03:37 next collapse

I don’t know anything about screen. I think it would be great if you included a nice README.md file in the root of your repo for explaining what screen is and what your repo does both differently and the same. Please let me know if you do that. I’ll come and check out the repo at that point - kinda hard for me to want to jump directly into the code at the moment.

CameronDev@programming.dev on 18 Feb 04:02 next collapse

I had thought screen was pretty commonly known, but its a tool you can use to background and reconnect to a process, with the child process being completely separated from your shell. So you can ssh into a box, start a process with screen, and then logout, return later and reconnect. (It also does other stuff like read from serial consoles)

Codewise, there isnt a lot there, 3 main files (main.rs, server.rs and client.rs) all weighing in at ~200 lines.

It felt premature to add a readme at this stagr, as I dont see this as a complete thing yet, but I can add a readme later today.

livingcoder@programming.dev on 18 Feb 13:05 collapse

Thanks for the explanation and README. I’ll check it out.

some_guy@lemmy.sdf.org on 18 Feb 14:11 collapse

If you’re someone who might use this tool, you’re likely on a system that can run man screen. I agree that readme-s are useful. But just run man screen, find out what the tool is, be done. Otherwise, I think you’re asking the creator to do more work while I suspect you aren’t the target audience.

livingcoder@programming.dev on 18 Feb 18:41 collapse

That’s an interesting take. I didn’t know that the tool screen even existed, so I had no idea that it would be nice to have in my toolbelt for future needs. A README also helps those that may already know a lot about screen and want to know the differences between screen and their implementation.

There is nothing better in open source than a thorough, well-written README at the root of the project. Wanting others who don’t understand the source of the inspiration to be completely clueless is unfriendly (at best).

some_guy@lemmy.sdf.org on 18 Feb 20:39 collapse

I’m pointing out that there is information available without asking the creator to explain it rather than suggesting that a readme shouldn’t be created. In software development, one of the primary skills is knowing where to find information yourself before interrupting others. I’m not suggesting that one shouldn’t ask for help; quite the opposite. I’m just trying to provide an answer as a third-party who is not in a position to author a readme. I don’t consider that unfriendly.

dangling_cat@lemmy.blahaj.zone on 18 Feb 04:33 next collapse

Screen is actually way more powerful than just opening a persistent session on the server side. It’s a terminal multiplexer, and you can use it to manage not only normal tty, but also USB serial! By replacing screen are you also going to recreate all the options like baud rate and /dev/ttyUSB0?

CameronDev@programming.dev on 18 Feb 05:32 collapse

Yeah, its a bit of a mess, it does so much. The thing I wanted was just the persistent sessions, so probably not gonna go further than that. Of course, the code exists, and someone else is welcome to take it and run with it (I’ll give it a permissive licence eventually).

brian@programming.dev on 18 Feb 14:40 collapse

for the minimal use case this exists as well. github.com/crigler/dtach

CameronDev@programming.dev on 18 Feb 15:00 collapse

Lol, if only I had known about this a year ago, that’s exactly what I wanted/needed.

I guess I could change the topic name to “Rewrite of dtach in Rust” :/

lazynooblet@lazysoci.al on 18 Feb 07:51 next collapse

How is your version going to be “better”? Add a readme.md with your intended plan of features.

CameronDev@programming.dev on 18 Feb 08:06 collapse

The name of the branch is probably misleading, its not gonna be better than screen, it was meant to be better than my first attempt.

This is likely to never have any real use outside of my own personal usage.

lazynooblet@lazysoci.al on 18 Feb 08:31 collapse

Ah well, good luck!

CameronDev@programming.dev on 18 Feb 08:34 next collapse

@lazynooblet@lazysoci.al @livingcoder@programming.dev I have added a README.md.

livingcoder@programming.dev on 18 Feb 13:10 collapse

The README helped a lot, thanks. Just wanted to point out a minor typo, I think the second word under the “Client” section is meant to be the word “client”.

CameronDev@programming.dev on 18 Feb 13:43 collapse

Yup, good catch, rushed it out on the train. Will fix

[deleted] on 18 Feb 13:09 collapse

.