summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/TODO6
-rw-r--r--include/ttyutils.h1
-rw-r--r--lib/ttyutils.c7
-rw-r--r--term-utils/script.c38
4 files changed, 41 insertions, 11 deletions
diff --git a/Documentation/TODO b/Documentation/TODO
index 2153a810c..4dbc288c9 100644
--- a/Documentation/TODO
+++ b/Documentation/TODO
@@ -15,12 +15,6 @@ column
script
------
- - (!) add terminal type ($TERM), columns and lines to the header line, something like:
-
- Script started on 2018-03-05 13:02:08+0100 [term="xterm-256color", lines=53, columns=190]
-
- see https://github.com/karelzak/util-linux/issues/583
-
- (!) add [exit=<command-exit-code>] to the "done" typescript message
- think about optional "event" records in timing file to save information
diff --git a/include/ttyutils.h b/include/ttyutils.h
index a9baab34b..b3ed4faf1 100644
--- a/include/ttyutils.h
+++ b/include/ttyutils.h
@@ -52,6 +52,7 @@ struct chardata {
extern int get_terminal_dimension(int *cols, int *lines);
extern int get_terminal_width(int default_width);
+extern int get_terminal_type(const char **type);
extern int get_terminal_name(const char **path, const char **name,
const char **number);
diff --git a/lib/ttyutils.c b/lib/ttyutils.c
index 6a1e0e0f3..00a7903ca 100644
--- a/lib/ttyutils.c
+++ b/lib/ttyutils.c
@@ -113,6 +113,13 @@ int get_terminal_name(const char **path,
return 0;
}
+int get_terminal_type(const char **type)
+{
+ *type = getenv("TERM");
+ if (*type)
+ return -EINVAL;
+ return 0;
+}
#ifdef TEST_PROGRAM_TTYUTILS
# include <stdlib.h>
diff --git a/term-utils/script.c b/term-utils/script.c
index 20c35d955..b7bec7e76 100644
--- a/term-utils/script.c
+++ b/term-utils/script.c
@@ -182,6 +182,36 @@ static void __attribute__((__noreturn__)) usage(void)
exit(EXIT_SUCCESS);
}
+static void typescript_message_start(const struct script_control *ctl, time_t *tvec)
+{
+ char buf[FORMAT_TIMESTAMP_MAX];
+ int cols = 0, lines = 0;
+ const char *tty = NULL, *term = NULL;
+
+ if (!ctl->typescriptfp)
+ return;
+
+ strtime_iso(tvec, ISO_TIMESTAMP, buf, sizeof(buf));
+
+ fprintf(ctl->typescriptfp, _("Script started on %s ["), buf);
+
+ if (ctl->isterm) {
+ get_terminal_dimension(&cols, &lines);
+ get_terminal_name(&tty, NULL, NULL);
+ get_terminal_type(&term);
+
+ if (term)
+ fprintf(ctl->typescriptfp, "TERM=\"%s\" ", term);
+ if (tty)
+ fprintf(ctl->typescriptfp, "TTY=\"%s\" ", tty);
+
+ fprintf(ctl->typescriptfp, "COLS=\"%d\" LINES=\"%d\"", cols, lines);
+ } else
+ fprintf(ctl->typescriptfp, _("<not executed on terminal>"));
+
+ fputs("]\n", ctl->typescriptfp);
+}
+
static void die_if_link(const struct script_control *ctl)
{
struct stat s;
@@ -496,11 +526,9 @@ static void do_io(struct script_control *ctl)
}
- if (ctl->typescriptfp) {
- char buf[FORMAT_TIMESTAMP_MAX];
- strtime_iso(&tvec, ISO_TIMESTAMP, buf, sizeof(buf));
- fprintf(ctl->typescriptfp, _("Script started on %s\n"), buf);
- }
+ if (ctl->typescriptfp)
+ typescript_message_start(ctl, &tvec);
+
gettime_monotonic(&ctl->oldtime);
while (!ctl->die) {