Pry in a non-stdin/stdout PTY uses incorrect output for pagination
Pry implicitly uses stdout for pagination, which is guaranteed incorrect when using pry in a non-stdout pty (ie. via PTY.open). It should use the configured output in that case.
Environment:
- ruby 2.6.2p47 (2019-03-13 revision 67232) [x86_64-linux]
- jruby 9.2.6.0 (2.5.3) 2019-02-11 15ba00b OpenJDK 64-Bit Server VM 25.201-b09 on 1.8.0_201-b09 +jit [linux-x86_64]
- pry (0.12.2)
- rb-readline gem with my PTY fixes: https://github.com/byteit101/rb-readline/tree/pty-fixes
- server/client scripts from https://bitbucket.org/byteit101/remotetty/src/default/
Setup (Terminal 1):
rvm use 2.6.2
gem install pry
git clone https://github.com/byteit101/rb-readline
cd rb-readline
git checkout pty-fixes
cd ..
hg clone https://bitbucket.org/byteit101/remotetty/
ruby -I rb-readline/lib remotetty/server.rb
Setup (Terminal 2):
ruby -I rb-readline/lib remotetty/client.rb
[1] pry(main)> ENV
[2] pry(main)>
Using MRI, I get the system pager less. Note that the pagination incorrectly appears in terminal 1 (the server).
(type q on terminal 1, then $pty_exit = true, enter, then ctrl-c on terminal 2 to exit)
Using JRuby, I get the pry simple pager. Note that the pagination correctly appears in terminal 2 (the client) in this case, and you can type enter/q for more, but note that https://github.com/pry/pry/blob/master/lib/pry/pager.rb#L116 directly assumes Readline is configured. I previously had a Readline2 with the pty, and Readline with stdio, which incorrectly requested input from Terminal 1 (the server). The current script works fine though, as I configured the global Readline class to use the pty.
Thanks for the detailed description. This seems to be a tough nut to crack. We pipe Pry output to less and apparently it runs on the server. I'm not sure how to use less on the client but any ideas are welcome.
Pry on JRuby always uses SimplePager. It doesn't shell out to less, so it works fine for your scenario. Perhaps, the correct solution would be preferring SimplePager in the client-server scenario or not paging at all.