Code Monkey home page Code Monkey logo

Comments (6)

johnsamuelwrites avatar johnsamuelwrites commented on August 25, 2024 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.

test.

I want to test with other Linux commands.

Yes, I was looking for something similar to rich - --separator=whitespace

from rich-cli.

doctorfree avatar doctorfree commented on August 25, 2024 1

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.

willmcgugan avatar willmcgugan commented on August 25, 2024

Why are you rendering the output of ps as markdown? What output are you expecting?

from rich-cli.

johnsamuelwrites avatar johnsamuelwrites commented on August 25, 2024

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.

willmcgugan avatar willmcgugan commented on August 25, 2024

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.

audunsol avatar audunsol commented on August 25, 2024

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 like sed 's/\s*PID/PID/i'
  • then replace all blank space with , with trto 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.