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 baf5509b5 nshlib: Add support for disabling echoback
baf5509b5 is described below
commit baf5509b59619051601f7d5271a95c5edb149dde
Author: Takumi Ando <[email protected]>
AuthorDate: Mon May 15 17:44:46 2023 +0900
nshlib: Add support for disabling echoback
If CONFIG_NSH_DISABLE_ECHOBACK is selected,
the NSH disables echoback prompt.
Signed-off-by: Takumi Ando <[email protected]>
---
nshlib/Kconfig | 6 ++++++
nshlib/nsh_session.c | 16 ++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/nshlib/Kconfig b/nshlib/Kconfig
index 196af77a1..2ecefc6d7 100644
--- a/nshlib/Kconfig
+++ b/nshlib/Kconfig
@@ -70,6 +70,12 @@ config NSH_PROMPT_STRING
---help---
Provide the shell prompt string, default is "nsh> ".
+config NSH_DISABLE_ECHOBACK
+ bool "Disable echoback"
+ default n
+ ---help---
+ If this option is selected, the NSH disables echoback.
+
choice
prompt "Command Line Editor"
default NSH_READLINE if DEFAULT_SMALL
diff --git a/nshlib/nsh_session.c b/nshlib/nsh_session.c
index 4e5621552..4c254ddde 100644
--- a/nshlib/nsh_session.c
+++ b/nshlib/nsh_session.c
@@ -28,6 +28,7 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
+#include <termios.h>
#ifdef CONFIG_NSH_CLE
# include "system/cle.h"
@@ -169,6 +170,21 @@ int nsh_session(FAR struct console_stdio_s *pstate,
}
}
+#ifdef CONFIG_NSH_DISABLE_ECHOBACK
+ /* Disable echoback */
+
+ if (isatty(INFD(pstate)))
+ {
+ struct termios cfg;
+
+ if (tcgetattr(INFD(pstate), &cfg) == 0)
+ {
+ cfg.c_lflag &= ~ECHO;
+ tcsetattr(INFD(pstate), TCSANOW, &cfg);
+ }
+ }
+#endif
+
/* Then enter the command line parsing loop */
for (; ; )