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

Psysh add ~0XXX~1 when pasting codes #636

Closed
starvsion opened this issue May 12, 2020 · 17 comments
Closed

Psysh add ~0XXX~1 when pasting codes #636

starvsion opened this issue May 12, 2020 · 17 comments

Comments

@starvsion
Copy link

Version:

Psy Shell v0.10.4 (PHP 7.4.5 — cli)

Problem:

When pasting in psysh, it adds ~0 at the begging of string , and ~1 at the end of string

@bobthecow
Copy link
Owner

Can you paste the output of Psy\info()?

@emcarson
Copy link

Hi, I'm having the same problem. Here is the output of Psy\info():

Psy Shell v0.9.12 (PHP 7.4.4 — cli) by Justin Hileman
>>> Psy\info();
=> [
     "PsySH version" => "v0.9.12",
     "PHP version" => "7.4.4",
     "OS" => "Linux",
     "default includes" => [],
     "require semicolons" => false,
     "error logging level" => 32767,
     "config file" => [
       "default config file" => null,
       "local config file" => null,
       "PSYSH_CONFIG env" => false,
     ],
     "loop listeners" => [
       "Psy\ExecutionLoop\ProcessForker",
     ],
     "commands" => [
       "help" => "Psy\Command\HelpCommand",
       "?" => "Psy\Command\HelpCommand",
       "ls" => "Psy\Command\ListCommand",
       "list" => "Psy\Command\ListCommand",
       "dir" => "Psy\Command\ListCommand",
       "dump" => "Psy\Command\DumpCommand",
       "doc" => "Psy\Command\DocCommand",
       "rtfm" => "Psy\Command\DocCommand",
       "man" => "Psy\Command\DocCommand",
       "show" => "Psy\Command\ShowCommand",
       "wtf" => "Psy\Command\WtfCommand",
       "last-exception" => "Psy\Command\WtfCommand",
       "wtf?" => "Psy\Command\WtfCommand",
       "whereami" => "Psy\Command\WhereamiCommand",
       "throw-up" => "Psy\Command\ThrowUpCommand",
       "timeit" => "Psy\Command\TimeitCommand",
       "trace" => "Psy\Command\TraceCommand",
       "buffer" => "Psy\Command\BufferCommand",
       "buf" => "Psy\Command\BufferCommand",
       "clear" => "Psy\Command\ClearCommand",
       "edit" => "Psy\Command\EditCommand",
       "sudo" => "Psy\Command\SudoCommand",
       "history" => "Psy\Command\HistoryCommand",
       "hist" => "Psy\Command\HistoryCommand",
       "exit" => "Psy\Command\ExitCommand",
       "quit" => "Psy\Command\ExitCommand",
       "q" => "Psy\Command\ExitCommand",
       "clear-compiled" => "Illuminate\Foundation\Console\ClearCompiledCommand",
       "down" => "Illuminate\Foundation\Console\DownCommand",
       "env" => "Illuminate\Foundation\Console\EnvironmentCommand",
       "migrate" => "Illuminate\Database\Console\Migrations\MigrateCommand",
       "optimize" => "Illuminate\Foundation\Console\OptimizeCommand",
       "up" => "Illuminate\Foundation\Console\UpCommand",
       "inspire" => "Illuminate\Foundation\Console\ClosureCommand",
     ],
     "updates" => [
       "update available" => true,
       "latest release version" => "v0.10.4",
       "update check interval" => "never",
       "update cache file" => "~/.config/psysh/update_check.json",
     ],
     "pcntl" => [
       "pcntl available" => true,
       "posix available" => true,
     ],
     "readline" => [
       "readline available" => true,
       "readline enabled" => true,
       "readline service" => "Psy\Readline\GNUReadline",
       "readline library" => "EditLine wrapper",
     ],
     "history" => [
       "history file" => "~/.config/psysh/psysh_history",
       "history size" => null,
       "erase duplicates" => null,
     ],
     "docs" => [
       "manual db file" => null,
       "sqlite available" => true,
     ],
     "autocomplete" => [
       "tab completion enabled" => true,
       "custom matchers" => [],
       "bracketed paste" => false,
     ],
   ]

Thanks.

@bobthecow
Copy link
Owner

that sounds kind of like bracketed paste, but per your psy\info() output, it's disabled. try adding 'useBracketedPaste' => true to your psysh config?

@emcarson
Copy link

Thank you @bobthecow. I went to try the solution but the problem had sorted itself out. Looks like restarting the computer did the trick.

