From 23338b47ee076d3919aa02a19e88a45e0c7db603 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Sat, 15 Apr 2017 12:56:43 -0700 Subject: [PATCH] Add multiline and sigwinch handling to mutt_multi_choice. (see #3877) Resize the message window up to three lines to fix wide prompts. Enable sigwinch processing and redraw the current menu as needed. --- curs_lib.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 5 deletions(-) diff --git a/curs_lib.c b/curs_lib.c index 262850649..55a6dd3c9 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -564,6 +564,27 @@ void mutt_reflow_windows (void) mutt_set_current_menu_redraw_full (); } +static void reflow_message_window_rows (int mw_rows) +{ + MuttMessageWindow->rows = mw_rows; + MuttMessageWindow->row_offset = LINES - mw_rows; + + MuttStatusWindow->row_offset = option (OPTSTATUSONTOP) ? 0 : LINES - mw_rows - 1; + + if (option (OPTHELP)) + MuttHelpWindow->row_offset = option (OPTSTATUSONTOP) ? LINES - mw_rows - 1 : 0; + + MuttIndexWindow->rows = MAX(LINES - MuttStatusWindow->rows - + MuttHelpWindow->rows - MuttMessageWindow->rows, 0); + +#ifdef USE_SIDEBAR + if (option (OPTSIDEBAR)) + MuttSidebarWindow->rows = MuttIndexWindow->rows; +#endif + + mutt_set_current_menu_redraw_full (); +} + int mutt_window_move (mutt_window_t *win, int row, int col) { return move (win->row_offset + row, win->col_offset + col); @@ -871,16 +892,49 @@ int mutt_multi_choice (char *prompt, char *letters) { event_t ch; int choice; + int redraw = 1, prompt_lines = 1; char *p; - SETCOLOR (MT_COLOR_PROMPT); - mutt_window_mvaddstr (MuttMessageWindow, 0, 0, prompt); - NORMAL_COLOR; - mutt_window_clrtoeol (MuttMessageWindow); FOREVER { + if (redraw || SigWinch) + { + redraw = 0; +#if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM) + if (SigWinch) + { + SigWinch = 0; + mutt_resize_screen (); + mutt_set_current_menu_redraw (REDRAW_SIGWINCH); + clearok (stdscr, TRUE); + mutt_current_menu_redraw (); + } +#endif + if (MuttMessageWindow->cols) + { + prompt_lines = (mutt_strwidth (prompt) + MuttMessageWindow->cols - 1) / + MuttMessageWindow->cols; + prompt_lines = MAX (1, MIN (3, prompt_lines)); + } + if (prompt_lines != MuttMessageWindow->rows) + { + reflow_message_window_rows (prompt_lines); + mutt_current_menu_redraw (); + } + + SETCOLOR (MT_COLOR_PROMPT); + mutt_window_mvaddstr (MuttMessageWindow, 0, 0, prompt); + NORMAL_COLOR; + mutt_window_clrtoeol (MuttMessageWindow); + } + mutt_refresh (); + /* SigWinch is not processed unless timeout is set */ + timeout (30 * 1000); ch = mutt_getch (); + timeout (-1); + if (ch.ch == -2) + continue; /* (ch.ch == 0) is technically possible. Treat the same as < 0 (abort) */ if (ch.ch <= 0 || CI_is_return (ch.ch)) { @@ -904,7 +958,13 @@ int mutt_multi_choice (char *prompt, char *letters) } BEEP (); } - mutt_window_clearline (MuttMessageWindow, 0); + if (MuttMessageWindow->rows != 1) + { + reflow_message_window_rows (1); + mutt_current_menu_redraw (); + } + else + mutt_window_clearline (MuttMessageWindow, 0); mutt_refresh (); return choice; } -- 2.40.0