X-Git-Url: https://git.llucax.com/software/mutt-debian.git/blobdiff_plain/14c29200cb58d3c4a0830265f2433849781858d0..9ae284163f491c64de122fcd555019040e0d4da7:/curs_lib.c diff --git a/curs_lib.c b/curs_lib.c index 42a8291..7f88cc9 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -72,18 +72,16 @@ void mutt_refresh (void) customize this is of course the Mutt way. */ void mutt_need_hard_redraw (void) { - if (!getenv ("DISPLAY")) - { - keypad (stdscr, TRUE); - clearok (stdscr, TRUE); - set_option (OPTNEEDREDRAW); - } + keypad (stdscr, TRUE); + clearok (stdscr, TRUE); + set_option (OPTNEEDREDRAW); } event_t mutt_getch (void) { int ch; event_t err = {-1, OP_NULL }, ret; + event_t timeout = {-2, OP_NULL}; if (!option(OPTUNBUFFEREDINPUT) && UngetCount) return (KeyEvent[--UngetCount]); @@ -100,7 +98,10 @@ event_t mutt_getch (void) mutt_allow_interrupt (0); if (SigInt) + { mutt_query_exit (); + return err; + } if(ch == ERR) { @@ -110,7 +111,7 @@ event_t mutt_getch (void) endwin (); exit (1); } - return err; + return timeout; } if ((ch & 0x80) && option (OPTMETAKEY)) @@ -179,6 +180,10 @@ void mutt_edit_file (const char *editor, const char *data) mutt_error (_("Error running \"%s\"!"), cmd); mutt_sleep (2); } +#if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM) + /* the terminal may have been resized while the editor owned it */ + mutt_resize_screen (); +#endif keypad (stdscr, TRUE); clearok (stdscr, TRUE); } @@ -202,9 +207,9 @@ int mutt_yesorno (const char *msg, int def) answer[1] = 0; reyes_ok = (expr = nl_langinfo (YESEXPR)) && expr[0] == '^' && - !regcomp (&reyes, expr, REG_NOSUB|REG_EXTENDED); + !REGCOMP (&reyes, expr, REG_NOSUB); reno_ok = (expr = nl_langinfo (NOEXPR)) && expr[0] == '^' && - !regcomp (&reno, expr, REG_NOSUB|REG_EXTENDED); + !REGCOMP (&reno, expr, REG_NOSUB); #endif CLEARLINE(LINES-1); @@ -218,7 +223,7 @@ int mutt_yesorno (const char *msg, int def) answer_string = safe_malloc (COLS + 1); snprintf (answer_string, COLS + 1, " ([%s]/%s): ", def == M_YES ? yes : no, def == M_YES ? no : yes); answer_string_len = strlen (answer_string); - printw ("%.*s%s", COLS - answer_string_len, msg, answer_string); + mutt_message ("%.*s%s", COLS - answer_string_len, msg, answer_string); FREE (&answer_string); FOREVER @@ -227,7 +232,7 @@ int mutt_yesorno (const char *msg, int def) ch = mutt_getch (); if (CI_is_return (ch.ch)) break; - if (ch.ch == -1) + if (ch.ch < 0) { def = -1; break; @@ -273,6 +278,12 @@ int mutt_yesorno (const char *msg, int def) addstr ((char *) (def == M_YES ? yes : no)); mutt_refresh (); } + else + { + /* when the users cancels with ^G, clear the message stored with + * mutt_message() so it isn't displayed when the screen is refreshed. */ + mutt_clear_error(); + } return (def); } @@ -293,54 +304,49 @@ void mutt_query_exit (void) SigInt = 0; } -void mutt_curses_error (const char *fmt, ...) +static void curses_message (int error, const char *fmt, va_list ap) { - va_list ap; char scratch[LONG_STRING]; - va_start (ap, fmt); vsnprintf (scratch, sizeof (scratch), fmt, ap); - va_end (ap); - + dprint (1, (debugfile, "%s\n", scratch)); mutt_format_string (Errorbuf, sizeof (Errorbuf), - 0, COLS-2, FMT_LEFT, 0, scratch, sizeof (scratch), 0); + 0, COLS, FMT_LEFT, 0, scratch, sizeof (scratch), 0); if (!option (OPTKEEPQUIET)) { - BEEP (); - SETCOLOR (MT_COLOR_ERROR); + if (error) + BEEP (); + SETCOLOR (error ? MT_COLOR_ERROR : MT_COLOR_MESSAGE); mvaddstr (LINES-1, 0, Errorbuf); clrtoeol (); SETCOLOR (MT_COLOR_NORMAL); mutt_refresh (); } - set_option (OPTMSGERR); + if (error) + set_option (OPTMSGERR); + else + unset_option (OPTMSGERR); } -void mutt_curses_message (const char *fmt, ...) +void mutt_curses_error (const char *fmt, ...) { va_list ap; - char scratch[LONG_STRING]; va_start (ap, fmt); - vsnprintf (scratch, sizeof (scratch), fmt, ap); + curses_message (1, fmt, ap); va_end (ap); +} - mutt_format_string (Errorbuf, sizeof (Errorbuf), - 0, COLS-2, FMT_LEFT, 0, scratch, sizeof (scratch), 0); - - if (!option (OPTKEEPQUIET)) - { - SETCOLOR (MT_COLOR_MESSAGE); - mvaddstr (LINES - 1, 0, Errorbuf); - clrtoeol (); - SETCOLOR (MT_COLOR_NORMAL); - mutt_refresh (); - } +void mutt_curses_message (const char *fmt, ...) +{ + va_list ap; - unset_option (OPTMSGERR); + va_start (ap, fmt); + curses_message (0, fmt, ap); + va_end (ap); } void mutt_progress_init (progress_t* progress, const char *msg, @@ -351,6 +357,9 @@ void mutt_progress_init (progress_t* progress, const char *msg, if (!progress) return; + if (option(OPTNOCURSES)) + return; + memset (progress, 0, sizeof (progress_t)); progress->inc = inc; progress->flags = flags; @@ -376,7 +385,8 @@ void mutt_progress_init (progress_t* progress, const char *msg, dprint (1, (debugfile, "gettimeofday failed: %d\n", errno)); /* if timestamp is 0 no time-based suppression is done */ if (TimeInc) - progress->timestamp = tv.tv_sec * 1000 + tv.tv_usec / 1000; + progress->timestamp = ((unsigned int) tv.tv_sec * 1000) + + (unsigned int) (tv.tv_usec / 1000); mutt_progress_update (progress, 0, 0); } @@ -387,6 +397,9 @@ void mutt_progress_update (progress_t* progress, long pos, int percent) struct timeval tv = { 0, 0 }; unsigned int now = 0; + if (option(OPTNOCURSES)) + return; + if (!progress->inc) goto out; @@ -399,7 +412,8 @@ void mutt_progress_update (progress_t* progress, long pos, int percent) /* skip refresh if not enough time has passed */ if (update && progress->timestamp && !gettimeofday (&tv, NULL)) { - now = tv.tv_sec * 1000 + tv.tv_usec / 1000; + now = ((unsigned int) tv.tv_sec * 1000) + + (unsigned int) (tv.tv_usec / 1000); if (now && now - progress->timestamp < TimeInc) update = 0; } @@ -410,7 +424,6 @@ void mutt_progress_update (progress_t* progress, long pos, int percent) if (update) { - dprint (1, (debugfile, "Updating progress: %ld\n", pos)); if (progress->flags & M_PROGRESS_SIZE) { pos = pos / (progress->inc << 10) * (progress->inc << 10); @@ -418,7 +431,9 @@ void mutt_progress_update (progress_t* progress, long pos, int percent) } else snprintf (posstr, sizeof (posstr), "%ld", pos); - + + dprint (5, (debugfile, "updating progress: %s\n", posstr)); + progress->pos = pos; if (now) progress->timestamp = now; @@ -553,7 +568,7 @@ int _mutt_enter_fname (const char *prompt, char *buf, size_t blen, int *redraw, mutt_refresh (); ch = mutt_getch(); - if (ch.ch == -1) + if (ch.ch < 0) { CLEARLINE (LINES-1); return (-1); @@ -635,7 +650,7 @@ int mutt_multi_choice (char *prompt, char *letters) { mutt_refresh (); ch = mutt_getch (); - if (ch.ch == -1 || CI_is_return (ch.ch)) + if (ch.ch < 0 || CI_is_return (ch.ch)) { choice = -1; break; @@ -719,6 +734,11 @@ void mutt_format_string (char *dest, size_t destlen, w = 1; /* hack */ else { +#ifdef HAVE_ISWBLANK + if (iswblank (wc)) + wc = ' '; + else +#endif if (!IsWPrint (wc)) wc = '?'; w = wcwidth (wc); @@ -730,7 +750,7 @@ void mutt_format_string (char *dest, size_t destlen, min_width -= w; max_width -= w; strncpy (p, scratch, k2); - p += k2; + p += k2; destlen -= k2; } } @@ -869,7 +889,7 @@ int mutt_wstr_trunc (const char *src, size_t maxlen, size_t maxwid, size_t *widt { wchar_t wc; int w = 0, l = 0, cl; - size_t cw, n; + int cw, n; mbstate_t mbstate; if (!src) @@ -883,7 +903,13 @@ int mutt_wstr_trunc (const char *src, size_t maxlen, size_t maxwid, size_t *widt if (cl == (size_t)(-1) || cl == (size_t)(-2)) cw = cl = 1; else + { cw = wcwidth (wc); + /* hack because M_TREE symbols aren't turned into characters + * until rendered by print_enriched_string (#3364) */ + if (cw < 0 && cl == 1 && src[0] && src[0] < M_TREE_MAX) + cw = 1; + } if (cl + l > maxlen || cw + w > maxwid) break; l += cl;