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

Backspace behavior at the end of line #292

Open
joshka opened this issue Nov 22, 2023 · 0 comments
Open

Backspace behavior at the end of line #292

joshka opened this issue Nov 22, 2023 · 0 comments

Comments

@joshka
Copy link

joshka commented Nov 22, 2023

In iTerm2 and Terminal.app on macOS, when the cursor is one past the end of line (i.e. the next character will be entered on the newline), the cursor position is regarded as being on that line rather than then next. When the backspace key is pressed, the logic that handles this case causes the rendering to move to the previous line and start rendering. This means that backspacing over newlines always breaks usages of dialoguer.

I'm not sure if this is a universal problem, a macOS specific issue, or one that is due to some personal random shell setting (I'm not aware of any that would affect this). Is this something others see?

iTerm2

Screen.Recording.2023-11-21.at.6.05.39.PM.mov

Terminal.app

Screen.Recording.2023-11-21.at.6.07.38.PM.mov

The code in question is

// Case we want to delete last char of a line so the cursor is at the beginning of the next line
if (position + prompt_len) % (line_size - 1) == 0 {
term.clear_line()?;
term.move_cursor_up(1)?;
term.move_cursor_right(line_size + 1)?;

Repro using VHS:

VHS Tape file
Output backspace-eol.gif

Set FontSize 32
Set Width 800
Set Height 600

Type "echo Single backspace" Enter
Type "cargo run --quiet --example=input" Enter
Sleep 2s
Type "Test Backspace EOL1" Backspace
Sleep 1s
Type " Line2"
Sleep 2s
Ctrl+C Enter
Sleep 2s

Type "echo Double backspace" Enter
Type "cargo run --quiet --example=input" Enter
Sleep 2s
Type "Test Backspace EOL12" Backspace 2
Sleep 2s
Type " Line2" Enter
Ctrl+C Enter
Sleep 2s

Type "echo Triple backspace" Enter
Type "cargo run --quiet --example=input" Enter
Sleep 2s
Type "Test Backspace EOL123" Backspace 3
Sleep 2s
Type " Line2" Enter
Ctrl+C
Sleep 2s

backspace-eol

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

1 participant