summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2024-10-29 21:00:15 +0100
committerGitHub <noreply@github.com>2024-10-29 21:00:15 +0100
commit1322af50e59ccd0e1e18194e7ea0aa6f4e872acb (patch)
tree648bd04ec940d409ee3ee73e70051d5e111c122c
parentsysusers: optionally create fully locked accounts (#34876) (diff)
parentmeson.build: do not mark test-progress-bar as manual (diff)
downloadsystemd-1322af50e59ccd0e1e18194e7ea0aa6f4e872acb.tar.xz
systemd-1322af50e59ccd0e1e18194e7ea0aa6f4e872acb.zip
progress-bar: issue Windows Terminal progress indicating ANSI sequences (#34929)
This generates the Windows Terminal OSC sequences indicating progress. This let's the terminal know that we are doing a slow operation, and how we are progressing. Windows Terminal uses this in two ways: it shows a circle in the tab that completes, and it highlights the progress in the task bar. I found no Linux terminal that currently supports it, but also none that didn't like it. Thankfully most terminals correctly ignore unrecognized OSC sequences. I think we should just merge this, and see if this trips up too many people, but I have reason to believe this shouldn't be too bad. And yes, I do work from Windows Terminal sometimes, ssh into my Linux build systems, and it is really cute seeing the progress animation there.
-rw-r--r--src/shared/pretty-print.c15
-rw-r--r--src/test/meson.build1
2 files changed, 13 insertions, 3 deletions
diff --git a/src/shared/pretty-print.c b/src/shared/pretty-print.c
index 0360fa9d72..322d5f496d 100644
--- a/src/shared/pretty-print.c
+++ b/src/shared/pretty-print.c
@@ -1,8 +1,9 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
-#include <sys/utsname.h>
#include <errno.h>
+#include <math.h>
#include <stdio.h>
+#include <sys/utsname.h>
#include "alloc-util.h"
#include "color-util.h"
@@ -468,6 +469,14 @@ void draw_progress_bar_impl(const char *prefix, double percentage) {
}
if (!terminal_is_dumb()) {
+ /* Generate the Windows Terminal progress indication OSC sequence here. Most Linux terminals currently
+ * ignore this. But let's hope this changes one day. For details about this OSC sequence, see:
+ *
+ * https://conemu.github.io/en/AnsiEscapeCodes.html#ConEmu_specific_OSC
+ * https://github.com/microsoft/terminal/pull/8055
+ */
+ fprintf(stderr, "\x1B]9;4;1;%u\a", (unsigned) ceil(percentage));
+
size_t cols = columns();
size_t prefix_width = utf8_console_width(prefix) + 1 /* space */;
size_t length = cols > prefix_width + 6 ? cols - prefix_width - 6 : 0;
@@ -525,7 +534,9 @@ void clear_progress_bar_impl(const char *prefix) {
LESS_BY(columns(), 1U)),
stderr);
else
- fputs(ANSI_ERASE_TO_END_OF_LINE, stderr);
+ /* Undo Windows Terminal progress indication again. */
+ fputs("\x1B]9;4;0;;\a"
+ ANSI_ERASE_TO_END_OF_LINE, stderr);
fputc('\r', stderr);
}
diff --git a/src/test/meson.build b/src/test/meson.build
index b8699a016b..2157e7c1f3 100644
--- a/src/test/meson.build
+++ b/src/test/meson.build
@@ -378,7 +378,6 @@ executables += [
},
test_template + {
'sources' : files('test-progress-bar.c'),
- 'type' : 'manual',
},
test_template + {
'sources' : files('test-qrcode-util.c'),