News for hackers. Stuff that matters.
Re:Entering text in the terminal is complicated by colmmacc on Monday July 08, 2024 @07:43PM (#40911005)
Over 20 years ago now I wrote a state machine around readline that meant you could use it as a multi-line editor. Not "multi-line" as in a single line can wrap, but a true editor that lets you move up and down, but is windowless.

Here's a video:

    https://github.com/colmmacc/jot/raw/master/jot-demo.mp4
and the CVS repository for the Unix terminal IM client it is part of is at:

    https://c-hey.redbrick.dcu.ie/src/c-hey_cvs_latest/
It tracks and redraws your cursor when you move up and down between lines, and also pays attention to SIGWINCH to redraw things when the terminal size changes. I've never had the time to rewrite it in Rust, but I'd like to and then release it as a small library.

It's always surprised me that nobody else has done this.

Re:Entering text in the terminal is complicated by Willish42 on Monday July 08, 2024 @08:40PM (#40911414)
This was fascinating!! Please do consider bringing it back to life as a library and sharing with HN.

I had no idea how much better such an editing experience is until your video, and completely agree about the benefit of not having to context-switch a la git commit "interactive mode". The "inline typewriter" effect is also really cool

Re:Entering text in the terminal is complicated by Pr0ject217 on Monday July 08, 2024 @09:36PM (#40911728)
Checked out the video. Looks cool!
Re:Entering text in the terminal is complicated by jxy on Monday July 08, 2024 @10:55PM (#40912117)
Yeah. That's how rio's text windows [0] look like in hold mode, except that it has a much simpler design and better support of mouse.

[0] https://p9f.org/magic/man2html/1/rio

Re:Entering text in the terminal is complicated by atiedebee on Tuesday July 09, 2024 @03:57AM (#40913586)
Oh, that looks really cool! Is the current iteration of the program stable?
Re:Entering text in the terminal is complicated by marttt on Tuesday July 09, 2024 @05:39AM (#40914130)
Thanks for the screencast. Another +1 for bringing it back to life!
Re:Entering text in the terminal is complicated by JNRowe on Tuesday July 09, 2024 @01:53PM (#40918952)
That's pretty cool, gonna steal the idea.

I can implement that specific case with a couple of lines in zsh. Something like:

    autoload -Uz zed
    icommit() {
      () {
        zed $1
        git commit -F $1  # -a too, if you must ;)
      } =(:)  # Or maybe even =(< commit_template.txt)
    }
Then icommit, via zed¹, will initiate an inline editor with all the power of ZLE available. Hit C-x C-w to write and commit, or C-c to abort. Obviously, you'd want some error checking and the like².

Beauty of this basic implementation is that the keymap is fully controllable in zed as it is simply a new ZLE widget. It works with emacs or vi mode out of the box, and is fully customisable beyond that.

You could make the interface generic by writing your own ZLE widget, so that it can be called directly from within the line editor and remove the need for wrapping commands like I did above.

¹ https://github.com/zsh-users/zsh/blob/master/Functions/Misc/...

² This at least uses, and cleans up, a temp file to handle the commit message so it isn't completely useless.