Giter Club home page Giter Club logo

Comments (9)

gwenn avatar gwenn commented on August 29, 2024

Could you please do the following ?
(a) check that you are respecting this rule:
https://docs.rs/rustyline/latest/rustyline/highlight/trait.Highlighter.html

Currently, the highlighted version must have the same display width as the original input.

(b) check that the provided example has the bug too:
https://github.com/kkawakam/rustyline/blob/master/examples/example.rs#L23-L47

cargo run --example example

(I don't have access to a Windows 11 machine but only a Windows 10, I am going to check)

from rustyline.

gwenn avatar gwenn commented on August 29, 2024

Cannot reproduce with the old cmd shell or powershell:

1> (abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuivwxyz abcdefg
hijklmno)

from rustyline.

BrandonXLF avatar BrandonXLF commented on August 29, 2024

The example example works as expected but minimal does not. I've tested cmd, Windows Terminal, VS Code, and PowerShell.

from rustyline.

gwenn avatar gwenn commented on August 29, 2024

Same here.
Thanks.

from rustyline.

gwenn avatar gwenn commented on August 29, 2024

Only occurs when color mode is enabled (which is on by default).

Indeed, with this local patch, minimal example behaves correctly:

diff --git a/examples/minimal.rs b/examples/minimal.rs
index 9fc627e..d3ff7b0 100644
--- a/examples/minimal.rs
+++ b/examples/minimal.rs
@@ -1,9 +1,12 @@
-use rustyline::{DefaultEditor, Result};
+use rustyline::{ColorMode, Config, DefaultEditor, Result};

 /// Minimal REPL
 fn main() -> Result<()> {
     env_logger::init();
-    let mut rl = DefaultEditor::new()?;
+    let config = Config::builder()
+        .color_mode(ColorMode::Disabled)
+        .build();
+    let mut rl = DefaultEditor::with_config(config)?;
     loop {
         let line = rl.readline("> ")?; // read
         println!("Line: {line}"); // eval / print

from rustyline.

gwenn avatar gwenn commented on August 29, 2024

Ok, the issue must be here:

if let Some(highlighter) = highlighter {
// TODO handle ansi escape code (SetConsoleTextAttribute)
// append the prompt
col = self.wrap_at_eol(&highlighter.highlight_prompt(prompt, default_prompt), col);
// append the input line
col = self.wrap_at_eol(&highlighter.highlight(line, line.pos()), col);
} else {
// append the prompt
self.buffer.push_str(prompt);
// append the input line
self.buffer.push_str(line);
}

from rustyline.

gwenn avatar gwenn commented on August 29, 2024

@BrandonXLF Could you please give PR #739 a try ?

from rustyline.

BrandonXLF avatar BrandonXLF commented on August 29, 2024

@BrandonXLF Could you please give PR #739 a try ?

Works as expected 👍

from rustyline.

gwenn avatar gwenn commented on August 29, 2024

Version 13.0.0 released.

from rustyline.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.