|
|
|
|
|
by 2211
2710 days ago
|
|
There's no library to handle all of this for you ('ncurses' etc). It has to all be done manually by hand. This involved scouring through VT100 and other terminal manuals to figure out escape sequences and other terminal behavior. Also the installation of something like 30~ terminal emulators to make sure the escape sequences behaved everywhere. I stuck to VT100 sequences (which are supported pretty much everywhere nowadays) with the exception of 1 or 2 newer sequences (which are ignored in older terminals and not required). I didn't want to use 'tput' since it would add the dependency of 'ncurses' and it would slow the program down quite a lot. Each 'tput' call is an external process which adds '10-15ms' to the program per call. I also ran into some funny bash behavior. The main loop waits for user input (with 'read') and if the script received a 'SIGWINCH' signal that ran a second 'read' asynchronously, it would break the terminal. The other big issue is you can't write anything widely portable in bash without supporting bash '3.2+' (which is over 10(?) years old at this point). macOS is forever stuck on this version due to Apple's issues with GPLv3. This means useful features like associative arrays, 'declare -n' etc are unavailable for use. Other than these issues it wasn't that difficult to pull off. It was a lot of fun actually! |
|