Skip to content

Commit 509e90a

Browse files
no1wudixiaoxiang781216
authored andcommitted
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 <huangqi3@xiaomi.com>
1 parent b370f77 commit 509e90a

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

system/termcurses/tcurses_vt100.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <debug.h>
3737
#include <stdio.h>
3838
#include <stdlib.h>
39+
#include <termios.h>
3940

4041
#include "tcurses_priv.h"
4142
#include "graphics/curses.h"
@@ -74,6 +75,9 @@ struct tcurses_vt100_s
7475
int out_fd;
7576
int keycount;
7677
char keybuf[16];
78+
#ifdef CONFIG_SERIAL_TERMIOS
79+
tcflag_t iflag;
80+
#endif
7781
};
7882

7983
/************************************************************************************
@@ -1465,6 +1469,9 @@ static bool tcurses_vt100_checkkey(FAR struct termcurses_s *dev)
14651469
FAR struct termcurses_s *tcurses_vt100_initialize(int in_fd, int out_fd)
14661470
{
14671471
FAR struct tcurses_vt100_s *priv;
1472+
#ifdef CONFIG_SERIAL_TERMIOS
1473+
struct termios cfg;
1474+
#endif
14681475

14691476
/* Allocate a new device structure */
14701477

@@ -1483,6 +1490,34 @@ FAR struct termcurses_s *tcurses_vt100_initialize(int in_fd, int out_fd)
14831490
priv->out_fd = out_fd;
14841491
priv->keycount = 0;
14851492

1493+
#ifdef CONFIG_SERIAL_TERMIOS
1494+
if (isatty(priv->in_fd))
1495+
{
1496+
if (tcgetattr(priv->in_fd, &cfg) == 0)
1497+
{
1498+
/* Save current iflags */
1499+
1500+
priv->iflag = cfg.c_iflag;
1501+
1502+
/* If ECHO enabled, disable it */
1503+
1504+
if (cfg.c_iflag & ECHO)
1505+
{
1506+
cfg.c_iflag &= ~ECHO;
1507+
tcsetattr(priv->in_fd, TCSANOW, &cfg);
1508+
}
1509+
}
1510+
else
1511+
{
1512+
/* Get attr failed, mark ECHO bit zero to skip set attr in
1513+
* tcurses_vt100_terminate
1514+
*/
1515+
1516+
priv->iflag = 0;
1517+
}
1518+
}
1519+
#endif
1520+
14861521
return (FAR struct termcurses_s *)priv;
14871522
}
14881523

@@ -1498,6 +1533,9 @@ static int tcurses_vt100_terminate(FAR struct termcurses_s *dev)
14981533
{
14991534
FAR struct tcurses_vt100_s *priv;
15001535
int fd;
1536+
#ifdef CONFIG_SERIAL_TERMIOS
1537+
struct termios cfg;
1538+
#endif
15011539

15021540
priv = (FAR struct tcurses_vt100_s *)dev;
15031541
fd = priv->out_fd;
@@ -1508,5 +1546,16 @@ static int tcurses_vt100_terminate(FAR struct termcurses_s *dev)
15081546

15091547
write(fd, g_setdefcolors, strlen(g_setdefcolors));
15101548

1549+
#ifdef CONFIG_SERIAL_TERMIOS
1550+
if (isatty(priv->in_fd))
1551+
{
1552+
if (tcgetattr(priv->in_fd, &cfg) == 0 && priv->iflag & ECHO)
1553+
{
1554+
cfg.c_iflag |= ECHO;
1555+
tcsetattr(priv->in_fd, TCSANOW, &cfg);
1556+
}
1557+
}
1558+
#endif
1559+
15111560
return OK;
15121561
}

0 commit comments

Comments
 (0)