You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Anything written to STDOUT while waiting for input from the user will not have a carriage return, which results in strange formatting of the data written to STDOUT.
Steps to reproduce the problem
To reproduce this, send multiple lines of data to STDOUT while waiting for some user input (ie. TTY::Prompt#ask).
t = Thread.new do
TTY::Prompt.new.ask('=>')
end
sleep 2
puts "one with no \\r"
puts "two with no \\r"
puts "three with no \\r"
puts "\rone with \\r"
puts "\rtwo with \\r"
puts "\rthree with \\r"
t.join
I thought this might have to do with malformed escapes for coloring, so I disabled color on the prompt and still had the same results.
Actual behaviour
=> one with no \r
two with no \r
three with no \r
one with \r
two with \r
three with \r
Expected behaviour
This is output from same code, except TTY::Prompt.new.ask('=>') has been replaced with print =>; readline
=>one with no \r
two with no \r
three with no \r
one with \r
two with \r
three with \r
Describe your environment
OS version: WSL2 Ubuntu (kernel 4.19.84-microsoft-standard)
Ruby version: 2.7.0p0
TTY version: 0.21.0
The text was updated successfully, but these errors were encountered:
This is consistent with how Ruby input works in the terminal raw mode. In order to process any keystroke, tty-prompt accepts input in a raw mode. Basically, the input is taken as is without any interpretation - a newline doesn't have any meaning apart from literal characters. This allows tty-prompt to provide nice editor behaviour like back and forward movement with arrow keys. You cannot do this in cooked mode. It's rather limited.
Here is your example changed to use raw mode:
t=Thread.newdo
$stdin.rawdoprint"=>"; $stdin.getcendendsleep2puts"one with no \\r"puts"two with no \\r"puts"three with no \\r"puts"\rone with \\r"puts"\rtwo with \\r"puts"\rthree with \\r"t.join
Which produces:
=>one with no \r
two with no \r
three with no \r
one with \r
two with \r
three with \r
And here is the same script in cooked mode:
t=Thread.newdoprint"=>"; $stdin.getcendsleep2puts"one with no \\r"puts"two with no \\r"puts"three with no \\r"puts"\rone with \\r"puts"\rtwo with \\r"puts"\rthree with \\r"t.join
Which produces:
=>one with no \r
two with no \r
three with no \r
one with \r
two with \r
three with \r
Unfortunately, this is not a bug. It may not be ideal in your case but I don't see a way out of it apart from you using carriage return character.
Describe the problem
Anything written to STDOUT while waiting for input from the user will not have a carriage return, which results in strange formatting of the data written to STDOUT.
Steps to reproduce the problem
To reproduce this, send multiple lines of data to STDOUT while waiting for some user input (ie. TTY::Prompt#ask).
I thought this might have to do with malformed escapes for coloring, so I disabled color on the prompt and still had the same results.
Actual behaviour
Expected behaviour
This is output from same code, except
TTY::Prompt.new.ask('=>')
has been replaced withprint =>; readline
Describe your environment
The text was updated successfully, but these errors were encountered: