]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/widechar/lib_get_wstr.c
ncurses 6.4 - patch 20230429
[ncurses.git] / ncurses / widechar / lib_get_wstr.c
index c4dec5c748dcfc176bf9fd5f915db31ddf5fb1b4..3b3bd522c2d8b20e7229de8fb3f9826974ecaaa3 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright 2018-2020,2021 Thomas E. Dickey                                *
+ * Copyright 2018-2021,2023 Thomas E. Dickey                                *
  * Copyright 2002-2009,2011 Free Software Foundation, Inc.                  *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
@@ -40,7 +40,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_get_wstr.c,v 1.20 2021/10/23 19:02:59 tom Exp $")
+MODULE_ID("$Id: lib_get_wstr.c,v 1.21 2023/04/29 19:02:03 tom Exp $")
 
 static int
 wadd_wint(WINDOW *win, wint_t *src)
@@ -88,7 +88,7 @@ wgetn_wstr(WINDOW *win, wint_t *str, int maxlen)
 {
     SCREEN *sp = _nc_screen_of(win);
     TTY buf;
-    bool oldnl, oldecho, oldraw, oldcbreak;
+    TTY_FLAGS save_flags;
     wchar_t erasec = 0;
     wchar_t killc = 0;
     wint_t *oldstr = str;
@@ -105,13 +105,11 @@ wgetn_wstr(WINDOW *win, wint_t *str, int maxlen)
 
     _nc_get_tty_mode(&buf);
 
-    oldnl = sp->_nl;
-    oldecho = sp->_echo;
-    oldraw = sp->_raw;
-    oldcbreak = sp->_cbreak;
+    save_flags = sp->_tty_flags;
     NCURSES_SP_NAME(nl) (NCURSES_SP_ARG);
     NCURSES_SP_NAME(noecho) (NCURSES_SP_ARG);
-    NCURSES_SP_NAME(raw) (NCURSES_SP_ARG);
+    if (!save_flags._raw)
+       NCURSES_SP_NAME(cbreak) (NCURSES_SP_ARG);
 
     NCURSES_SP_NAME(erasewchar) (NCURSES_SP_ARGx &erasec);
     NCURSES_SP_NAME(killwchar) (NCURSES_SP_ARGx &killc);
@@ -149,7 +147,7 @@ wgetn_wstr(WINDOW *win, wint_t *str, int maxlen)
             * *getn_wstr() with \n should work either way.
             */
            if (ch == KEY_DOWN || ch == KEY_ENTER) {
-               if (oldecho == TRUE
+               if (save_flags._echo == TRUE
                    && win->_cury == win->_maxy
                    && win->_scroll)
                    wechochar(win, (chtype) '\n');
@@ -157,11 +155,11 @@ wgetn_wstr(WINDOW *win, wint_t *str, int maxlen)
            }
            if (ch == KEY_LEFT || ch == KEY_BACKSPACE) {
                if (tmpstr > oldstr) {
-                   tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho);
+                   tmpstr = WipeOut(win, y, x, oldstr, tmpstr, save_flags._echo);
                }
            } else if (ch == KEY_EOL) {
                while (tmpstr > oldstr) {
-                   tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho);
+                   tmpstr = WipeOut(win, y, x, oldstr, tmpstr, save_flags._echo);
                }
            } else {
                beep();
@@ -171,7 +169,7 @@ wgetn_wstr(WINDOW *win, wint_t *str, int maxlen)
        } else {
            *tmpstr++ = ch;
            *tmpstr = 0;
-           if (oldecho == TRUE) {
+           if (save_flags._echo == TRUE) {
                int oldy = win->_cury;
 
                if (wadd_wint(win, tmpstr - 1) == ERR) {
@@ -181,7 +179,7 @@ wgetn_wstr(WINDOW *win, wint_t *str, int maxlen)
                     */
                    win->_flags &= ~_WRAPPED;
                    waddch(win, (chtype) ' ');
-                   tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho);
+                   tmpstr = WipeOut(win, y, x, oldstr, tmpstr, save_flags._echo);
                    continue;
                } else if (IS_WRAPPED(win)) {
                    /*
@@ -211,11 +209,7 @@ wgetn_wstr(WINDOW *win, wint_t *str, int maxlen)
     /* Restore with a single I/O call, to fix minor asymmetry between
      * raw/noraw, etc.
      */
-    sp->_nl = oldnl;
-    sp->_echo = oldecho;
-    sp->_raw = oldraw;
-    sp->_cbreak = oldcbreak;
-
+    sp->_tty_flags = save_flags;
     (void) _nc_set_tty_mode(&buf);
 
     *tmpstr = 0;