From 165f69023b73898e424949a8c6a2a9de86077cfd Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 30 May 2020 22:11:35 +0200 Subject: [PATCH] LibVT: Allow updating the window progress via an escape sequence You can now request an update of the terminal's window progress by sending this escape sequence: ]9;;; I'm sure we can find many interesting uses for this! :^) --- Kernel/TTY/VirtualConsole.cpp | 5 +++++ Kernel/TTY/VirtualConsole.h | 1 + Libraries/LibVT/Terminal.cpp | 3 +++ Libraries/LibVT/Terminal.h | 1 + Libraries/LibVT/TerminalWidget.cpp | 9 +++++++++ Libraries/LibVT/TerminalWidget.h | 1 + 6 files changed, 20 insertions(+) diff --git a/Kernel/TTY/VirtualConsole.cpp b/Kernel/TTY/VirtualConsole.cpp index 3716421bfe4..f7cb4a376e4 100644 --- a/Kernel/TTY/VirtualConsole.cpp +++ b/Kernel/TTY/VirtualConsole.cpp @@ -307,6 +307,11 @@ void VirtualConsole::set_window_title(const StringView&) // Do nothing. } +void VirtualConsole::set_window_progress(int, int) +{ + // Do nothing. +} + void VirtualConsole::terminal_did_resize(u16 columns, u16 rows) { ASSERT(columns == 80); diff --git a/Kernel/TTY/VirtualConsole.h b/Kernel/TTY/VirtualConsole.h index db9c9b8b01d..44ef39d682e 100644 --- a/Kernel/TTY/VirtualConsole.h +++ b/Kernel/TTY/VirtualConsole.h @@ -59,6 +59,7 @@ private: // ^TerminalClient virtual void beep() override; virtual void set_window_title(const StringView&) override; + virtual void set_window_progress(int, int) override; virtual void terminal_did_resize(u16 columns, u16 rows) override; virtual void terminal_history_changed() override; virtual void emit(const u8*, size_t) override; diff --git a/Libraries/LibVT/Terminal.cpp b/Libraries/LibVT/Terminal.cpp index 22af6fa62bd..42c8dd7aecd 100644 --- a/Libraries/LibVT/Terminal.cpp +++ b/Libraries/LibVT/Terminal.cpp @@ -573,6 +573,9 @@ void Terminal::execute_xterm_command() // FIXME: Respect the provided ID m_current_attribute.href_id = String::format("%u", m_next_href_id++); break; + case 9: + m_client.set_window_progress(numeric_params[1], numeric_params[2]); + break; default: unimplemented_xterm_escape(); break; diff --git a/Libraries/LibVT/Terminal.h b/Libraries/LibVT/Terminal.h index 4f8d10ad50c..1ce3b81d4f4 100644 --- a/Libraries/LibVT/Terminal.h +++ b/Libraries/LibVT/Terminal.h @@ -42,6 +42,7 @@ public: virtual void beep() = 0; virtual void set_window_title(const StringView&) = 0; + virtual void set_window_progress(int value, int max) = 0; virtual void terminal_did_resize(u16 columns, u16 rows) = 0; virtual void terminal_history_changed() = 0; virtual void emit(const u8*, size_t) = 0; diff --git a/Libraries/LibVT/TerminalWidget.cpp b/Libraries/LibVT/TerminalWidget.cpp index aa381566eee..ab666cc6418 100644 --- a/Libraries/LibVT/TerminalWidget.cpp +++ b/Libraries/LibVT/TerminalWidget.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -361,6 +362,14 @@ void TerminalWidget::paint_event(GUI::PaintEvent& event) } } +void TerminalWidget::set_window_progress(int value, int max) +{ + float float_value = value; + float float_max = max; + float progress = (float_value / float_max) * 100.0f; + window()->set_progress((int)roundf(progress)); +} + void TerminalWidget::set_window_title(const StringView& title) { if (!Utf8View(title).validate()) { diff --git a/Libraries/LibVT/TerminalWidget.h b/Libraries/LibVT/TerminalWidget.h index efd46068f1b..6b483089554 100644 --- a/Libraries/LibVT/TerminalWidget.h +++ b/Libraries/LibVT/TerminalWidget.h @@ -108,6 +108,7 @@ private: // ^TerminalClient virtual void beep() override; virtual void set_window_title(const StringView&) override; + virtual void set_window_progress(int value, int max) override; virtual void terminal_did_resize(u16 columns, u16 rows) override; virtual void terminal_history_changed() override; virtual void emit(const u8*, size_t) override;