7 ms·
Rich Tables in the Terminal
- zemnmez 6y agothis is awesome! Terminal programs are so satisfying, but at the same time it always feels like they miss so many primitives that I take for granted for content display
- willm 6y agoThat was my main motivation in working in Rich. Whenever I move from the frontend to the backend, I miss what the browser can do so effortlessly.
- yjftsjthsd-h 6y agoSo, it is cool; let me say that much before I criticize. That said: live resizing a table is a bit of a pain if you're trying to select something (to copy or to highlight it to show someone else). It's like a webpage that moves a link just as you click. Is there any way to fix the width and append only to the end? (Just optionally; I understand why it resizes dynamically by default)
- willm 6y agoThe animation is purely for demonstration purposes. Generally you would use this to render a formatted table as the result of a CLI.
- 1996 6y agoIF you want to add other things to the CLI, like graphics or unicode, check this library: https://gitlab.com/klamonte/jexer https://gitlab.com/klamonte/jexer
- dredmorbius 6y agoBest suggestion I've seen is for the interface to respond to what was at the point of interaction ~300ms before the click or touch action.
- easterncalculus 6y agoRich is great. Have been using it for a couple of projects and the support is great, even on terminals with less color support.
- xixixao 6y agoThis makes me think how close this is to HTML output + DOM rendering, and what would be the proc and cons of each, how could you get max pros of the CLI approach into the HTML approach.
- willm 6y agoMy goal was to bring some of the capabilities of HTML to the console. The browser is always going to win in terms of capabilities.
- gonewb 6y agoIs this using ncurses?
- detaro 6y agodoesnt seem so
- sxp 6y agohttps://github.com/willmcgugan/rich/blob/master/rich/console.py#L501 https://github.com/willmcgugan/rich/blob/master/rich/console... shows that's it's directly using escape codes: http://ascii-table.com/ansi-escape-sequences-vt-100.php http://ascii-table.com/ansi-escape-sequences-vt-100.php
- eepp 6y agolooks like it hardcodes escape sequences with no regard to the current terminal.
- JdeBP 6y agoIt's not using ncurses nor terminfo, but it's very misleading to point to a list of VT100 escape sequences when it most definitely is not doing things the VT100 way either. 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.
- teddyh 6y agoThis seems to only support rendering. If you also want interactive use, another library which does things like this is Urwid: http://urwid.org/examples/ http://urwid.org/examples/
- cthonicthulu 6y agoI originally looked at Urwid for a side project I was working on, but it seemed a bit heavyweight for the kind of prototyping I wanted to do. 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/vdtui.py https://github.com/saulpw/visidata/blob/stable/visidata/vdtu...
- anjakefala 6y agoDo you have a link to the tool you built with vdtui? =)
- oblio 6y agoHe he! Souped up IBM PC box drawing characters, circa 1981: https://en.m.wikipedia.org/wiki/Box-drawing_character https://en.m.wikipedia.org/wiki/Box-drawing_character
- ishcheklein 6y agoThis looks awesome! Gonna try to use it for DVC where we need to show tables of experiments, metrics, etc.
- miguelmota 6y agoThis is sweet. Is there an equivalent of this library for Go? Particularly with scrolling support
- omani 6y agoIm using https://github.com/olekukonko/tablewriter https://github.com/olekukonko/tablewriter in Go.
- bluedays 6y agoI started using this in a project of mine a few days ago and I highly recommend this library. It is super intuitive and easy.
- kureikain 6y agoCan It detect non terminal output and render normal ascii such as when pipe/redirect stdout/stderror to a file? or pipe to seed and avoid messing up with color code. 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 :-(
- willm 6y agoYes, Rich will remove escape sequences when not writing to a terminal.
- spudlyo 6y agoman 3 isatty 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.
- JdeBP 6y ago* https://github.com/willmcgugan/rich/blob/837b6d7e85254f0047cb41a4cbe0e4b00f54809d/rich/console.py#L435 https://github.com/willmcgugan/rich/blob/837b6d7e85254f0047c... Note that it is possible to respect TERM=dumb without using termcap or terminfo, although this library does not do that.
- the8472 6y agoThis may be heresey, but does it support mouse interaction, e.g. sorting by clicking on the column header like midnight commander does?
- willm 6y agoNo, the animation was for demo purposes. It’s not normally dynamic.
- dang 6y agoRelated from a few months ago: https://news.ycombinator.com/item?id=23070821 https://news.ycombinator.com/item?id=23070821
- enricozb 6y agoThose progress bars look delicious
- reaperducer 6y agoI agree. Also: My kingdom for rsync with progress bars.
- yjftsjthsd-h 6y ago--progress ?
- mattatkeyboard 6y agoNaff tables (along with poor graphs) was one of my key motivations to create WV Linweise, which spawns a tiny web renderer to make displays nicer... Love the terminal, but some things it is just not great at... This mini example app renders CSV data from STDIN into a HTML tables - https://github.com/forbesmyester/wv-linewise/tree/master/examples/discover-types https://github.com/forbesmyester/wv-linewise/tree/master/exa...
- a_t48 6y agoThat traceback handler is awesome. I wonder if there's a way to hook all my python programs to use it.
- chameleon_world 6y agoYou can, the instructions are here: https://rich.readthedocs.io/en/latest/traceback.html https://rich.readthedocs.io/en/latest/traceback.html But it is noticeably slower than the default python handler
- a_t48 6y agoSlower in what way? Just on crash? I don't mind that. But I meant for programs I _don't_ typically write source for - if Python has a way to run code before every program start up it would do what I want.
- willm 6y agoIts slower when it renders the traceback, all that reading of source and syntax highlighting takes second or two. There is a way of importing something automatically, see the sites module docs.
- cosmotic 6y agoThis seems to be begging the question: At what point does one move to a GUI? GUIs are well suited for these tasks.
- makecheck 6y agoTerminal features work better across all platforms than most GUIs. They are more likely to have efficient keyboard commands for everything. And if (say) you wanted to Copy arbitrary text from anywhere in the terminal, you can (a GUI would have to explicitly support Copy for the things it presents). Clearly GUIs have a place but terminal UIs are really powerful.
- cosmotic 6y agoGUIs are much more consistent across platforms than terminal features. Windows look and behave consistently but DOS vs BASH are totally different. 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.
- cryptonector 6y agossh, mosh
- cosmotic 6y agoxwindows, rdp, vnc
- 2ion 6y agokitty terminal has built-in extensions to xterm terminal protocol extensions to make this kind of thing much easier, toda. Hacking the terminal is nice but another way is moving forward in developing it.
- Anthony-G 6y agoThis looks really impressive: elegant and beautiful with an easy-to-use API. I don't know if submission titles can be edited 9 hours after posting but this would be an excellent addition to Show HN and might get more attention as such. https://news.ycombinator.com/showhn.html https://news.ycombinator.com/showhn.html