jacklund / repl-rs

Rust library for managing an interactive command-line session
24 stars 27 forks source link

example has incorrect cursor position on windows shell #7

Open RustyJoeM opened 2 years ago

RustyJoeM commented 2 years ago

Hello,

when i try to run examples with current "head" (git log - 2474e4785db205e0327a5359d6d41af52d830dc8), The REPL line has a wrong cursor position - there seems to be some constant offset/space between REPL prefix "MyApp>" and line being written:

C:\...\repl-rs>cargo run --example no_context
    Finished dev [unoptimized + debuginfo] target(s) in 0.09s
     Running `target\debug\examples\no_context.exe`
Welcome to MyApp v0.1.0
MyApp>          _       // <---- '_' is position of cursor
MyApp>          help
MyApp v0.1.0: My very cool app

add - Add two numbers together
hello - Greetings!
MyApp>          _       // <---- '_' is position of cursor

// i press up-arrow to get last command from history, and result is:
MyApp> help     _       // "help" is written on correct position, but cursor is again positioned behind it

Not sure if this is windows specific or behaves the same on *nix environment.

jacklund commented 2 years ago

Hey, sorry it took so long to get back to you.

Here's what it looks like on Linux:

image

So, it might be a windows thing. Unfortunately, I don't have a windows box to test this on, but if you can find the issue, feel free to submit a PR on it.

fvilers commented 1 year ago

I have the same issue. It might be an issue with the yansi crate on Windows.

You can always make your own prompt with repl-rs, see this PR

GilesLeinad commented 1 year ago

Hello, I had the same issue and found some discussions in the rustyline repo which explains the behavior:

The result is more or less that the prompt passed to the readline function should not contain any escape sequence. It seems that this problem appears only on Windows.

When you wan't to use a colored prompt you have to implement the highlight_prompt function for the Helper struct.

With the changes in this PR it is working for me. Unfortunatley I can't run the tests (are they requiring a Linux system?) so I can't check whether my changes broke something else.