Show HN: Terminal Multiplexer Inspired by I3
The quality of a terminal multiplexor is is in part determined by the quality of the terminal emulation.  Unfortunately, this one leaves a lot out.<p>* The ECMA-35&#x2F;ECMA-48 escape sequence and control sequence processing is wrong.  It is a common error made by people who have read escape sequence lists, but the actual way to process output to a terminal involves a proper state machine, which handles <i>all</i> sequences, even unknown private ones.  ECMA-35 and ECMA-48 define ranges of Intermediate, Parameter, and Final characters.  One needs to handle the succession of such characters fully, otherwise one ends up like Konsole, which breaks when given some control sequences, erroneously displaying part of the control sequence as text.<p>* In that same vein, the actual code for CSI is U+009B.  The ESC plus open square bracket sequence is a 7-bit alias, from when the world was not 8-bit clean.  That 7-bit world hasn&#x27;t been the case since the late 1970s.  There is a whole range of control characters from U+0080 to U+009F.<p>* Continuing in that vein, the correct terminator for OSC is ST, U+009C.  There are moreover rules about ESC, CAN, SUB, CSI, OSC, PM, DSC, and so forth occurring partway through control sequences.<p>* Even more: The actual code for Reverse Index is U+008D.  The ESC plus M sequence is but another 7-bit alias.  For best results, translate the <i>entire</i> set of 7-bit aliases into the actual C1 control characters and handle them in their true 8-bit clean forms.  It&#x27;s a simple addition calcuation.  It&#x27;s silly that people write terminal emulators in the 21st century that are decades past the years of not being 8-bit clean, and that handle Unicode, that nonetheless still recognise only the 7-bit alias forms of escape and control sequences as if we still live in a 7-bit world.<p>* Just don&#x27;t work from the console_codes manual page for Linux.  At all.  That documents an idiosyncratic, very limited, and in some famous places <i>downright wrong</i> terminal emulator.  I set out explicitly to provide the feature set of that terminal emulator.  <i>You</i> should not have to.  Use ECMA-48, ECMA-35, and ITU T.416.<p>* Several years ago people started coming around to the reality that SGR 38 and SGR 48 were supposed to take colon-separated <i>sub</i>parameters, not semicolon-separated parameters.  The world has been gradually rectifying an almost 30-year-old error.  The correct source of information is ITU T.416, <i>not Wikipedia</i>.<p>* On the positive side, note that this terminal emulator does not have zero meaning default.  Zero means zero.  This is a good thing.  Zero meaning default went away entirely in 1991, and was superseded in 1986.  But note that various test programs haven&#x27;t progressed past 1976.  Particularly, note that several of the tests in vttest will fail when zero means zero.  (I myself just implemented Mode 22 for getting vttest to work, even though technically Mode 22 has been deprecated since 1991.)<p>* Although many modern terminal emulators agree on not providing blink any more, the <i>reason for</i> not supporting blink (wasted battery power continually blinking parts of a framebuffer) does not apply to something that renders onto an outer terminal rather than onto a GUI.  Let the outer terminal emulator make this decision.<p>* A lack of reverse video is a shame, and there isn&#x27;t a reason for not having it represented internally at least.  However, it is non-trivial to pass through.  Only Konsole really gets it right, and some terminal emulators get it profoundly wrong.  Interix cannot turn only it off, (U)RXVT decides to do something completely other than reverse video sometimes, and PuTTY erases using the wrong colour when reverse video is on.<p>* In that vein, note that several terminal emulators support subparameters to SGR 4 nowadays, giving different underline styles, including curly (SGR 4:3) and dotted (SGR 4:4) amongst others.  Mine does, as does kitty (not KiTTY).  The Windows Terminal people have it on their to-do list.<p>* You&#x27;ll find that there are still outer terminals that do not support SGR 38:5&#x2F;SGR 48:5 and there are still outer terminals that do not support SGR 38:2&#x2F;SGR 48:2.  One actually has to translate colour systems.<p>* &quot;hard refresh&quot; misses out a lot that a full-screen TUI program needs to do, from unsetting origin mode and margins, through resetting the cursor shape, to turning off automatic right margin and erase colour mode.<p>* People <i>will</i> complain about lack of DECSCUSR support.  VIM, NeoVIM, and others do make use of it, including several XTerm extensions to it.  And this <i>will</i> highlight the aforementioned deficiciencies in the control&#x2F;escape sequence processing model.  DECSCUSR is a CSI-begun control sequence with U+0020 as an intermediate character and U+0071 as the final character.<p>* People will complain about lack of scrolling region support, too.  Full-screen TUI applications that present windows&#x2F;panes redraw scrolls significantly less efficiently without it.<p>* Not handling ISO 2022 graphic sets is actually a feature, nowadays.  It&#x27;s a feature of Mosh (q.v.).  But again the partial escape sequence processing won&#x27;t handle this properly.  There are several Intermediate characters involved in the G0&#x2F;G1&#x2F;G2&#x2F;G3 designation escape sequences, not solely U+0028.  The state machine for decoding them needs to correctly decode all of the Intermediate, Parameter, and Final characters of such a sequence, too.<p>* Unfortunately, for full keyboard support -- particularly for (U)RXVT, the SCO Console (and derivatives), and Interix as the outer terminal -- one has to add non-standard extensions to ECMA-48.  Handling function keys sent from URXVT is particularly egregious.  (I myself actually use a patched URXVT, to remedy a couple of its more extreme problems, including a hardwired assumption of 10 function keys.)<p>* You really don&#x27;t want to ask the outer terminal for anything other than the new ECMA-48-conformant mouse reports (DEC Private Mode 1006) or the old DEC Locator reports.  The other report styles (1005 and 1015) have significant problems.  Vanilla URXVT is deficient in this regard, unfortunately.<p>* It&#x27;s actually ECMA-48 in <i>both</i> directions, outer terminal <i>input</i> in addition to outer terminal <i>output</i>.  DECFNK et al are valid ECMA-48 control sequences, with parameters and a final character.  It is a very common error to mishandle them with pattern matching and fixed buffer offsets, but it is an error nonetheless.  It&#x27;s an error that becomes very apparent whey trying to implement modifier recognition.  Learn from the pain that users  have configuring the recognition of modifiers in pattern-matching systems like GNU Readline, editline, or ZLE.  Make it parse ECMA-48 properly, so that parameter recognition in input control sequences <i>just works</i>.<p>* Deferred wrap should be cancelled by cursor motions.<p>* Tab stops are set by CTC and HTS.  They should not be fixed at every 8 columns.<p>* Passing the TERM environment variable straight through, whilst otherwise ignoring it, is going to cause no end of problems.