commit f571d6ba366bc002737b2b096a7cee1f986a760a
parent 0e21baf61139f8522a8024718beea2dcaf21fd0a
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Wed, 22 Jan 2020 12:45:15 +0100
tweaks: gather four calls that are always done together into a function
Diffstat:
M | src/nano.c | | | 43 | +++++++++++++------------------------------ |
1 file changed, 13 insertions(+), 30 deletions(-)
diff --git a/src/nano.c b/src/nano.c
@@ -304,11 +304,17 @@ void say_there_is_no_help(void)
}
#endif
-/* Tell the terminal to disable bracketed pastes. */
-void disable_bracketed_paste(void)
+/* Make sure the cursor is visible, then exit from curses mode, disable
+ * bracketed-paste mode, and restore the original terminal settings. */
+void restore_terminal(void)
{
+ curs_set(1);
+ endwin();
+
printf("\e[?2004l");
fflush(stdout);
+
+ tcsetattr(0, TCSANOW, &original_state);
}
/* Exit normally: restore the terminal state and save history files. */
@@ -326,14 +332,8 @@ void finish(void)
delwin(edit);
delwin(bottomwin);
#endif
- /* Switch on the cursor and exit from curses mode. */
- curs_set(1);
- endwin();
-
- disable_bracketed_paste();
-
- /* Restore the old terminal settings. */
- tcsetattr(0, TCSANOW, &original_state);
+ /* Switch the cursor on, exit from curses, and restore terminal settings. */
+ restore_terminal();
#if defined(ENABLE_NANORC) || defined(ENABLE_HISTORIES)
display_rcfile_errors();
@@ -359,14 +359,7 @@ void die(const char *msg, ...)
va_list ap;
openfilestruct *firstone = openfile;
- /* Switch on the cursor and leave curses mode. */
- curs_set(1);
- endwin();
-
- disable_bracketed_paste();
-
- /* Restore the old terminal settings. */
- tcsetattr(0, TCSANOW, &original_state);
+ restore_terminal();
#ifdef ENABLE_NANORC
display_rcfile_errors();
@@ -930,11 +923,7 @@ bool scoop_stdin(void)
{
FILE *stream;
- /* Exit from curses mode and put the terminal into its original state. */
- endwin();
- tcsetattr(0, TCSANOW, &original_state);
-
- disable_bracketed_paste();
+ restore_terminal();
/* When input comes from a terminal, show a helpful message. */
if (isatty(STANDARD_INPUT))
@@ -1049,10 +1038,7 @@ RETSIGTYPE do_suspend(int signal)
#ifdef ENABLE_MOUSE
disable_mouse_support();
#endif
- curs_set(1);
- endwin();
-
- disable_bracketed_paste();
+ restore_terminal();
printf("\n\n");
@@ -1060,9 +1046,6 @@ RETSIGTYPE do_suspend(int signal)
printf(_("Use \"fg\" to return to nano.\n"));
fflush(stdout);
- /* Restore the old terminal settings. */
- tcsetattr(0, TCSANOW, &original_state);
-
/* The suspend keystroke must not elicit cursor-position display. */
suppress_cursorpos=TRUE;