I'm working on a Linux Mint 18.3 machine with Vagrant and Virtualbox (Ubuntu 18.0.4), on a Laravel project (which uses Psysh for the "artisan tinker" command). Before posting I tried halting/starting the virtual machine (to no avail).

Thanks again!

@bobthecow
Copy link
Owner

If it pops back up again, feel free to raise it :)

@francislavoie
Copy link

francislavoie commented Sep 22, 2020

I'm having problems with this. 🤔

>>> \Psy\info()
=> [
     "PsySH version" => "v0.10.4",
     "PHP version" => "7.4.10",
     "OS" => "Linux",
     "default includes" => [],
     "require semicolons" => false,
     "error logging level" => 32767,
     "config file" => [
       "default config file" => null,
       "local config file" => null,
       "PSYSH_CONFIG env" => false,
     ],
     "loop listeners" => [
       "Psy\ExecutionLoop\ProcessForker",
     ],
     "commands" => [
       "help" => "Psy\Command\HelpCommand",
       "?" => "Psy\Command\HelpCommand",
       "ls" => "Psy\Command\ListCommand",
       "dir" => "Psy\Command\ListCommand",
       "dump" => "Psy\Command\DumpCommand",
       "doc" => "Psy\Command\DocCommand",
       "rtfm" => "Psy\Command\DocCommand",
       "man" => "Psy\Command\DocCommand",
       "show" => "Psy\Command\ShowCommand",
       "wtf" => "Psy\Command\WtfCommand",
       "last-exception" => "Psy\Command\WtfCommand",
       "wtf?" => "Psy\Command\WtfCommand",
       "whereami" => "Psy\Command\WhereamiCommand",
       "throw-up" => "Psy\Command\ThrowUpCommand",
       "timeit" => "Psy\Command\TimeitCommand",
       "trace" => "Psy\Command\TraceCommand",
       "buffer" => "Psy\Command\BufferCommand",
       "buf" => "Psy\Command\BufferCommand",
       "clear" => "Psy\Command\ClearCommand",
       "edit" => "Psy\Command\EditCommand",
       "sudo" => "Psy\Command\SudoCommand",
       "history" => "Psy\Command\HistoryCommand",
       "hist" => "Psy\Command\HistoryCommand",
       "exit" => "Psy\Command\ExitCommand",
       "quit" => "Psy\Command\ExitCommand",
       "q" => "Psy\Command\ExitCommand",
     ],
     "updates" => [
       "update available" => false,
       "latest release version" => "v0.10.4",
       "update check interval" => "never",
       "update cache file" => "~/.config/psysh/update_check.json",
     ],
     "pcntl" => [
       "pcntl available" => true,
       "posix available" => true,
       "use pcntl" => true,
     ],
     "input" => [
       "interactive mode" => "auto",
       "input interactive" => true,
     ],
     "readline" => [
       "readline available" => true,
       "readline enabled" => true,
       "readline service" => "Psy\Readline\GNUReadline",
       "readline library" => "EditLine wrapper",
       "readline name" => "psysh",
     ],
     "output" => [
       "color mode" => "auto",
       "output decorated" => null,
       "output verbosity" => "normal",
     ],
     "history" => [
       "history file" => "~/.config/psysh/psysh_history",
       "history size" => null,
       "erase duplicates" => null,
     ],
     "docs" => [
       "manual db file" => null,
       "sqlite available" => true,
     ],
     "autocomplete" => [
       "tab completion enabled" => true,
       "bracketed paste" => true,
       "custom matchers" => [],
     ],
   ]

@bobthecow what else should I try to fix it?

This isn't solved by rebooting for me, I've had this problem on my laptop for a few months now. I'm not sure what's triggering it.

Running Ubuntu 20.04, didn't do much in terms of config, it happens in any terminal emulator (stock gnome one, pantheon-terminal, kitty)

It is fixed by turning off useBracketedPaste, but I do prefer to have it on.

@bobthecow
Copy link
Owner

In your case, it looks like it's some confusion between libedit and readline. Per psy\info your system is using the "EditLine wrapper", but picked "GNUReadline" as its Readline implementation in PsySH.

Unfortunately, this likely means you can't use bracketed paste as, IIRC, it's not supported in libedit. But we can sort out why PsySH let you enable it without proper readline. I bet, somehow, you ended up with readline_list_history defined, which is what we use to distinguish between full and partial readline implementations.

Run this in PsySH and let me know what it says?

ls --functions --internal --grep readline_list_history

@francislavoie
Copy link

francislavoie commented Sep 25, 2020

>>> ls --functions --internal --grep readline_list_history
Internal Functions: readline_list_history

🤔

