diff options
author | Bram Moolenaar <Bram@vim.org> | 2017-06-27 17:09:37 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2017-06-27 17:09:37 +0200 |
commit | 2e147caa14f622dfd1c1def8e07c113b9b85d4b2 (patch) | |
tree | 53c69cc89daa1da1462c061da18e104ae3972f7e /src/term.c | |
parent | 0b2eef24bcbe2c85c90bbde914a1782cbedc5c72 (diff) | |
download | vim-git-2e147caa14f622dfd1c1def8e07c113b9b85d4b2.tar.gz |
patch 8.0.0683: visual bell flashes too quicklyv8.0.0683
Problem: When using a visual bell there is no delay, causing the flash to
be very short, possibly unnoticeable. Also, the flash and the
beep can lockup the UI when repeated often.
Solution: Do the delay in Vim or flush the output before the delay. Limit the
bell to once per half a second. (Ozaki Kiichi, closes #1789)
Diffstat (limited to 'src/term.c')
-rw-r--r-- | src/term.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/term.c b/src/term.c index 56d698bb2..0dbe6d500 100644 --- a/src/term.c +++ b/src/term.c @@ -2514,6 +2514,75 @@ out_str_nf(char_u *s) #endif /* + * A conditional-flushing out_str, mainly for visualbell. + * Handles a delay internally, because termlib may not respect the delay or do + * it at the wrong time. + * Note: Only for terminal strings. + */ + void +out_str_cf(char_u *s) +{ + if (s != NULL && *s) + { + char_u *p; + +#ifdef FEAT_GUI + /* Don't use tputs() when GUI is used, ncurses crashes. */ + if (gui.in_use) + { + out_str_nf(s); + return; + } +#endif + if (out_pos > OUT_SIZE - 20) + out_flush(); +#ifdef HAVE_TGETENT + for (p = s; *s; ++s) + { + /* flush just before delay command */ + if (*s == '$' && *(s + 1) == '<') + { + char_u save_c = *s; + int duration = atoi((char *)s + 2); + + *s = NUL; + tputs((char *)p, 1, TPUTSFUNCAST out_char_nf); + *s = save_c; + out_flush(); +#ifdef ELAPSED_FUNC + /* Only sleep here if we can limit this happening in + * vim_beep(). */ + p = vim_strchr(s, '>'); + if (p == NULL || duration <= 0) + { + /* can't parse the time, don't sleep here */ + p = s; + } + else + { + ++p; + do_sleep(duration); + } +#else + /* Rely on the terminal library to sleep. */ + p = s; +#endif + break; + } + } + tputs((char *)p, 1, TPUTSFUNCAST out_char_nf); +#else + while (*s) + out_char_nf(*s++); +#endif + + /* For testing we write one string at a time. */ + if (p_wd) + out_flush(); + } +} + +/* * out_str(s): Put a character string a byte at a time into the output buffer. * If HAVE_TGETENT is defined use the termcap parser. (jw) * This should only be used for writing terminal codes, not for outputting |