36
36
#include <debug.h>
37
37
#include <stdio.h>
38
38
#include <stdlib.h>
39
+ #include <termios.h>
39
40
40
41
#include "tcurses_priv.h"
41
42
#include "graphics/curses.h"
@@ -74,6 +75,9 @@ struct tcurses_vt100_s
74
75
int out_fd ;
75
76
int keycount ;
76
77
char keybuf [16 ];
78
+ #ifdef CONFIG_SERIAL_TERMIOS
79
+ tcflag_t iflag ;
80
+ #endif
77
81
};
78
82
79
83
/************************************************************************************
@@ -1465,6 +1469,9 @@ static bool tcurses_vt100_checkkey(FAR struct termcurses_s *dev)
1465
1469
FAR struct termcurses_s * tcurses_vt100_initialize (int in_fd , int out_fd )
1466
1470
{
1467
1471
FAR struct tcurses_vt100_s * priv ;
1472
+ #ifdef CONFIG_SERIAL_TERMIOS
1473
+ struct termios cfg ;
1474
+ #endif
1468
1475
1469
1476
/* Allocate a new device structure */
1470
1477
@@ -1483,6 +1490,34 @@ FAR struct termcurses_s *tcurses_vt100_initialize(int in_fd, int out_fd)
1483
1490
priv -> out_fd = out_fd ;
1484
1491
priv -> keycount = 0 ;
1485
1492
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
+
1486
1521
return (FAR struct termcurses_s * )priv ;
1487
1522
}
1488
1523
@@ -1498,6 +1533,9 @@ static int tcurses_vt100_terminate(FAR struct termcurses_s *dev)
1498
1533
{
1499
1534
FAR struct tcurses_vt100_s * priv ;
1500
1535
int fd ;
1536
+ #ifdef CONFIG_SERIAL_TERMIOS
1537
+ struct termios cfg ;
1538
+ #endif
1501
1539
1502
1540
priv = (FAR struct tcurses_vt100_s * )dev ;
1503
1541
fd = priv -> out_fd ;
@@ -1508,5 +1546,16 @@ static int tcurses_vt100_terminate(FAR struct termcurses_s *dev)
1508
1546
1509
1547
write (fd , g_setdefcolors , strlen (g_setdefcolors ));
1510
1548
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
+
1511
1560
return OK ;
1512
1561
}
0 commit comments