kellyjonbrazil / jtbl

CLI tool to convert JSON and JSON Lines to terminal, CSV, HTTP, and markdown tables
MIT License
289 stars 9 forks source link

Print rows in each line #8

Closed mailsanchu closed 2 years ago

mailsanchu commented 2 years ago

This will help large tables without truncating

kellyjonbrazil commented 2 years ago

Hi there!

Have you tried the -n option, which disables truncation and wrapping?

You can use it in conjunction with the -S option in less to view long rows without wrapping.

$ cat data.json | jtbl -n | less -S

Hope that helps!

mailsanchu commented 2 years ago

Please see the attached screenshot and you will understand what I mean image

kellyjonbrazil commented 2 years ago

How would multiple rows work in this case? Would there be a blank line and then the next row of data would be printed - one row per column? This doesn't seem much different than pretty-printing the JSON itself.

mailsanchu commented 2 years ago

Yes it pretty printing json in a tabular format without the curly brackets

kellyjonbrazil commented 2 years ago

Interesting. I could do something like add an -r option that will "rotate" the data and print multiple single-line key-value pair tables. Thanks for the suggestion!

mailsanchu commented 2 years ago

I think that will do it.. Thanks

kellyjonbrazil commented 2 years ago

I have a working prototype. Does something like this work?

$ jc -a | jq .parsers | jtbl -r
item: 0
key             value
--------------  ------------------------
name            acpi
argument        --acpi
version         1.3
description     `acpi` command parser
author          Kelly Brazil
author_email    kellyjonbrazil@gmail.com
compatible      ['linux']
magic_commands  ['acpi']

item: 1
key             value
--------------  ---------------------------
name            airport
argument        --airport
version         1.4
description     `airport -I` command parser
author          Kelly Brazil
author_email    kellyjonbrazil@gmail.com
compatible      ['darwin']
magic_commands  ['airport -I']

item: 2
key             value
--------------  ---------------------------
name            airport_s
argument        --airport-s
version         1.5
description     `airport -s` command parser
author          Kelly Brazil
author_email    kellyjonbrazil@gmail.com
compatible      ['darwin']
magic_commands  ['airport -s']

item: 3
key             value
--------------  -------------------------------------
name            arp
argument        --arp
version         1.8
description     `arp` command parser
author          Kelly Brazil
author_email    kellyjonbrazil@gmail.com
compatible      ['linux', 'aix', 'freebsd', 'darwin']
magic_commands  ['arp']

<SNIP>

item: 24
key           value
------------  -----------------------------------------------
name          hash
argument      --hash
version       1.3
description   `hash` command parser
author        Kelly Brazil
author_email  kellyjonbrazil@gmail.com
compatible    ['linux', 'darwin', 'cygwin', 'aix', 'freebsd']

item: 25
+----------------+------------------------------------------------------------+
| key            | value                                                      |
+================+============================================================+
| name           | hashsum                                                    |
+----------------+------------------------------------------------------------+
| argument       | --hashsum                                                  |
+----------------+------------------------------------------------------------+
| version        | 1.2                                                        |
+----------------+------------------------------------------------------------+
| description    | hashsum command parser (`md5sum`, `shasum`, etc.)          |
+----------------+------------------------------------------------------------+
| author         | Kelly Brazil                                               |
+----------------+------------------------------------------------------------+
| author_email   | kellyjonbrazil@gmail.com                                   |
+----------------+------------------------------------------------------------+
| details        | Parses MD5 and SHA hash program output                     |
+----------------+------------------------------------------------------------+
| compatible     | ['linux', 'darwin', 'cygwin', 'aix', 'freebsd']            |
+----------------+------------------------------------------------------------+
| magic_commands | ['md5sum', 'md5', 'shasum', 'sha1sum', 'sha224sum', 'sha25 |
|                | 6sum', 'sha384sum', 'sha512sum']                           |
+----------------+------------------------------------------------------------+

It respects all the same wrapping/truncating/columns arguments as well.

mailsanchu commented 2 years ago

It looks good to me

kellyjonbrazil commented 2 years ago

I have published jtbl version 1.2.0 that includes this feature. Enjoy!

mailsanchu commented 2 years ago

Tested and it works. I prefer without borders but that is ok

kellyjonbrazil commented 2 years ago

I agree - I was able to remove the borders for the rotate view in v1.2.1. It's now up on PyPi. Thanks!

mailsanchu commented 2 years ago

You are a super listener. I will check and update here

mailsanchu commented 2 years ago

I tested this and works perfectly. One small suggestion is If there is only one item, hide the item: 0 header.

kellyjonbrazil commented 2 years ago

Yeah, that makes sense - I can fix that today. Thanks!

kellyjonbrazil commented 2 years ago

Do you like the item header the way it is or would you like it to stand out more? say something like:

$ jc -a | jello _.parsers[5:7] | jtbl -r
--- Item: 0 ---
name            cksum
argument        --cksum
version         1.3
description     `cksum` and `sum` command parser
author          Kelly Brazil
author_email    kellyjonbrazil@gmail.com
compatible      ['linux', 'darwin', 'cygwin', 'aix', 'freebsd']
magic_commands  ['cksum', 'sum']

--- Item: 1 ---
name            crontab
argument        --crontab
version         1.6
description     `crontab` command and file parser
author          Kelly Brazil
author_email    kellyjonbrazil@gmail.com
compatible      ['linux', 'darwin', 'aix', 'freebsd']
magic_commands  ['crontab']
mailsanchu commented 2 years ago

Item:5 -------------------------------------------------------------------------- FULL SCREEN $COLUMNS in bash key value I think some think like the above

kellyjonbrazil commented 2 years ago

Like this? (dashes go the entire column length)

$ jc -a | jello _.parsers[5:7] | jtbl -r
item: 0
------------------------------------------------------------------------------------------------------------
name            cksum
argument        --cksum
version         1.3
description     `cksum` and `sum` command parser
author          Kelly Brazil
author_email    kellyjonbrazil@gmail.com
compatible      ['linux', 'darwin', 'cygwin', 'aix', 'freebsd']
magic_commands  ['cksum', 'sum']

item: 1
------------------------------------------------------------------------------------------------------------
name            crontab
argument        --crontab
version         1.6
description     `crontab` command and file parser
author          Kelly Brazil
author_email    kellyjonbrazil@gmail.com
compatible      ['linux', 'darwin', 'aix', 'freebsd']
magic_commands  ['crontab']
mailsanchu commented 2 years ago

Yes . What do you think?

kellyjonbrazil commented 2 years ago

Yeah, I think it looks good. Cool, thanks for your suggestions!

kellyjonbrazil commented 2 years ago

This is up on v1.2.3 now. Enjoy!

mailsanchu commented 2 years ago

Thanks and a happy Christmas. I will not disturb you for a month as I am on holidays :)

kellyjonbrazil commented 2 years ago

Merry Xmas!