Closed johnsamuelwrites closed 2 years ago
Why are you rendering the output of ps
as markdown? What output are you expecting?
As a table (a rendering similar to that with --csv option). I also tried the following:
ps |rich - -m --csv
This gives the same output as above.
The output of ps isn't markdown, so I'm not surprised it wouldn't render. The output can't be markdown and CSV at the same time (the combination of those two switches should really be an error).
The output isn't a CSV either. So I'm afraid there is not much that rich-cli can do about that.
Just found this while looking for something similar, so just wanted to post a workaround to how to use rich-cli to nicely format ps output.
PID
column by something like sed 's/\s*PID/PID/i'
,
with tr
to make output CSV-like--csv
optionps \
| sed 's/\s*PID/PID/i' \
| tr -s '[:blank:]' ',' \
| rich - --csv
Outputs:
┏━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┳━━━━━━┓
┃ PID ┃ TTY ┃ TIME ┃ CMD ┃
┡━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━┩
│ 14142 │ pts/19 │ 00:00:00 │ ps │
│ 14143 │ pts/19 │ 00:00:00 │ sed │
│ 14144 │ pts/19 │ 00:00:00 │ tr │
│ 14145 │ pts/19 │ 00:00:00 │ rich │
│ 22162 │ pts/19 │ 00:00:01 │ bash │
└───────┴────────┴──────────┴──────┘
For completeness, since I just looked at the same thing for kubectl
output:
kubectl get pods | tr -s '[:blank:]' ',' | rich - --csv
Outputs your pods with Rich CSV table formatting as:
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━┳━━━━━┓
┃ NAME ┃ READY ┃ STATUS ┃ RESTARTS ┃ AGE ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━╇━━━━━┩
│ cert-manager-cainjector-abcdefghij-54321 │ 1/1 │ Running │ 0 │ 11h │
│ cert-manager-klmnopqrs-12345 │ 1/1 │ Running │ 1 │ 11h │
│ cert-manager-webhook-fedcba9876-6565 │ 1/1 │ Running │ 0 │ 5h │
│ nginx-ingress-ingress-nginx-controller-123456789a-bcdef │ 2/2 │ Running │ 0 │ 11h │
│ nginx-ingress-ingress-nginx-controller-123456789a-fedcb │ 2/2 │ Running │ 42 │ 15h │
└─────────────────────────────────────────────────────────┴───────┴─────────┴──────────┴─────┘
It could of course be nice if rich-cli had an option to also accept white space separated output tables directly (like we get from a lot popular of command line tools, like docker
, kubectl
, ps
, etc.), e.g.:
kubectl get pods | rich - --table
Or as I interpret the initial question/suggestion in this issue:
kubectl get pods | rich - --separator=whitespace
Anyways, thanks for a very nice CLI tool! :+1:
Thanks @audunsol for your solution. I like to see the output of ps
in colors, thanks to rich-cli. Thanks @willmcgugan for this work.
.
I want to test with other Linux commands.
Yes, I was looking for something similar to rich - --separator=whitespace
The above cool way to format ps output using rich did not work for me. That is because my process ids were not all the same length so the tr put some commas at the beginning of some lines which made the output not valid csv.
I modified the sed part to remove all leading and trailing whitespace from all lines. That seemed to work:
ps | sed 's/^[ \t]*//;s/[ \t]*$//' | tr -s '[:blank:]' ',' | rich - --csv
On running the following command
I got the following output
So rich-cli is able to inspect the first line (header) correctly, but not the subsequent lines.
Without rich-cli, I got the following output:
Tested with commands like netstat.
One possible solution could be to allow the users to specify the delimiters.
I am wondering whether this could be a bug, since rich-cli is able to detect the first line.