dbcli / litecli

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

Unecessary usage of pager #94

Open FreddieOliveira opened 3 years ago

FreddieOliveira commented 3 years ago

Description

Sometimes, even when the command output fits on the screen, it is displayed by the pager.

Steps to reproduce

  1. Open chinook db in litecli and enter the pragma table_info('albums') command

Expected behavior

The output should be displayed without being handled by the pager, since it fits on the screen

Actual behavior

The output is displayed on fullscreen by the pager program

amjith commented 3 years ago

I'm not able to reproduce this, can you tell me what pager you're using?

You can check the env var $PAGER or $LESS in your terminal.

I presume you're using linux, if you're on windows, you might want to install less.exe and use that as your pager.

FreddieOliveira commented 3 years ago

Hey @amjith, thanks for the response. I'm on Linux using less as pager. What's causing the problem is the fact that this line

https://github.com/dbcli/litecli/blob/11c87dbf7b13f5e9b8f713ff9f0efe39062ccc17/litecli/main.py#L648

in the output method is comparing the screen width with each formated line of the output without ripping the formatting of. What I mean is, when calculating the length of a line which has colorful text, it takes the escape sequences as if it was part of the line. For example, the header of the output select * from media_types, is considered to be

'| \x1b[38;5;47;01mMediaTypeId\x1b[39;00m | \x1b[38;5;47;01mName\x1b[39;00m                        |'

instead of simply

| MediaTypeId | Name                        |

To check that, add print(bytearray(line, 'utf-8')) right after the for loop, run the program and run a command with colorful output:

Screenshot_20200822-182246_Termux