Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> you can use `stty` to change a lot of stuff about the terminal, including how it deals with inputs

> You can rewire all of these defaults and behaviors

I've also found this article on implementing a terminal text editor to be illuminating:

https://viewsourcecode.org/snaptoken/kilo/

https://viewsourcecode.org/snaptoken/kilo/02.enteringRawMode...

Also, just in case anyone is wondering, as I once did, where many of these magical-looking stty parameters and symbols are coming from: they are control sequences defined a long time ago. A lot of stuff is defined in ambiguous old standards from the 70s such as ECMA-48 that include such arcane terminology not seen anywhere else.

For example, jargon like Select Graphic Rendition basically refers to a 70s version of the HTML <font> tag.

  SGR<params>TextSGR<0>
  <font params>Text</font>
Where params are something like 38/2 RGB to set foreground color. The parameter 0 clears the current style.

  ESC[38;2;R;G;BmTextESC[0m
  <font color="#RGB">Text</font>

         ESC = The literal ASCII escape character
  ESC[ = CSI = Control Sequence Introducer
  m    = SGR = Select Graphic Rendition
  38         = Set foreground color
  2          = Use the RGB color space
         RGB = Color
  0          = Reset style back to defaults
Parameters come before the command. Kind of backwards.

They even had the same implementation issues we have today with browsers. Terminals were and stil are inconsistent in what they implemented and how they did it. Stuff like colors is pretty well supported but many other features aren't. For example, SGR<7> is supposed to enable "negative image" mode, whatever that is. Standard doesn't really explain. Some terminals choose to do reverse video, other terminals do other equally valid things and to this day people have problems with it.



I like your comparison with browsers. In many ways, the only way to know for sure is to test in the desired terminals and figure out what works on all of them.

There's some "new" stuff as well (90's), like SIXEL graphics. I was surprised by how broad the support is (however not that broad to count on it).


Yeah. Even more recent efforts are the efforts to bring powerful features to terminals. Kitty in particular came up with many of them and had to deal with ncurses refusing to support it.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: