kkawakam / rustyline

Readline Implementation in Rust
https://crates.io/crates/rustyline/
MIT License
1.52k stars 175 forks source link

Fix position calculation on Windows #702

Open ShaneEverittM opened 1 year ago

ShaneEverittM commented 1 year ago

The implementations for Renderer::calculate_position differed slightly between unix and Windows. Notably, the Windows implementation did not use tty::width, but instead used UnicodeWidthStr::width. It seems that the latter did not correctly compute the length.

For context, this bug was discovered in the boa JS interpreter, where on Windows the prompt being bold and blue caused the cursor to be offset by 9 characters.

gwenn commented 1 year ago

See https://github.com/kkawakam/rustyline/pull/215#issuecomment-491945339

ShaneEverittM commented 1 year ago

Dang, not sure how I missed that when looking for duplicates! Sorry!

gwenn commented 1 year ago
  1. So either we introduce some code / dependencies to remove ascii escape sequences when colours are not supported or wanted (I would prefer not to).
  2. Or you make sure that raw prompt / input contains no ascii escape sequences (and only your Highlighter adds some style).

But neither 1 or 2 are compatible with continuation prompt (see https://github.com/kkawakam/rustyline/pull/372#issuecomment-626295074).