antirez/linenoise

Multi-threading problem

owent opened this issue · 3 comments

owent commented

Hello, this library is awesome and I use it in my tools. But I have some problem.

In my tool, I use libuv to do the network jobs and use linenoise to interactive with user. They are run on different thread. But when running linenoise and blocked on one thread and writing some message with '\n' on another thread, the column position of the next line is padding to the position of the preview's.
For example, if I write abc\ndef to stdout, it will be:

~>    
# terminal show this and then I call printf("abc\ndef") on another thread.
# then it will be like this
~>abc
     def

It's hard for humen to read especially the line is long and there is many line.Such as I print the DebugString of protobuf to stdout.

Then I fork this repo and comment linenoise.c:233

    raw.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
    /* output modes - disable post processing */
    // raw.c_oflag &= ~(OPOST);  // HERE MODIFIED
    /* control modes - set 8 bit chars */
    raw.c_cflag |= (CS8);

And then this problem is gone.
But I wonder if is there any problem in other cases?
Hope for your help.

Thanks

owent commented

please see https://github.com/owent-contrib/linenoise to view the changes

I had the same issue, thank you for this temporary fix! I'll report back if I run into any unintended consequences.

I had the same issue. This proposed fix solves the problem. Please consider merging to the main branch. Thanks! (unless it has unintended side effects, if so, please point it out, thanks!).