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

Cannot paste multiple lines into the example program. #208

Open
culler opened this issue Oct 22, 2022 · 1 comment
Open

Cannot paste multiple lines into the example program. #208

culler opened this issue Oct 22, 2022 · 1 comment

Comments

@culler
Copy link

culler commented Oct 22, 2022

Highlight and copy the 10 lines below:

This is line 1.
This is line 2.
This is line 3.
This is line 4.
This is line 5.
This is line 6.
This is line 7.
This is line 8.
This is line 9.
This is line 10.

Now run the example program and paste these10 lines into it. This is what you get:

$ ./linenoise_example
hello> This is line 1.
echo: 'This is line 1.'
hello>

Only the first line is received. Lines 2 - 9 are ignored. Each line should be printed with a prompt and a response. Pasting short code snippets into a REPL is a very common thing to do.

@culler
Copy link
Author

culler commented Oct 23, 2022

I think I found the explanation for this problem in the linux termios man page where it explains the TCSAFLUSH flag to tcsetattr:

      the change occurs after all output written to the object
          referred by fd has been transmitted, and all input that
          has been received but not read will be discarded before
          the change is made.

That flag is used in disableRawMode. So everything in the input buffer after the first newline gets discarded when disableRawMode is called after processing the first line.

The fix for this appears to be to use TCSADRAIN instead of TCSAFLUSH. That drains the output but does not discard the input.

tung added a commit to tung/clox that referenced this issue Dec 16, 2022
When pasting multiple lines into the REPL before, only the first line
would be recognized; this change allows all pasted lines to go through.

See also: antirez/linenoise#208
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

1 participant