zee-editor / zee

A modern text editor for the terminal written in Rust
Apache License 2.0
1.48k stars 42 forks source link

Is Zee overriding the default cursor? #27

Open tommythorn opened 2 years ago

tommythorn commented 2 years ago

I had a hard time finding the cursor in Zee and noticed it wasn't using my terminal (eg. macOS Terminal) default cursor, but uses its own. Is this intentional? Is there a way to make it use the terminal cursor?

mcobzarenco commented 2 years ago

Thanks for issue -- indeed, zee uses the terminal in raw mode and disables the tty cursor.

I would love to help though, would you be so kind to go into some detail about what the issue is? Is it unexpected that the cursor doesn't look the same? Is it a styling consideration?


Raw mode with no tty cursor has many advantages, i.e. you get complete control over what's displayed on the screen + allows accurate incremental repainting that the tty cursor would interfere with. I did start by trying to use the tty cursor early on, but found it to be super limitative, buggy and causing it flickering when repainting incrementally. By painting my own cursor, the behaviour is cross-platform and works the same regardless of terminal emulator, as well as allow for correct handling of wide unicode graphemes or compound graphemes correctly (which most emaulators don't handle correctly most of the time), multiple cursors, box selection etc. etc. AFAIK, emacs does the same, but may have a config option not to..

For more context, the terminal is actually abstracted away, zee renders to a rectangular "canvas" containing of what I call "textel"s (i.e. a grapheme together with associated text styling and a background and foreground colors). This is handled by https://github.com/mcobzarenco/zi . The editor is not really aware of the backend we render to, one thing this will enable down the line is to support a GPU accelerated version, similar to how emacs' GUI verison.

tommythorn commented 2 years ago

highly unusual; I can't think of a single example where when entering text, we aren't using the terminal cursor. The examples that spring to mind: bash (any shell really), nano, vi, emacs -nw, gpg. Examples without a cursor (but also aren't entering text): top, htop

It's literally the point of the cursor to point out were you are entering text. Arguing about customization is a very zee-centric view of the world - I don't want to have to customize it, I already customized the terminal and that covers all the interactive apps.

I think it's broken, but it's very easy to fix.

cessen commented 2 years ago

highly unusual ... I think it's broken,

Not the author, but I disagree that it's broken or especially unusual. As just a couple of examples, Kakoune and Helix are both terminal-based editors that draw their own cursors.

Now, whether that's a preferable approach or not is certainly up for debate (and somewhat depends on use case--e.g you can't do multiple cursors with the tty cursor). But calling it broken and/or highly unusual seems hyperbolic to me.