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

ExternalPrinter can't handle ASCII control character #692

Open
yalikes opened this issue Mar 20, 2023 · 6 comments
Open

ExternalPrinter can't handle ASCII control character #692

yalikes opened this issue Mar 20, 2023 · 6 comments

Comments

@yalikes
Copy link

yalikes commented Mar 20, 2023

I am using rustyline version 11.0.0

I want use ExternalPrinter to print string that contains some ASCII control character
if I write the following code, it output a single character t. this make since because \x08 is a backspace.

fn main(){
    let mut rl = rustyline::DefaultEditor::new().unwrap();
    let mut printer = rl.create_external_printer().unwrap();
    printer.print("test\x08\x08\x08".to_owned()).unwrap();
}

but if I instead using the following code, ExternalPrintetr output all four character test.
and I expect it output just a t

fn main(){
    let mut rl = rustyline::DefaultEditor::new().unwrap();
    let mut printer = rl.create_external_printer().unwrap();
    thread::spawn(move || {
        printer.print("test\x08\x08\x08".to_owned()).unwrap();
    });
    let line = rl.readline(">>").unwrap();
}

why ASCII control character didn't work in ExternalPrinter that I use it in another thread?
and how can I make ExternalPrinter handle ASCII control character?

@yalikes yalikes changed the title ExternalPrinter can't handle ASCII control character in another thread ExternalPrinter can't handle ASCII control character Mar 20, 2023
@gwenn
Copy link
Collaborator

gwenn commented Mar 20, 2023

Raw mode is activated only while reading / readline(">>") is called. And deactivated when readline(">>") returns.
And some escape sequences are interpreted only in raw mode.
I guess replxx behaves the same.

@gwenn
Copy link
Collaborator

gwenn commented Mar 20, 2023

Same behavior with linefeed:

diff --git a/examples/demo.rs b/examples/demo.rs
index a7ad87c..4754cac 100644
--- a/examples/demo.rs
+++ b/examples/demo.rs
@@ -90,8 +90,8 @@ fn main() -> io::Result<()> {
                     let mut rng = thread_rng();
                     let mut i = 0usize;
                     loop {
-                        writeln!(iface, "[#{}] Concurrent message #{}",
-                            my_thread_id, i).unwrap();
+                        writeln!(iface, "test\x08\x08\x08",
+                            ).unwrap();
                         let wait_ms = rng.gen_range(1, 500);
                         thread::sleep(Duration::from_millis(wait_ms));
                         i += 1;
linefeed % cargo run --example demo
demo> spawn-log-thread
Spawning log thread #0
test
test
test
test
test
demo>
Goodbye.

But if I add one character like "test\x08\x08\x08!"
I get "t!st" with both rustyline and replxx...

@yalikes
Copy link
Author

yalikes commented Mar 27, 2023

do we have any plan to add the feature that enable ASCII control character in external printer?
or maybe I just misunderstanding the usage of external printer. because it by design to print plain text info...

@gwenn
Copy link
Collaborator

gwenn commented Mar 27, 2023

To print plain or styled text

@michabs
Copy link

michabs commented May 17, 2023

tested with this bash script:
#!/bin/bash
input="./test.txt"
while IFS= read -r line
do
echo -e "$line"
done < "$input"

test.txt is just one line:
test\b\b\b!

yield (as rustyline):
t!st

@Outfluencer
Copy link

is there something like the external printer that supports ansii?

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

4 participants