commit 8aaf03000b3e797b479fc250b396c7155e05ed25
parent ad1fd0d96814b50f2baee50e9aa4acace3d29a66
Author: David Lawrence Ramsey <pooka109@gmail.com>
Date: Tue, 27 Jul 2004 16:46:35 +0000
move the main terminal initialization functions, aside from initscr(),
into a new terminal_init() function, and convert nano to use it; also,
when reloading the newly spell-checked temporary file in
do_alt_speller(), call terminal_init() to make sure that all the
original terminal settings are restored, as a curses-based alternative
spell checker (e.g. aspell) can change them
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1866 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Diffstat:
3 files changed, 34 insertions(+), 24 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -45,6 +45,9 @@ CVS code -
Benbennick)
- Include <sys/types.h> in proto.h. (David Benbennick) DLR:
Remove some redundant inclusions of <sys/types.h> elsewhere.
+ - Move the main terminal initialization functions, aside from
+ initscr(), into a new terminal_init() function, and convert
+ nano to use it. (DLR)
- files.c:
close_open_file()
- Tweak to no longer rely on the return values of
@@ -69,6 +72,11 @@ CVS code -
thanks_for_all_the_fish()
- Delete topwin, edit, and bottomwin. (David Benbennick)
- nano.c:
+ do_alt_speller()
+ - When reloading the newly spell-checked temporary file, call
+ terminal_init() to make sure that all the original terminal
+ settings are restored, as a curses-based alternative spell
+ checker (e.g. aspell) can change them. (DLR)
do_justify()
- Add allow_respacing flag, used to indicate when we've moved to
the next line after justifying the current line, and only run
diff --git a/src/nano.c b/src/nano.c
@@ -1796,6 +1796,7 @@ const char *do_alt_speller(char *tempfile_name)
/* Only reload the temp file if it isn't a marked selection. */
#endif
free_filestruct(fileage);
+ terminal_init();
global_init(TRUE);
open_file(tempfile_name, FALSE, TRUE);
#ifndef NANO_SMALL
@@ -2893,6 +2894,9 @@ void handle_sigwinch(int s)
refresh();
#endif
+ /* Restore the terminal to its previous state. */
+ terminal_init();
+
/* Do the equivalent of what both mutt and Minimum Profit do:
* Reinitialize all the windows based on the new screen
* dimensions. */
@@ -2906,9 +2910,6 @@ void handle_sigwinch(int s)
/* Turn cursor back on for sure. */
curs_set(1);
- /* Restore the terminal to its previously saved state. */
- resetty();
-
/* Reset all the input routines that rely on character sequences. */
reset_kbinput();
@@ -3019,6 +3020,24 @@ void enable_flow_control(void)
tcsetattr(0, TCSANOW, &term);
}
+/* Set up the terminal state. Put the terminal in cbreak mode (read one
+ * character at a time and interpret the special control keys), disable
+ * translation of carriage return (^M) into newline (^J) so that we can
+ * tell the difference between the Enter key and Ctrl-J, and disable
+ * echoing of characters as they're typed. Finally, disable
+ * interpretation of the special control keys, and if we're not in
+ * preserve mode, disable interpretation of the flow control characters
+ * too. */
+void terminal_init(void)
+{
+ cbreak();
+ nonl();
+ noecho();
+ disable_signals();
+ if (!ISSET(PRESERVE))
+ disable_flow_control();
+}
+
int main(int argc, char *argv[])
{
int optchr;
@@ -3442,28 +3461,10 @@ int main(int argc, char *argv[])
/* Back up the old terminal settings so that they can be restored. */
tcgetattr(0, &oldterm);
- /* Curses initialization stuff: Start curses, save the state of the
- * terminal mode, put the terminal in cbreak mode (read one character
- * at a time and interpret the special control keys), disable
- * translation of carriage return (^M) into newline (^J) so that we
- * can tell the difference between the Enter key and Ctrl-J, and
- * disable echoing of characters as they're typed. Finally, disable
- * interpretation of the special control keys, and if we're not in
- * preserve mode, disable interpretation of the flow control
- * characters too. */
+ /* Curses initialization stuff: Start curses and set up the
+ * terminal state. */
initscr();
- cbreak();
- nonl();
- noecho();
- disable_signals();
- if (!ISSET(PRESERVE))
- disable_flow_control();
-
-#ifndef NANO_SMALL
- /* Save the terminal's current state, so that we can restore it
- * after a resize. */
- savetty();
-#endif
+ terminal_init();
/* Set up the global variables and the shortcuts. */
global_init(FALSE);
diff --git a/src/proto.h b/src/proto.h
@@ -360,6 +360,7 @@ void enable_signals(void);
#endif
void disable_flow_control(void);
void enable_flow_control(void);
+void terminal_init(void);
/* Public functions in rcfile.c */
#ifdef ENABLE_NANORC