★ wanayoo — archive 1999 https://github.com/dbcli/pgcli/issues/399Nouvelle recherche | Portail wanayoo
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pager breaks cli history with wide output? #399

Closed
pik opened this issue Oct 26, 2015 · 19 comments
Closed

Pager breaks cli history with wide output? #399

pik opened this issue Oct 26, 2015 · 19 comments

Comments

@pik
Copy link

@pik pik commented Oct 26, 2015

I'm not sure if there is a configurable setting to fix this but the default is insanely bad. Scrolling up I have dozens of screens that look like this (when using arrow keys to horizontal scroll the warped columns, which essential destroys the ability to scroll up and see query history).

screen shot 2015-10-26 at 4 59 20 pm

@amjith
Copy link
Member

@amjith amjith commented Oct 26, 2015

It is configurable.

pgcli will honor your $PAGER env variable. So you can launch pgcli as follows:

PAGER=cat pgcli

That sets the PAGER env var to cat. Which will pipe the output through cat instead of less, which would solve the history scrollback.

Alternatively, you can set PAGER to more to still keep some of the functionality of scrolling but it won't do horizontal scrolling.

@pik
Copy link
Author

@pik pik commented Oct 26, 2015

Thanks for the response. The problem isn't the horizontal scrolling in less, it's that the less output is written to the same display as the pgcli repl. If you run psql with the same settings (using PAGER=less) the output is contained in a separate display and is hidden after the user exists less (likewise ipython %edit magic etc.).

screen shot 2015-10-26 at 5 26 12 pm

screen shot 2015-10-26 at 5 26 34 pm

@amjith
Copy link
Member

@amjith amjith commented Oct 26, 2015

Yes. I chose a specific set of less options to make it behave the way it does right now. I completely understand that this won't be desirable to everyone.

I'll take that into consideration for the future release and provide a way to override that behavior.

@pik
Copy link
Author

@pik pik commented Oct 26, 2015

@amjith aren't the less defaults (SXRF) not being applied there? Would something like this fix it (let me know if I'm misunderstanding something):

def adjust_less_opts(self):
    less_opts = os.environ.get('LESS', '-SRXF')
    return less_opts
@amjith
Copy link
Member

@amjith amjith commented Oct 26, 2015

The code as it is now, reads the current value set in LESS env var and stores it away. Then overrides the LESS env var by setting it to -SRXF. The reason I store it away is because I want to restore it to the original value chosen by the user upon exit. Done here: https://github.com/dbcli/pgcli/blob/master/pgcli/main.py#L427

The reasoning behind this decision is that an average user is unlikely to have set their LESS env var to a specific value.

So pgcli tries to set some sane values for LESS options. This has served well up until now.

Your suggested correction is a good compromise. It won't stomp the user value (assuming the user has deliberately set it to their choosing).

Would you mind making that a PR?

@pik
Copy link
Author

@pik pik commented Oct 26, 2015

I made a patch pik@ad6687f - but I am reconsidering it's usefulness now -- primarily because less will function somewhat differently within pgcli than it does on terminal.

I guess there are two issues here: One is custom less flags which atm can be configured using \pager less <custom_flags> but could use a permanent home. And the other is sanely displaying both multi-screen (horizontally non-fitting output) and regular output along with session history.

