Skip to content

Instantly share code, notes, and snippets.

@saitoha
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saitoha/9819c355445e269f87ff to your computer and use it in GitHub Desktop.
Save saitoha/9819c355445e269f87ff to your computer and use it in GitHub Desktop.
vim: prevent echo-back problem on start up time (https://github.com/saitoha/mouseterm-plus/issues/3)
diff -r 3bd553b9e4bf runtime/doc/eval.txt
--- a/runtime/doc/eval.txt Sat Mar 14 15:35:52 2015 +0100
+++ b/runtime/doc/eval.txt Tue Mar 17 02:26:11 2015 +0900
@@ -6123,11 +6123,8 @@
list items converted to NULs).
Pipes are not used.
- When prepended by |:silent| the shell will not be set to
- cooked mode. This is meant to be used for commands that do
- not need the user to type. It avoids stray characters showing
- up on the screen which require |CTRL-L| to remove. >
- :silent let f = system('ls *.vim')
+ The shell will be set to cbreak mode during execution of the
+ command. It avoids stray characters showing up on the screen.
<
Note: Use |shellescape()| or |::S| with |expand()| or
|fnamemodify()| to escape special characters in a command
diff -r 3bd553b9e4bf src/diff.c
--- a/src/diff.c Sat Mar 14 15:35:52 2015 +0100
+++ b/src/diff.c Tue Mar 17 02:26:11 2015 +0900
@@ -986,7 +986,7 @@
#ifdef FEAT_AUTOCMD
block_autocmds(); /* Avoid ShellCmdPost stuff */
#endif
- (void)call_shell(buf, SHELL_FILTER | SHELL_COOKED);
+ (void)call_shell(buf, SHELL_FILTER | SHELL_CBREAK);
#ifdef FEAT_AUTOCMD
unblock_autocmds();
#endif
diff -r 3bd553b9e4bf src/eval.c
--- a/src/eval.c Sat Mar 14 15:35:52 2015 +0100
+++ b/src/eval.c Tue Mar 17 02:26:11 2015 +0900
@@ -18795,10 +18795,9 @@
}
}
- /* Omit SHELL_COOKED when invoked with ":silent". Avoids that the shell
- * echoes typeahead, that messes up the display. */
- if (!msg_silent)
- flags += SHELL_COOKED;
+ /* Set term to cbreak mode to avoid that the shell echoes typeahead,
+ * that messes up the display. */
+ flags |= SHELL_CBREAK;
if (retlist)
{
diff -r 3bd553b9e4bf src/os_unix.c
--- a/src/os_unix.c Sat Mar 14 15:35:52 2015 +0100
+++ b/src/os_unix.c Tue Mar 17 02:26:11 2015 +0900
@@ -622,7 +622,7 @@
in_mch_delay = TRUE;
old_tmode = curr_tmode;
if (curr_tmode == TMODE_RAW)
- settmode(TMODE_SLEEP);
+ settmode(TMODE_CBREAK);
/*
* Everybody sleeps in a different way...
@@ -3438,8 +3438,12 @@
tnew.c_cc[VMIN] = 1; /* return after 1 char */
tnew.c_cc[VTIME] = 0; /* don't wait */
}
- else if (tmode == TMODE_SLEEP)
- tnew.c_lflag &= ~(ECHO);
+ else if (tmode == TMODE_CBREAK)
+ {
+ tnew.c_lflag &= ~(ICANON | ECHO);
+ tnew.c_cc[VMIN] = 1; /* return after 1 char */
+ tnew.c_cc[VTIME] = 0; /* don't wait */
+ }
# if defined(HAVE_TERMIOS_H)
{
@@ -3478,7 +3482,7 @@
ttybnew.sg_flags &= ~(CRMOD | ECHO);
ttybnew.sg_flags |= RAW;
}
- else if (tmode == TMODE_SLEEP)
+ else if (tmode == TMODE_CBREAK)
ttybnew.sg_flags &= ~(ECHO);
ioctl(read_cmd_fd, TIOCSETN, &ttybnew);
#endif
@@ -4054,7 +4058,9 @@
out_flush();
- if (options & SHELL_COOKED)
+ if (options & SHELL_CBREAK)
+ settmode(TMODE_CBREAK); /* set to normal mode without echo */
+ else if (options & SHELL_COOKED)
settmode(TMODE_COOK); /* set to normal mode */
# if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
@@ -4179,7 +4185,9 @@
goto error;
out_flush();
- if (options & SHELL_COOKED)
+ if (options & SHELL_CBREAK)
+ settmode(TMODE_CBREAK); /* set to normal mode without echo */
+ else if (options & SHELL_COOKED)
settmode(TMODE_COOK); /* set to normal mode */
/*
diff -r 3bd553b9e4bf src/term.h
--- a/src/term.h Sat Mar 14 15:35:52 2015 +0100
+++ b/src/term.h Tue Mar 17 02:26:11 2015 +0900
@@ -163,6 +163,6 @@
#define T_OP (term_str(KS_OP)) /* original color pair */
#define T_U7 (term_str(KS_U7)) /* request cursor position */
-#define TMODE_COOK 0 /* terminal mode for external cmds and Ex mode */
-#define TMODE_SLEEP 1 /* terminal mode for sleeping (cooked but no echo) */
-#define TMODE_RAW 2 /* terminal mode for Normal and Insert mode */
+#define TMODE_COOK 0 /* terminal mode for :shell, ! and Ex mode */
+#define TMODE_CBREAK 1 /* terminal mode for system() and sleeping */
+#define TMODE_RAW 2 /* terminal mode for Normal and Insert mode */
diff -r 3bd553b9e4bf src/vim.h
--- a/src/vim.h Sat Mar 14 15:35:52 2015 +0100
+++ b/src/vim.h Tue Mar 17 02:26:11 2015 +0900
@@ -973,6 +973,7 @@
#define SHELL_SILENT 16 /* don't print error returned by command */
#define SHELL_READ 32 /* read lines and insert into buffer */
#define SHELL_WRITE 64 /* write lines from buffer */
+#define SHELL_CBREAK 128 /* set term to cbreak mode */
/* Values returned by mch_nodetype() */
#define NODE_NORMAL 0 /* file or directory, check with mch_isdir()*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment