3 ms·
> you actually need to fully model the rendering behavior of a PTY I think 'input contains control sequences' can be filed away along with 'input contains vert
by moonchild 5y ago
> you actually need to fully model the rendering behavior of a PTY
I think 'input contains control sequences' can be filed away along with 'input contains vertical tab' as 'you're on your own, kid'.
Just handling newlines and tabs is relatively trivial. I think it's even a k&r exercise.
> libncurses works at all, while dealing with all of this
ncurses filters out escape sequences. You can, too (which is probably a nicer approach than attempting to model them).
- derefr 5y agoIt filters out escape sequences on input, yes. But ncurses does generate its own escape sequences (obviously, that's how it does what it does); and so it still has to have a full internal PTY <-> what-a-terminal-emulator-would-do mapping model for what it itself has emitted to the screen, in order to be able to do "damage region" repainting correctly without e.g. suddenly making some text lose color because it jumped to a "display cell" that actually corresponds in the PTY stream to both the text and some SGR escape codes.
- moonchild 5y ago> suddenly making some text lose color because it jumped to a "display cell" that actually corresponds in the PTY stream to both the text and some SGR escape codes Not how the terminal works. Try this: printf " \e[34mhiii\r\e[0mxx\n" This: - Prints a space - Switches to blue - Prints hiii - Moves to the left of the screen - Turns off all attributes - Prints 'xx' (such that the cell where the colour started has definitely been overwritten) This should result in a default-coloured 'xx' followed by blue 'iii'. You do not need a complete model of the terminal. All you need is calculate dirty regions -> redraw them line-by-line in the naive manner. SGR escapes aren't associated with specific cells; you can think of them as commands to the terminal. 'Set your default foreground colour to ...' They could as easily go along a separate channel (barring synchronization overhead, etc.).