mkaz / termgraph

a python command-line tool which draws basic graphs in the terminal
MIT License
3.14k stars 165 forks source link

A flag to swap labels and values in the input (Unix "uniq" compatibility) #94

Open maxim-kukushkin opened 2 years ago

maxim-kukushkin commented 2 years ago

Termgraph looks like an amazing tool and it could be really useful for some ad-hoc investigations.

When looking at the logs and other texts it's often useful to run some-command | sort | uniq -c which counts unique entries and prints the list of unique values and the number of occurrences. For example:

     16 alter
     17 create
     15 drop
     12 insert
      8 update

Termgraph would fit nicely into this use case, like some-command | sort | uniq -c | termgraph. The issue is that termgraph always expects the label to go first. Of course in the example above it can be solved with Awk for example (like | awk '{print $2, $1}', however first of all it's an extra step (which reduces usability), and also it makes it problematic if the label contains a space.

That said, it would be awesome to have a CLI flag for termgraph like --values-first, which would tell termgraph to read the value in the first column and use the rest of the line as a label.

It would allow termgraph to be used seamlessly in the example above and also provide extra flexibility in other use cases which can use a similar input format

maxim-kukushkin commented 2 years ago

A pull request has been raised to add this functionality: https://github.com/mkaz/termgraph/pull/95