piotrmurach / tty-prompt

A beautiful and powerful interactive command line prompt
https://ttytoolkit.org
MIT License
1.47k stars 136 forks source link

prompt.debug does not work in tmux when prompt.select is in the code #116

Closed DannyBen closed 4 years ago

DannyBen commented 5 years ago

Describe the problem

When using prompt.debug in a terminal with tmux panels stacked one on top of the other, the debug message is not displayed when using prompt.select anywhere in the code - probably due to some screen height calculation issues. Without prompt.select in the code, the debug message is shown properly.

Steps to reproduce the problem

  1. Install tmux (sudo apt-get install tmux)
  2. Start tmux: $ tmux
  3. Split the screen to two horizontal panels: Press Ctrl+b+"
  4. Run the below code:
require 'tty-prompt'

prompt = TTY::Prompt.new

prompt.debug "Hello"

# Does NOT show debug message in tmux panel
prompt.select "Can we see it?", [:yes, :no]

# DOES show debug message in tmux panel
# Comment the select above and uncomment this one
# prompt.ask "Can we see it?"

Actual behaviour

Debug message is not shown at the top right corner unless removing the prompt.select line.

Expected behaviour

Expecting to see debug message on the top right corner even when inside tmux panel.

Describe your environment

piotrmurach commented 4 years ago

Hi Danny,

I cannot reproduce this behaviour. It works fine in both vertical and horizontal tmux panels when using the select and multi_select prompts. The Hello is printed in the top right corner when navigating the selections.

DannyBen commented 4 years ago

I think I know why - give me a few minutes, to try and reproduce more clearly.

DannyBen commented 4 years ago

Found the reason.

The above reproduction steps work, assuming your cursor is at the very bottom of the screen.

When there is a select control, it prints multiple lines and the "hello" is probably positioned before tty-prompt knows how many lines it will display, so the debug message is pushed up outside of the screen.

Here is a screencast: https://asciinema.org/a/283351

You can see the hello printed even when the select is used, but only briefly, and then it is pushed outside the screen.

Now that I understand the problem, I am not even sure it is easy to solve.

if not - feel free to close the issue.

piotrmurach commented 4 years ago

Ah, I see. The debug message gets printed first in the top right corner but then "disappears" as the selection prompt pushes it up by the very amount of lines needed to display the prompt. The ask prompt doesn't do it as it is printed on the same line. The simplest thing I can think of right now is to provide an option :offset which would adjust the display, by let's say the size of choices list?

DannyBen commented 4 years ago

The simplest thing I can think of right now is to provide an option :offset which would adjust the display, by let's say the size of choices list?

That's an option, but debug messages like this are supposed to be a quick, thoughtless command we throw in when we need to debug. Perhaps it would make sense to display at the bottom-right corner instead?

(Unless you meant that this :offset happens automatically?)

piotrmurach commented 4 years ago

Yup I agree, I added debug to help me to debug issues quickly. I was selfish here 😄 I didn't plan for this to be public API.

As for printing it at the bottom, I think I tried that but the problem was that the select clears a whole line and potentially would wipe out the debug message. Do you have time to try it out? Happy to accept a patch if it works. Alternatively, it could be displayed at the one line above the current line, so we wouldn't worry about moving screen and the debug message being wiped out.

DannyBen commented 4 years ago

Whatever works. Now that I now why it happens, I can easily still debug, by just ensuring I clear the screen first, so it will not scroll. Your call.

piotrmurach commented 4 years ago

Changed it to work with the current line - it's in master but I won't have time to release. Have plenty of things to do including trying to wrap up a release of strings-inflect.