oils-for-unix / oils

Oils is our upgrade path from bash to a better language and runtime. It's also for Python and JavaScript users who avoid shell!
http://www.oilshell.org/
Other
2.85k stars 159 forks source link

terminal rendering by diff #693

Open andychu opened 4 years ago

andychu commented 4 years ago

From https://github.com/oilshell/oil/wiki/How-Interactive-Shells-Work

If a shell provides high-level support for this, layout and rendering can be performed by the shell but not by the shell scripts so that the shell scripts only have to specify the characters and their graphic attributes. If the shell provides the prompt calculation, it should also provide the cursor position information after the prompt is printed. The means to suppress/control the I/O of the original shell is also needed.

I think it's a little similar to React or Elm:

https://github.com/dwyl/learn-elm-architecture-in-javascript/issues/2

I think the low level is #682 . Raw hooks. And this is a higher level abstraction. You emit your own events, and those update the model. And then after the changes have propagated, then you diff it and render it in the terminal.

andychu commented 4 years ago

TODO: measure the performance vs. just clearing a bunch of lines and redrawing them?

I guess it saves bandwidth over SSH.

andychu commented 4 years ago

It looks like there a bunch of TUI libraries in Rust and Go that do this sort of thing:

https://github.com/fdehau/tui-rs (Rust)

The library is based on the principle of immediate rendering with intermediate buffers. This means that at each new frame you should build all widgets that are supposed to be part of the UI. While providing a great flexibility for rich and interactive UI, this may introduce overhead for highly dynamic content. So, the implementation try to minimize the number of ansi escapes sequences generated to draw the updated UI. In practice, given the speed of Rust the overhead rather comes from the terminal emulator than the library itself.

https://github.com/gizak/termui (Go)

I'm not sure how these work:

https://github.com/gdamore/tcell

https://github.com/nsf/termbox-go

andychu commented 4 years ago

This can use some help from anyone with experience :)