dbcli / litecli

CLI for SQLite Databases with auto-completion and syntax highlighting
https://litecli.com
BSD 3-Clause "New" or "Revised" License
2.12k stars 68 forks source link

How to specify max column width to avoid breaking output ascii table formatting? #63

Closed mightymiff closed 4 years ago

mightymiff commented 5 years ago

Disclaimer:I am a sqlite newbie.

When the contents of my query fields are long, it breaks the default formatting of the ascii tables of the output from litecli in my terminal. The separators do not line up and the output is basically unreadable.

Is there a way to specify the max column width for query output to avoid this, or some other mechanism by which this might be achieved?

Thanks.

amjith commented 5 years ago

Yes. We use the default pager to display the tables. When the table is too wide the pager might try to wrap the lines making it unreadable.

There are two ways to handle this.

  1. Use vertical output, which will display results in a vertical format instead of the tabular format. You can trigger this by add \G at the end of your query.

eg:

/home/amjith/History> select * from urls limit 2 \G                                                                                                                      
***************************[ 1. row ]***************************
id              | 3
url             | https://drive.google.com/
title           | Google Drive
visit_count     | 17
typed_count     | 11
last_visit_time | 13185914782626610
hidden          | 0
***************************[ 2. row ]***************************
id              | 15
url             | https://web.whatsapp.com/
title           | WhatsApp
visit_count     | 105
typed_count     | 39
last_visit_time | 13187629519053067
hidden          | 0
  1. You can change the pager setting to not wrap the lines. I typically use \P less -SXRF. This will set the pager to use less -SXRF.

You can make these permanent via the config file: https://litecli.com/config/

Look for the option called auto_vertical_output which will automatically switch to the vertical mode whenever the output doesn't fit in the screen.

You can also set the pager setting in your config file. Look for the pager option.