Comments (6)
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
from rich-cli.
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
from rich-cli.
Why are you rendering the output of ps
as markdown? What output are you expecting?
from rich-cli.
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.
from rich-cli.
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.
from rich-cli.
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.
- first remove the spaces before
PID
column by something likesed 's/\s*PID/PID/i'
- then replace all blank space with
,
withtr
to make output CSV-like - then pipe it to rich-cli with
--csv
option
ps \
| 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! 👍
from rich-cli.
Related Issues (20)
- List of every supported filename extensions HOT 2
- Feature request: support setting `--hyperlinks` via the `RICH_HYPERLINKS` environment variable HOT 3
- --width / --max-width in SVG export don't affect the width of the picture HOT 1
- head / tail operations are slow on larger files
- Provide help for pager
- No lexer fo csv HOT 4
- Multiple emoji encoding issues on Windows HOT 3
- Is it possible to format outputs of commands executed? HOT 4
- feature request: pv equivalent progress bar (using --size) feature HOT 4
- Rich capturing mouse movements from stdin
- Rich as a drop-in replacement for "more"/"less" HOT 1
- Reused option name: -j is used for both JSON and emoji options HOT 2
- Unable to install latest textual and rich-cli together HOT 1
- Align title to the left in markdown HOT 2
- Feature request: Allow tailing a CSV HOT 2
- `rich --print` always adds an extra newline
- How to set background color inside strings should be documented better HOT 1
- Exposing Text.from_ansi in rich-cli HOT 1
- Feature request: horizontal padding HOT 1
- please detect encoding before opening a file
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rich-cli.