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

Pasting multiple lines doesn't work #75

Open
welash opened this issue Sep 28, 2014 · 1 comment
Open

Pasting multiple lines doesn't work #75

welash opened this issue Sep 28, 2014 · 1 comment

Comments

@welash
Copy link

welash commented Sep 28, 2014

When trying to paste multiple lines into an application using linenoise, only the first line is taken. As an example, compiling the example applicacation and trying to paste

test1
test2
test3
test4
test5

into the example application gives:

lash@bill17laptop:~/linenoisepaste/linenoise$ ./linenoise_example
hello> test1
echo: 'test1'
hello>

This seems to be because of the use of TCAFLUSH in enableRawMode and disableRawMode. By changing thos to TCADRAIN, I see the expected behavior:

lash@bill17laptop:~/linenoisepaste/linenoise$ ./linenoise_example
hello> test1
echo: 'test1'
hello> test2
echo: 'test2'
hello> test3
echo: 'test3'
hello> test4
echo: 'test4'
hello> test5
echo: 'test5'
hello>

Here is the patch that I used:

lash@bill17laptop:~/linenoisepaste/linenoise$ git diff
diff --git a/linenoise.c b/linenoise.c
index 36c0c5f..572c34a 100644
--- a/linenoise.c
+++ b/linenoise.c
@@ -238,7 +238,7 @@ static int enableRawMode(int fd) {
     raw.c_cc[VMIN] = 1; raw.c_cc[VTIME] = 0; /* 1 byte, no timer */

     /* put terminal in raw mode after flushing */
-    if (tcsetattr(fd,TCSAFLUSH,&raw) < 0) goto fatal;
+    if (tcsetattr(fd,TCSADRAIN,&raw) < 0) goto fatal;
     rawmode = 1;
     return 0;

@@ -249,7 +249,7 @@ fatal:

 static void disableRawMode(int fd) {
     /* Don't even check the return value as it's too late. */
-    if (rawmode && tcsetattr(fd,TCSAFLUSH,&orig_termios) != -1)
+    if (rawmode && tcsetattr(fd,TCSADRAIN,&orig_termios) != -1)
         rawmode = 0;
 }

@nukep
Copy link

nukep commented Apr 23, 2015

I'm encountering the same problem in gnome-terminal, lxterminal and xterm, and would like to see it fixed. The above patch works for me in gnome-terminal and lxterminal, but acts strangely in xterm (and probably other terminal emulators).
The first line is entered individually, but the subsequent lines seem to be entered "together".

xterm:

hello> test1
echo: 'test1'
test2
test3
test4
test5hello> test2
                 test3
                      test4
                           test5
echo: 'test2
test3
test4
test5'
hello> 

zcourts added a commit to zcourts/linenoise that referenced this issue Mar 16, 2016
gwenn added a commit to gwenn/rustyline that referenced this issue Nov 11, 2016
gwenn added a commit to gwenn/rustyline that referenced this issue Nov 11, 2016
Sonophoto added a commit to Sonophoto/linenoise that referenced this issue Nov 15, 2016
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

2 participants