Re:Ink: React for interactive command-line apps
by Siilwyn on Sunday July 23, 2017 @03:46PM
(#14834009)
Think [react-blessed](https://github.com/Yomguithereal/react-blessed) comes close to what you're thinking of.
Re:Ink: React for interactive command-line apps
by thomasballinger on Sunday July 23, 2017 @06:49PM
(#14834809)
One optimization that's not hard to do for terminal output is a line cache: if a row is the same, don't render it. The rendering logic is probably already operating on lines, so this doesn't require the fancy diffing; but diffing a flat grid seems easier anyway vs the dom tree. For context, (I suspect parent already understands this) this is analogous to the vdom optimizations (not shouldComponentUpdate optimizations) possible with React. Except the algorithm is more straightforward: for each character on the grid, is the content the same since the previous render?
This library looks real neat, a declarative TUI with an api already familiar to many developers. I've thought this would be a neat thing to exist since I started using React after having written a similar declarative, redraw-only-as-necessary terminal rendering library for bpython (http://ballingt.com/bpython-curtsies/).
In it (http://curtsies.readthedocs.io/en/latest/) the only rendering optimization was a line cache. For the specific use case of an interactive interpreter this worked pretty well: once a line is changing, it's probably changing a lot. But you could go further using the output of diffing of arrays of terminal text.
edit: whoa https://github.com/Yomguithereal/react-blessed looks awesome for this
Re:Ink: React for interactive command-line apps
by xiaq on Sunday July 23, 2017 @03:03PM
(#14833833)
If you keep an internal representation of the terminal (which you should totally do when building a terminal toolkit), you can just update whatever changed. It is not hard with cursor positioning sequences.
Seeing that it doesn't use ncurses, I'm suspicious of how it does re-draws. I'd imagine the naive thing of just redrawing every bit of text on the screen for every reactive event would work, but be pretty slow. Of course, if they're doing something smarter than this, I'd be interested to hear how it's done.