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

Fix the cause of test_yamatanooroti randomly failing #474

Merged
merged 2 commits into from
Feb 27, 2023

Conversation

tompng
Copy link
Member

@tompng tompng commented Oct 23, 2022

When pressing tab key for a long time, cursor is moving right and left. On the right end, something(nt and ----) is remain displayed.
tabpress

This behavior is also causing random test failure in rake test_yamatanooroti.
These tests failed in my local environment (macOS, Terminal.app, vterm 0.2, looks like fails more frequently compared to ci)

test_autocomplete_after_2nd_line
test_autowrap_in_the_middle_of_a_line
test_backspace
test_dynamic_prompt_returns_empty
test_dynamic_prompt_with_newline
test_finish_autowrapped_line_in_the_middle_of_multilines
test_force_enter
test_incremental_search_on_not_last_line
test_insert_line_in_the_middle_of_line
test_insert_newline_in_the_middle_of_buffer_just_after_dialog
test_mode_string_vi
test_mode_string_vi_changing
test_original_mode_string_vi
test_prompt
test_prompt_list_caching
test_prompt_with_escape_sequence
test_two_fullwidth
test_update_cursor_correctly_when_just_cursor_moving

I ran test_update_cursor_correctly_when_just_cursor_moving, the most frequently failing test in local for 100 times(local) and 50 times(ci in forked repository: tompng@da6b2c5, job result: https://github.com/tompng/reline/actions/runs/3307143383/jobs/5458548780)

result local(100 runs) ci(50 runs) description
"Multiline REPL.\nprompt> def hoge\nprompt> 0123456789\n" 75 48 expected result
"Multiline REPL.\nprompt> def hoge^B\nprompt> 0123456789\n" 9 0 extra ^B
"Multiline REPL.\nprompt> def hog^N\nprompt> 0123456789\n" 9 2 extra ^N
"Multiline REPL.\nprompt> def hoge\nprompt> def hoge^B\nprompt> 0123456789\n" 2 0 extra line and ^B
"Multiline REPL.\nprompt> def hog^NB\nprompt> 0123456789\n" 4 0 extra ^NB
"Multiline REPL.\nprompt> def hoge\nprompt> def hoge\nprompt> 0123456789\n" 1 0 extra line

Failing result sometimes contains ^B and ^N.
This is because getc in ansi.rb is using STDIN.raw{getc}, that means there is a non-raw time between the next getc.
When there is new input while rendering a dialog, prompt or something else, the input is echo-ed.
To fix this, reline should not echo while editing multiline.

Changes

I added Reline::IOGate.with_raw_input and used in Reline.readmultiline.
I used IO#raw, not IO#noecho. noecho will show a key mark cursor for password input in Terminal.app and iTerm2 and maybe other teminals.

In raw mode, \n will only move cursor down, not left-end of the next line and test_terminate_in_the_middle_of_lines will fail. So I added \r to method rerender in line_editor.rb

Added test writing a[delete]a[delete]a[delete]...(4000 times) to vterm.
In HEAD, it fails with

<"Multiline REPL.\n" + "prompt>\n"> expected but was
<"a^Ha^Ha^Ha^Ha^Ha^Ha^Ha^Ha^Ha^H\n" +
"a^Ha^Ha^Ha^Ha^Ha^Ha^Ha^Ha^Ha^H\n" +
"a^Ha^Ha^Ha^Ha^Ha^Ha^Ha^Ha^Ha^H\n" +
"a^Ha^Ha^Ha^Ha^Ha^Ha^Ha^Ha^Ha^H\n" +
"prompt>\n">

failed result: https://github.com/tompng/reline/actions/runs/3307571761/jobs/5459304761

@tompng
Copy link
Member Author

tompng commented Dec 26, 2022

ruby/irb#445

  1. Makes backspacing slow (mentioned multiple times in the poll comments)

I think cooked mode is making backspace ignored (not sent to remote server), and this pull request might improve it.

@hasumikin
Copy link
Collaborator

@tompng
(This is just to clarify)
The original issue, jumping cursor and remaining ==== and nt, seems not to happen on Linux and Windows (I now don't have a Mac).
Do you figure out if it's a Mac-specific issue?

@tompng
Copy link
Member Author

tompng commented Jan 10, 2023

@hasumikin
I only figure it out on Mac (I have mac only), so I don't know. It reproduced in Terminal.app, iTerm2, Alacaritty and Terminal in VSCode.
I think it's because of my keyboard key repeat setting and cpu speed. It only reproduced when I set key repeat speed to maximum in system preference. With this monkey-patch pasted to bin/console, it reproduced in slower key repeat speed

# jumping cursors
Reline::LineEditor.prepend Module.new{
  def render_dialog(...); sleep 0.2; super(...); end
}
# remaining strings
class Reline::LineEditor::Dialog
  def contents;sleep 0.005;@contents;end
end

@ima1zumi
Copy link
Member

I checked on macOS, and Linux is also Reline::ANSI, so I think it's ok.
Please wait for a while I check it in Windows. I recently got a Windows license.

@hasumikin
Copy link
Collaborator

It works fine on Windows.

@hasumikin hasumikin merged commit c3b8cec into ruby:master Feb 27, 2023
matzbot pushed a commit to ruby/ruby that referenced this pull request Feb 27, 2023
(ruby/reline#474)

* Add repeated input-delete test that fails on HEAD

* Use raw mode while readmultiline
@tompng tompng deleted the fix_stdin_read_raw branch February 27, 2023 08:56
hsbt pushed a commit to hsbt/ruby that referenced this pull request Feb 27, 2023
(ruby/reline#474)

* Add repeated input-delete test that fails on HEAD

* Use raw mode while readmultiline
@ima1zumi ima1zumi added the bug Something isn't working label Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging this pull request may close these issues.

3 participants