Looking at how psql handles this when a pager is configured -- it seems they use a native print (?) for lines that fit the screen and switch to the pager when the output does not fit the screen; less when run without -X will hide the output when it returns to the prompt -- which I find quite a bit more sane, since their way of reprinting the view on each horizontal scroll is really quite broken. Unfortunately it does not seem possible (if there is some shell magic I'm missing for this it would be good to know) to selectively trigger -X (e.g. only -X if -F was triggered, so results that fit into one screen can still be displayed).

Still, following psql it would be nice to offer an output option based on whether the lines exceed terminal length or not -- e.g. there could be a config option such as PAGE_EXCEEDING_MAX_WIDTH_ONLY -- in which case perhaps pgcli could do something like this:

terminal_size = shutil.get_terminal_size()
if terminal_size and terminal_size.columns > len(max(output[0].split('\n'))):
    click.secho('\n'.join(output))
else:
    click.echo_via_pager('\n'.join(output))
@amjith
Copy link
Member

@amjith amjith commented Oct 26, 2015

I'm not sure I entirely follow your request. So let me rephrase it to see if I understand it correctly.

You'd like to show the output via less but in a different screen so whenever you press q it will clear the screen.

I think that can be achieved using the -c flag.

One of the advantages of rewriting pgcli from scratch is I don't have to recreate the mistakes made by psql. So I don't think following psql behavior in using a custom display for short lines and pager output for long lines is a good approach.

@pik
Copy link
Author

@pik pik commented Oct 26, 2015

I think it will always clear if you don't use the -X flag?

So I don't think following psql behavior in using a custom display for short lines and pager output for long lines is a good approach.

The thing is that while having visible output in a session is very useful, the way less reprints horizontally scrolled output makes viewing prior history in a session nearly impossible that is to say I would prefer to hide it in those specific cases. (I'm not saying this should be a default behaviour but it would be quite nice to have that option).

@amjith
Copy link
Member

@amjith amjith commented Oct 26, 2015

the way less reprints horizontally scrolled output makes viewing prior history in a session nearly impossible

Ah, got it. That was introduced by the -S flag. If you don't include that then you won't get the horizontal scrolling.

@pik
Copy link
Author

@pik pik commented Oct 26, 2015

I think I'm doing a very bad job explaining, sorry - the table formatting will break if you wrap the lines and the horizontal scroll is quite useful - the problem is what happens to the session when the less output stays in pgcli - I've uploaded a gif which hopefully helps
pgcli_horizontal_scroll

@amjith
Copy link
Member

@amjith amjith commented Oct 26, 2015

I finally get what you're saying. A picture is indeed worth a thousand words. :)

Let me summarize it. If the output fits in the screen (horizontally) then show the output in the screen and keep it there. If the output is wider than the screen then use the separate screen and clear the screen when the user quits the pager. Is that an accurate assessment?

If so, it can be achieved by setting the less options to -RXF when the output fits the screen, when the output doesn't fit the screen then use -SRF and omit the '-X' is that right?

I believe that is possible. Because we recently implemented \x auto feature which will detect if the output fits in the screen horizontally and switches to expanded mode output if it doesn't fit the screen. We can use the same logic to determine which less options to use in each case.

@blendmaster
Copy link

@blendmaster blendmaster commented Jun 8, 2017

I'm still having this problem the problem in the gif in #399 (comment) ; each time I scroll horizontally in paged output, the output gets "stuck" into the scrollback, unlike psql where closing the paged output makes it disappear entirely. I have \x auto on, but I'd still like to be able to scroll horizontally in cases.

@tsroten
Copy link
Member

@tsroten tsroten commented Jun 8, 2017

@blendmaster You'll want to remove the -X flag from your LESS environment variable:

$ export LESS="-SRF"

Then give it a try :)

If you want the change to be permanent, you'll want to put that line in your .bashrc or .zshrc file.

@blendmaster
Copy link

@blendmaster blendmaster commented Jun 8, 2017 •

Hmm, no luck with explicitly setting LESS, even on an empty /bin/sh profile, just in case anything was weird about my zsh setup.

$ pgcli --version
Version: 1.6.0
$ python --version
Python 2.7.12
$ python3 --version
Python 3.5.2
$ less --version
less 481 (GNU regular expressions)
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.2 LTS"

the pager within psql works fine still.

@tsroten
Copy link
Member

@tsroten tsroten commented Jun 8, 2017 •

@blendmaster Ah, my bad, I forgot that pgcli overrides LESS. I'm sorry about that! We'll see what we can do to fix this.

@amjith @j-bennet Do you think we should make it like mycli where it only overrides LESS if it doesn't exist?

@amjith
Copy link
Member

@amjith amjith commented Jun 8, 2017

Yes. I think we should use the LESS var if it's available.

My bad for forcibly overriding it in the code. 😞

@pik
Copy link
Author

@pik pik commented Jun 8, 2017 •

I had a PR that fixed this (amongst other things awhile ago) #409

Personally I've given up on using pgcli and went back to psql, because the display of output is incredibly bad for a number of common cases (this is just one of them) and there doesn't seem to be much interest in getting it fixed.

@amjith
Copy link
Member

@amjith amjith commented Jun 8, 2017

@pik I'm sorry you felt discouraged by the output. We are making progress in that front. I did steal many of the ideas from your PR and integrated it into pgcli. I'm sorry I couldn't merge in the full PR as it stood.

We will be making the pager configurable by the user and not override the LESS variable if set by the user. I know @tsroten recently made that change to mycli which we plan on porting over to pgcli.

I completely understand that pgcli didn't measure up to your expectation and you had to go back to psql. I wouldn't mind learning about the common cases where it failed to display the output appropriately.

@j-bennet
Copy link
Contributor

@j-bennet j-bennet commented May 5, 2019

I'm closing this, because we do not force a specific PAGER and LESS anymore.

@j-bennet j-bennet closed this May 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.