New ask Hacker News story: Fast and portable keyboard/mouse terminal handler in pure shell script

Fast and portable keyboard/mouse terminal handler in pure shell script
2 by alganet | 0 comments on Hacker News.
Quick demo: bash -c "$(curl -L https://git.io/fjToH)" To exit, use CTRL+W Piping will not work! Please use the subshell above. When open, type anything or move the mouse in the terminal. Code is less than 500 lines. Uses mostly standard POSIX shell and does detection when using non-standard stuff. Tested on multiple shells and terminals in multiple OSs. zsh, bash, ksh93, mksh and xterm, mintty, WSL, Terminal.app, Termux. The trick for the speed is to use `stty -tostop` which allows background jobs to send output to the terminal, then issue atomic changes to the screen in background and let the shell itself decide the order. ksh variants are particularly performant and stable with this technique. Other shells almost got support: posh and dash miss the `read -n` option which allows reading input byte per byte. yash is too slow to track mouse. Busybox, oil shell, mrsh were not tested. Ion and fish are largely POSIX incompatible so I didn't bother. It's a prototype, so it has no API for making your own stuff. It's mostly designed to prove that complex , dynamic TUIs are possible using pure scripting. I'd love some feedback on compatibility and performance! Thank you. Gist Page: https://ift.tt/2V1zPuj

No comments