]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
scriptlive: add --echo <never|always|auto>
authorKarel Zak <kzak@redhat.com>
Tue, 23 Jul 2024 11:57:46 +0000 (13:57 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 23 Jul 2024 11:57:46 +0000 (13:57 +0200)
It would be beneficial to have a method for controlling the ECHO flag.

References: https://github.com/util-linux/util-linux/pull/3133
Signed-off-by: Karel Zak <kzak@redhat.com>
term-utils/scriptlive.1.adoc
term-utils/scriptlive.c

index 73e8faf5d3b36f7a37675a622887fb4e9d4ca1aa..1efb429bb6e7d0628d8d63adf5039245f0f6cc75 100644 (file)
@@ -33,6 +33,11 @@ File containing *script*'s terminal input.
 *-B*, *--log-io* _file_::
 File containing *script*'s terminal output and input.
 
+*-E*, *--echo* _when_::
+This option controls the *ECHO* flag for the slave end of the session's pseudoterminal. The supported modes are _always_, _never_, or _auto_.
++
+The default is _auto_ -- in this case, *ECHO* enabled; this default behavior is subject to change.
+
 *-t*, *--timing* _file_::
 File containing *script*'s timing output. This option overrides old-style arguments.
 
index 36c195cc0d6e09a22efe9c087f983f14023692ea..af946a08d05f704426c54d17ba199494f200f3fa 100644 (file)
@@ -72,6 +72,7 @@ usage(void)
        fputs(USAGE_SEPARATOR, out);
        fputs(_(" -c, --command <command> run command rather than interactive shell\n"), out);
        fputs(_(" -d, --divisor <num>     speed up or slow down execution with time divisor\n"), out);
+       fputs(_(" -E, --echo <when>       echo input in session (auto, always or never)\n"), out);
        fputs(_(" -m, --maxdelay <num>    wait at most this many seconds between updates\n"), out);
        fprintf(out, USAGE_HELP_OPTIONS(25));
 
@@ -164,13 +165,14 @@ main(int argc, char *argv[])
                   *shell = NULL, *command = NULL;
        double divi = 1;
        int diviopt = FALSE, idx;
-       int ch, caught_signal = 0;
+       int ch, caught_signal = 0, echo = 1;
        struct ul_pty_callbacks *cb;
        struct scriptlive ss = { .pty = NULL };
        pid_t child;
 
        static const struct option longopts[] = {
                { "command",    required_argument,      0, 'c' },
+               { "echo",       required_argument,      0, 'E' },
                { "timing",     required_argument,      0, 't' },
                { "log-timing", required_argument,      0, 'T' },
                { "log-in",     required_argument,      0, 'I'},
@@ -200,7 +202,7 @@ main(int argc, char *argv[])
        replay_init_debug();
        timerclear(&maxdelay);
 
-       while ((ch = getopt_long(argc, argv, "c:B:I:T:t:d:m:Vh", longopts, NULL)) != -1) {
+       while ((ch = getopt_long(argc, argv, "c:B:E:I:T:t:d:m:Vh", longopts, NULL)) != -1) {
 
                err_exclusive_options(ch, longopts, excl, excl_st);
 
@@ -208,6 +210,16 @@ main(int argc, char *argv[])
                case 'c':
                        command = optarg;
                        break;
+               case 'E':
+                       if (strcmp(optarg, "auto") == 0)
+                               ; /* keep default */
+                       else if (strcmp(optarg, "never") == 0)
+                               echo = 0;
+                       else if (strcmp(optarg, "always") == 0)
+                               echo = 1;
+                       else
+                               errx(EXIT_FAILURE, _("unssuported echo mode: '%s'"), optarg);
+                       break;
                case 't':
                case 'T':
                        log_tm = optarg;
@@ -289,7 +301,7 @@ main(int argc, char *argv[])
        cb->mainloop = mainloop_cb;
 
        /* We keep ECHO flag for compatibility with script(1) */
-       ul_pty_slave_echo(ss.pty, 1);
+       ul_pty_slave_echo(ss.pty, echo);
 
        if (ul_pty_setup(ss.pty))
                err(EXIT_FAILURE, _("failed to create pseudo-terminal"));