$ php -i | grep readline
/etc/php/7.4/cli/conf.d/20-readline.ini,
readline
$ php -i | grep Readline
Readline Support => enabled
Readline library => EditLine wrapper

Took a look at the Libedit isSupported() code...

>>> \function_exists('readline')
=> true
>>> !\function_exists('readline_list_history')
=> false
>>> \Psy\Readline\Libedit::isSupported()
=> false
>>> \Psy\Readline\GNUReadline::isSupported()
=> true
>>> readline_info()
=> [
     "line_buffer" => "readline_info()\n",
     "point" => 18,
     "end" => 33,
     "library_version" => "EditLine wrapper",
     "readline_name" => "psysh",
     "attempted_completion_over" => 0,
   ]

My entire config for PsySH is this:

        $config = new Configuration([
            'updateCheck'       => 'never',
            'useBracketedPaste' => true,
        ]);
        $shell = new Shell($config);
        $shell->setIncludes($input->getArgument('include'));
        $shell->run();

Commenting out 'useBracketedPaste' => true, from my config does make paste work ok but there must have been a reason that I turned it on 🤔 I think I must have done it so paste worked on one machine but I guess it must've clobbered this one instead... I don't know anymore 😬

Edit: Yeah if I paste this into my terminal (two tabs) I get Display all 4809 possibilities:

[
		1
]

I was probably following the suggestion in #254 (comment) and turning on bracketed paste but it doesn't seem to behave well 😢

@bobthecow
Copy link
Owner

bobthecow commented Sep 25, 2020

Where are you getting it from if it's not internal?

show readline_list_history

Edit: just kidding it was internal. I misread.

@bobthecow
Copy link
Owner

bobthecow commented Sep 25, 2020

Alright, got it.

php/php-src#3824

As of PHP 7.4, it looks like they've implemented history with the libedit wrapper. Since, initially, the difference between our GNUReadline and Libedit implementations was whether we had first-class history support or we were emulating it, we used the presence of that function to decide which to use. As soon as it was implemented in Libedit, everything switched over to the GNUReadline implementation.

Later, when we added bracketed paste support, the logic switched on whether our readline implementation was GNUReadline. Which is the wrong thing to check, since now Libedit-based readline is also using that.

I'll have a fix shortly!

@bobthecow
Copy link
Owner

Unfortunately the fix will be that bracketed paste will not work at all for you 😢

@francislavoie
Copy link

francislavoie commented Sep 25, 2020

That sounds about right. I think I was using 7.3 on my other machine that didn't have this issue. Thanks!

Edit: does that mean that bracketed paste just won't work anymore in 7.4+? 🤔

@bobthecow
Copy link
Owner

No, it'll still work if you have proper readline rather than the libedit wrapper. The "fix" here is to stop letting the libedit wrapper trick PsySH into letting you enable bracketed paste support.

@francislavoie
Copy link

Hmm. It's odd that php-readline installs libedit on Ubuntu then 😢

bobthecow added a commit that referenced this issue Sep 25, 2020
As of PHP 7.4, the libedit-based readline implementation sometimes has history file support. When it does, PsySH will use the full "GNUReadline" implementation.

Unfortunately, we were also using that to determine whether we could allow bracketed paste. EditLine/libedit still hasn't added support for that, so we need to explicitly check whether we're using the real readline-based readline.

See #636
@bobthecow
Copy link
Owner

Yeah, it does. I think you might have to build from source to get actual readline.

@gituser
Copy link

gituser commented Oct 8, 2020

This is still an issue with PHP 7.4.10 with readline and Psy Shell v0.10.4.

To mitigate this issue, so your pasting works without ~0 XXX ~1 add this into your ~/.config/psysh/config.php:

// PsySH uses readline if you have it installed, because interactive input
    // is pretty awful without it. But you can explicitly disable it if you hate
    // yourself or something.
    //
    // If readline is disabled (or unavailable) then terminal input is subject
    // to the line discipline provided for TTYs by the OS, which may impose a
    // maximum line size (4096 chars in GNU/Linux, for example) with larger
    // lines being truncated before reaching PsySH.
    'useReadline' => false,

    // Enable bracketed paste support. If you use PHP built with readline
    // (not libedit) and a relatively modern terminal, enable this.
    'useBracketedPaste' => false,

If you only use:

// Enable bracketed paste support. If you use PHP built with readline
    // (not libedit) and a relatively modern terminal, enable this.
    'useBracketedPaste' => false,

There will be still and issue with ~0 ~1 when pasting into psysh terminal.

@bobthecow
Copy link
Owner

The fix mentioned above hasn't made it into a stable release yet. Install @dev and confirm that it works for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants