This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new 509e90aad termcurses: Disable echo for serial driver
509e90aad is described below
commit 509e90aadcb6b080d12ed163a9de4d21813c005f
Author: Huang Qi <[email protected]>
AuthorDate: Sat Mar 4 20:16:41 2023 +0800
termcurses: Disable echo for serial driver
Since termcurse will control whole echo and vt100 command itself.
This fix the dupped character in VI's command mode and some display issue
in editor mode, like:
```
~
~
~
~
:qq!!
```
Signed-off-by: Huang Qi <[email protected]>
---
system/termcurses/tcurses_vt100.c | 49 +++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/system/termcurses/tcurses_vt100.c
b/system/termcurses/tcurses_vt100.c
index 98c8ed881..ed8ec278c 100644
--- a/system/termcurses/tcurses_vt100.c
+++ b/system/termcurses/tcurses_vt100.c
@@ -36,6 +36,7 @@
#include <debug.h>
#include <stdio.h>
#include <stdlib.h>
+#include <termios.h>
#include "tcurses_priv.h"
#include "graphics/curses.h"
@@ -74,6 +75,9 @@ struct tcurses_vt100_s
int out_fd;
int keycount;
char keybuf[16];
+#ifdef CONFIG_SERIAL_TERMIOS
+ tcflag_t iflag;
+#endif
};
/************************************************************************************
@@ -1465,6 +1469,9 @@ static bool tcurses_vt100_checkkey(FAR struct
termcurses_s *dev)
FAR struct termcurses_s *tcurses_vt100_initialize(int in_fd, int out_fd)
{
FAR struct tcurses_vt100_s *priv;
+#ifdef CONFIG_SERIAL_TERMIOS
+ struct termios cfg;
+#endif
/* Allocate a new device structure */
@@ -1483,6 +1490,34 @@ FAR struct termcurses_s *tcurses_vt100_initialize(int
in_fd, int out_fd)
priv->out_fd = out_fd;
priv->keycount = 0;
+#ifdef CONFIG_SERIAL_TERMIOS
+ if (isatty(priv->in_fd))
+ {
+ if (tcgetattr(priv->in_fd, &cfg) == 0)
+ {
+ /* Save current iflags */
+
+ priv->iflag = cfg.c_iflag;
+
+ /* If ECHO enabled, disable it */
+
+ if (cfg.c_iflag & ECHO)
+ {
+ cfg.c_iflag &= ~ECHO;
+ tcsetattr(priv->in_fd, TCSANOW, &cfg);
+ }
+ }
+ else
+ {
+ /* Get attr failed, mark ECHO bit zero to skip set attr in
+ * tcurses_vt100_terminate
+ */
+
+ priv->iflag = 0;
+ }
+ }
+#endif
+
return (FAR struct termcurses_s *)priv;
}
@@ -1498,6 +1533,9 @@ static int tcurses_vt100_terminate(FAR struct
termcurses_s *dev)
{
FAR struct tcurses_vt100_s *priv;
int fd;
+#ifdef CONFIG_SERIAL_TERMIOS
+ struct termios cfg;
+#endif
priv = (FAR struct tcurses_vt100_s *)dev;
fd = priv->out_fd;
@@ -1508,5 +1546,16 @@ static int tcurses_vt100_terminate(FAR struct
termcurses_s *dev)
write(fd, g_setdefcolors, strlen(g_setdefcolors));
+#ifdef CONFIG_SERIAL_TERMIOS
+ if (isatty(priv->in_fd))
+ {
+ if (tcgetattr(priv->in_fd, &cfg) == 0 && priv->iflag & ECHO)
+ {
+ cfg.c_iflag |= ECHO;
+ tcsetattr(priv->in_fd, TCSANOW, &cfg);
+ }
+ }
+#endif
+
return OK;
}