[HN Gopher] Show HN: Rich-CLI - A CLI toolbox for highlighting, ...
       ___________________________________________________________________
        
       Show HN: Rich-CLI - A CLI toolbox for highlighting, Markdown, JSON
       and rich text
        
       Author : willm
       Score  : 75 points
       Date   : 2022-01-31 16:56 UTC (6 hours ago)
        
 (HTM) web link (github.com)
 (TXT) w3m dump (github.com)
        
       | amanzi wrote:
       | This is great as a general replacement for the `cat` command,
       | especially with the `-n` argument to add line numbers.
        
       | chme wrote:
       | Looks similar to bat: https://github.com/sharkdp/bat
        
       | willm wrote:
       | Hi HN,
       | 
       | This is a command line tool I've been working on for rendering
       | various types of content in the terminal.
       | 
       | The core functionality is syntax highlighting with line numbers
       | and indent guides.
       | 
       | It can render Markdown (commonmark), and does a reasonable job
       | given the limitations of Terminal emulators.
       | 
       | It can render JSON with syntax highlighting.
       | 
       | Finally it can display general purpose rich text with "console
       | markup" (like bbcode).
       | 
       | All of the above can have borders, styles, alignment applied
       | independently.
       | 
       | This was written hastily, the majority of it came together over a
       | single weekend. This is because it was built with Rich (a Python
       | library which I am also the author of) which does the heavy
       | lifting.
       | 
       | Currently you can install it as a Python package, but I plan on
       | adding it to other channels so you can get it via your preferred
       | package manager.
       | 
       | I know there are some excellent apps with equivalent features but
       | I'm hoping this will become a versatile tool for developers (in
       | particular). I'll be adding more formats in the future.
       | 
       | Hope you find it interesting. I'll be around for a while to
       | answer questions.
        
         | baggiponte wrote:
         | How do you add a new line? I tried
         | 
         | $ rich --print "\n hello world"
         | 
         | but it just returned
         | 
         | \n hello world
         | 
         | Also, where can I find the list of emoji and the correspondent
         | ":description:"?
        
         | simonw wrote:
         | Progress bar support would be really interesting - providing a
         | neat way to add progress bars to shell scripts that do a bunch
         | of work.
         | 
         | Not sure how to go about designing a CLI tool that adds
         | progress bars to things that might involve executing other
         | shell commands though - I guess "pv" is good prior art here.
        
           | willm wrote:
           | This is good idea. Will investigate how to pipe data and
           | display a progress bar at the same time.
        
           | pletnes wrote:
           | tqdm already does this. It's also a python package.
           | 
           | https://tqdm.github.io/docs/cli/
        
             | simonw wrote:
             | That's awesome - I've used tqdm as a Python library before
             | (mainly within Jupyter notebooks) but I hadn't spotted that
             | CLI version of it.
        
         | pletnes wrote:
         | Can it render git diffs / git difftool?
        
           | willm wrote:
           | Nope, but that would be a nice addition.
        
       | jpm48 wrote:
       | This is going to be useful for many things in my teaching. I've
       | just got my students to install Rich / textual for my python
       | coding course as I've featured it as one of my Modules of the
       | week.
       | https://nccastaff.bournemouth.ac.uk/jmacey/msc/PipeLineAndTD...
       | So this will come in handy. Great work.
        
         | willm wrote:
         | Thanks. Hope your students also enjoy it!
        
           | jpm48 wrote:
           | One thing that may be nice is a pager mode. If you feed into
           | more or less with a pipe you loose the syntax highlight.
        
             | willm wrote:
             | You can add --force-terminal to avoid stripping ANSI codes.
             | But you're right, a built in pager would be nice.
        
       | josephg wrote:
       | This looks great! I'd love something like this for the rust code
       | I've been working on lately. Does anyone know of a similar
       | library in rust?
        
       | simonw wrote:
       | I really like the potential this has to add more compelling
       | output to simple shell scripts:                   #!/bin/bash
       | rich "Starting process" --rule --rule-style "red"         # ...
       | do some stuff         rich "Process [b]complete[/b]" -p -c
       | --padding 1 --style "on blue"
        
         | tinalumfoil wrote:
         | Couldn't you do something like this instead?
         | echo "$(tput setaf 1)Starting process$(tput sgr0)"         echo
         | "  $(tput setaf 2)Process $(tput bold)complete$(tput sgr0)"
        
         | baggiponte wrote:
         | I have been looking for something like this for a long time T.T
        
       | baggiponte wrote:
       | That's beautiful! Maybe adding tab completions would be useful?
       | For example:
       | 
       | $ rich "hello world" -p -a <TAB> ...
       | 
       | Where "..." is all the possible values that can be taken in.
        
         | willm wrote:
         | I think Click can do that. I'll look in to it for the next
         | version.
        
           | baggiponte wrote:
           | So you are using Click and not Typer?
        
             | willm wrote:
             | That's right. I would usually reach for Typer for CLIs. I
             | chose Click because I wanted to extend the ---help and I
             | wasn't certain If Typer exposed the internals.
        
             | simonw wrote:
             | Typer uses Click under the hood.
        
               | baggiponte wrote:
               | Yeah, that I knew: why Click over Typer? Greater control
               | in creating the CLI?
        
       | [deleted]
        
       | [deleted]
        
       | patrick91 wrote:
       | This looks great! Congrats on shipping! My only nit is that it
       | needs some paddings
        
         | willm wrote:
         | What kind of paddings?
        
       | mr-karan wrote:
       | [rich](https://news.ycombinator.com/item?id=29945848) was
       | recently discussed as well.
        
       ___________________________________________________________________
       (page generated 2022-01-31 23:01 UTC)