298 points · by willm · 6y ago · 50 comments
I recently release a tool with a nice table but many hate the format, the color and it even make `grep` impossible because color code make grep match every line :-(
If you find yourself hard coding ANSI escape sequences in your program's output, please, please check to see if STDOUT is a tty first. This will prevent spewing escape sequences to a file.
For extra credit, please consider using tput() and friends to emit escape sequences rather than hard coding them. This may seem stupid when nearly every terminal in the world is now effectively an ANSI terminal, but sometimes vision impaired folks (and others) are using intentionally limited terminals with their type set to "dumb". Good programs respect this, and conditionally output their escape sequences.
Note that it is possible to respect TERM=dumb without using termcap or terminfo, although this library does not do that.
I ended up settling on Visidata's vdtui [1]. It's pretty strongly opinionated and there are a lot of batteries included, but on the plus side, you can get a pretty functional tabular CLI app working with very little code, and start focusing on your business logic rather than the scaffolding. I was pretty satisfied with it.
[1] https://github.com/saulpw/visidata/blob/stable/visidata/vdtu...
This mini example app renders CSV data from STDIN into a HTML tables - https://github.com/forbesmyester/wv-linewise/tree/master/exa...
Also: My kingdom for rsync with progress bars.
In contrast to the monochrome VT100 this is using colour quite significantly, albeit not supporting the recent corrections of a widespread mistake; and it even seems to support the rare framed and encircled attributes of later ECMA-48. Also in contrast to the VT100 it nowhere seems to deal in double-height or double-width, nor is it using ECMA-35 character set switching.
But it is noticeably slower than the default python handler
Clearly GUIs have a place but terminal UIs are really powerful.
I'm not sure what you mean by efficient keyboard commands. Command line programs are extremely inconsistent with regard to command line parameters, especially across platforms. They're inconsistent between common programs in Linux and between common programs on Windows.
Copying arbitrary text from a terminal is more rigid than a GUI; it's difficult to select with a keyboard, the text is unlikely to be formatted ( sometimes a good thing), and often what you want to copy isn't text but an image, sound, video clip, or some sort of object.
Powerful depends on what you mean by power. There exist somewhat-interoperable terminal programs, but there are lots of GUI programs that are as interoperable or even more interoperable and both can be scripted. Often requisite functionality is only exposed with a terminal program, but that has nothing to do with the lack of power of a GUI.