[PATCH] Add feature to disable echo (-E)

20 views
Skip to first unread message

Sergey Nazaryev

unread,
Mar 1, 2022, 8:41:23 AM3/1/22
to klis...@googlegroups.com, Sergey Nazaryev
This feature can be helpful while using klish on top of serial port
and someone uses it in non-interactive way. For instance, this can be
applied in case when shell commands are used for inter-device
communication.

Signed-off-by: Sergey Nazaryev <ser...@coolautomation.com>
---
bin/clish.c | 10 +++++++++-
clish/shell.h | 1 +
clish/shell/shell_tinyrl.c | 6 ++++++
3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/bin/clish.c b/bin/clish.c
index 764cc94..5f81989 100644
--- a/bin/clish.c
+++ b/bin/clish.c
@@ -62,6 +62,7 @@ int main(int argc, char **argv)
bool_t utf8 = BOOL_FALSE;
bool_t bit8 = BOOL_FALSE;
bool_t log = BOOL_FALSE;
+ bool_t no_echo = BOOL_FALSE;
int log_facility = LOG_LOCAL0;
bool_t dryrun = BOOL_FALSE;
bool_t dryrun_config = BOOL_FALSE;
@@ -86,7 +87,7 @@ int main(int argc, char **argv)
struct sigaction sigpipe_act;
sigset_t sigpipe_set;

- static const char *shortopts = "hvs:ledx:w:i:bqu8oO:kKt:c:f:z:p:";
+ static const char *shortopts = "hvs:ledx:w:i:bqu8oO:kKt:c:f:z:p:E";
#ifdef HAVE_GETOPT_LONG
static const struct option longopts[] = {
{"help", 0, NULL, 'h'},
@@ -94,6 +95,7 @@ int main(int argc, char **argv)
{"socket", 1, NULL, 's'},
{"lockless", 0, NULL, 'l'},
{"stop-on-error", 0, NULL, 'e'},
+ {"no-echo", 0, NULL, 'E'},
{"dry-run", 0, NULL, 'd'},
{"xml-path", 1, NULL, 'x'},
{"view", 1, NULL, 'w'},
@@ -163,6 +165,9 @@ int main(int argc, char **argv)
case '8':
bit8 = BOOL_TRUE;
break;
+ case 'E':
+ no_echo = BOOL_TRUE;
+ break;
case 'o':
log = BOOL_TRUE;
break;
@@ -279,6 +284,8 @@ int main(int argc, char **argv)
/* Set startup viewid */
if (viewid)
clish_shell__set_startup_viewid(shell, viewid);
+ if (no_echo)
+ clish_shell__disable_echo(shell);
/* Set UTF-8 or 8-bit mode */
if (utf8 || bit8)
clish_shell__set_utf8(shell, utf8);
@@ -413,6 +420,7 @@ static void help(int status, const char *argv0)
"\n\t\tof the konfd daemon.\n");
printf("\t-l, --lockless\tDon't use locking mechanism.\n");
printf("\t-e, --stop-on-error\tStop script execution on error.\n");
+ printf("\t-E, --no-echo\tDisable echo.\n");
printf("\t-b, --background\tStart shell using non-interactive mode.\n");
printf("\t-q, --quiet\tDisable echo while executing commands\n\t\tfrom the file stream.\n");
printf("\t-d, --dry-run\tDon't actually execute ACTION scripts.\n");
diff --git a/clish/shell.h b/clish/shell.h
index c51870b..9173db6 100644
--- a/clish/shell.h
+++ b/clish/shell.h
@@ -193,6 +193,7 @@ int clish_shell__save_history(const clish_shell_t *instance, const char *fname);
int clish_shell__restore_history(clish_shell_t *instance, const char *fname);
void clish_shell__stifle_history(clish_shell_t *instance, unsigned int stifle);
char *clish_shell_format_username(const clish_shell_t *instance);
+void clish_shell__disable_echo(clish_shell_t *instance);

/* Plugin functions */
clish_plugin_t * clish_shell_create_plugin(clish_shell_t *instance,
diff --git a/clish/shell/shell_tinyrl.c b/clish/shell/shell_tinyrl.c
index 880eafe..77fa020 100644
--- a/clish/shell/shell_tinyrl.c
+++ b/clish/shell/shell_tinyrl.c
@@ -618,6 +618,12 @@ void clish_shell__stifle_history(clish_shell_t *this, unsigned int stifle)
tinyrl__stifle_history(this->tinyrl, stifle);
}

+/*----------------------------------------------------------*/
+void clish_shell__disable_echo(clish_shell_t *this)
+{
+ tinyrl_disable_echo(this->tinyrl, '\0');
+}
+
CLISH_SET(shell, unsigned int, idle_timeout);
CLISH_SET(shell, bool_t, interactive);
CLISH_GET(shell, bool_t, interactive);
--
2.30.2

Serj Kalichev

unread,
Mar 2, 2022, 1:00:06 PM3/2/22
to klis...@googlegroups.com
Applied.
Thanks!

See -q clish option for non-interactive mode.
Also see "clish" plugin:
CLISH_PLUGIN_SYM(clish_machine_interface)
CLISH_PLUGIN_SYM(clish_human_interface)

Machine interface is for inter-device automation. In this mode you can
get operation return code.


01.03.2022 16:40, Sergey Nazaryev пишет:
Reply all
Reply to author
Forward
0 new messages