bobthecow / psysh

A REPL for PHP

Home Page:https://psysh.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

History does not show long lines in full

ooglek opened this issue · comments

Problem

Sometimes I just type a lot without a newline. I know that PSYSH supports hitting enter and it will intelligently continue accepting input until the input is ended.

Sometimes I paste code into PSYSH without considering the length of the line.

Today I typed in a long line. I wanted to run it again but with a small tweak. However, when I ran history --grep subscriptions though it did find my line, the line was truncated in a way that I could not copy and paste it and edit it. The line just ends with a simple >

>>> history --show 7732
7732: $a = $b->account->subscriptions()->create(["OrderType" => "fun", "CallbackSubscription" => ["URL" => "https://example.com>

This happens when I look at help and man pages too. No suggestions exist in the History docs.

note the > angle bracket at the end of the command line reference

>>> help history
Usage:
 history [-s|--show SHOW] [-H|--head HEAD] [-T|--tail TAIL] [-G|--grep GREP] [-i|--insensitive] [-v|--invert] [-N|--no-numbers] [--save SAVE] [--replay] [--c>

Aliases: hist

Am I missing something? My shell $PAGER is less -imnXesR and my iTerm2 window is 158 chars wide by 71 lines tall.

OK, so I found pager in the configuration.

--> php -i | grep -i pager
cli.pager => no value => no value

I'm using tmux and I wonder if that also causes interesting issues. I also use a shell script called lesspipe.sh that will automatically gzcat gzipped files and "prettyify" other files rather than just show plain text or forcing me to have to gzcat the file first to pipe to less.

It seems like if cli.pager has no value in the php.ini, and despite the Config Docs stating that the fallback is less it seems like something else is handling the paging, because if I specify /usr/bin/less (FreeBSD) as the pager in the config, it outputs all of the ANSI control characters when entering help history

If I change the PSYSH config to use 'pager' => 'less -minXesR' then things work and wrap as expected.

AH!

There it is.

public function __construct(StreamOutput $output, string $cmd = 'less -R -S -F -X')

You're truncating long lines by default.

   -S or --chop-long-lines
         Causes lines longer than the screen width to be chopped
         (truncated) rather than wrapped.  That is, the portion of a long
         line that does not fit in the screen width is not shown.  The
         default is to wrap long lines; that is, display the remainder on
         the next line.

The Fix

Remove the less -S flag from ProcOutputPager.php

Thanks for your thorough analysis! I agree, preventing wrapping via the default less arguments feels better than the current behavior. I've updated the defaults in 4d1f353, which will be in the next stable release.

Thanks for pushing this out! Hurrah!