cursive icon indicating copy to clipboard operation
cursive copied to clipboard

View for showing other TUI apps?

Open matthiasbeyer opened this issue 4 years ago • 9 comments

It would be nice if there was a View which can show other TUI apps... I particularly think about vim here, (but this is not related to #358 because in my case, vim would be opened inside of cursive, rather than replacing cursive temporarily).

This could then be used to build a tmux-like UI, for example, or even something like aerc where vim is used for composing emails inside of the TUI application itself.


Just a brain-dump, really.

matthiasbeyer avatar Jan 20 '20 12:01 matthiasbeyer

I think @IGBC has started experimenting with something a bit similar: https://github.com/igbc/cue Haven't looked much in there so I'm not sure how far the experiment went.

The brute-force solution I'm thinking about involves re-implementing a terminal emulator, forwarding events from cursive and printing the output as a View. Doesn't sound super easy, but maybe terminal emulator libraries (like VTE or VT-100) are easier to use than I fear? For example https://crates.io/crates/terminal-emulator is unmaintained, but extracting the terminal emulation logic from alacritty sounds nice.

gyscos avatar Jan 20 '20 19:01 gyscos

Correct, I started writing a 'desktop environment' in cursive. That was a stupid idea, but I did end up implementing a terminal emulator widget for cursive.

This was like 2 years ago and the first thing I wrote in rust, but I can check what state it is in and makeca PR to add the widget to cursive if people want it.

IGBC avatar Jan 20 '20 19:01 IGBC

This hasn't been run in well over a year but this is the code for my terminal emulator view:

https://gitlab.com/IGBC/CUE/blob/master/cue/src/views/term.rs (xpost to Gitlab where I keep my bigger projects.)

It should still work. should.

IGBC avatar Jan 22 '20 12:01 IGBC

Thank you for that! Pretty impressive to get something like that working with so few lines of code.

Note that a few edge cases may need some special effort to support properly:

  • Wide characters (chinese/japanese/korean)
  • Composed graphemes (more than one char per cell)
  • Right-to-left text (but that one is already broken in cursive, so...)

gyscos avatar Jan 27 '20 22:01 gyscos

Wide characters (chinese/japanese/korean) Composed graphemes (more than one char per cell) Right-to-left text (but that one is already broken in cursive, so...)

FWIW I needed to do something similar (not the actual terminal emulation part, but needed a TextGrid widget that could store an arbitrary combination of attributes and text in a grid), for this I re-used parts of https://github.com/agavrilov/cursive_buffered_backend/blob/master/src/lib.rs#L119

Each cell has a EnumSet<theme::Effect>, a theme::ColorPair and a SmallVec<[u8; 8]>, but can also be empty. Maybe it's not the most memory efficient way possible but also I think this handles these cases besides right-to-left text.

vmedea avatar Mar 05 '20 18:03 vmedea

Based of the idea listed in this issue, I am wondering how doable it is to make Cursive widgets, which are individually compiled into dynamic libraries, that can be loaded by other main running Cursive applications.

The widgets will all implement something like _widget_create(), and the view size and positioning management can be done akin to a tilling windows manager. reference for myself

Inc0n avatar Mar 30 '20 20:03 Inc0n

That would be nice, technically, but where's the actual benefit? Compiling everything into the binary that is shipped is less effort for the user and more security for the developer. So I don't see how this would yield any benefit.

But from a technical perspective, it would be nice, sure. Although I think that all plugins then need to be compiled with the same rustc version,...

matthiasbeyer avatar Mar 31 '20 07:03 matthiasbeyer

Compiling everything into the binary that is shipped is less effort for the user and more security for the developer. So I don't see how this would yield any benefit.

This is basically the rust core's approach to dynamic linking in general.

Generally speaking dynamic libs on Rust are "Kinda supported" but there's not a lot of information about it floating around as its super not recommended.

IGBC avatar Mar 31 '20 15:03 IGBC

Checkout https://github.com/deadpixi/mtm. Here is simple terminal emulator in less than 1000 lines of code. A TTYView can be added for handling nested TUI apps.

dzhang-b avatar May 13 '20 16:05 dzhang-b