summaryrefslogtreecommitdiff
path: root/src/shell_manager.cc
diff options
context:
space:
mode:
authorJohannes Altmanninger <aclopte@gmail.com>2024-11-24 10:19:32 +0100
committerMaxime Coste <mawww@kakoune.org>2024-12-09 22:23:35 +1100
commit7105584538f84d1c244809601fd3e573e8d6080c (patch)
treeca1e38b5fb7fd6862fb917212af817e3328f1412 /src/shell_manager.cc
parent816a8c35a8cfa0cc8b7f9d80dd3c0e721ba3c273 (diff)
Print elapsed time when blocked on opening file for writing
Extract the logic for "waiting for shell to finish" and reuse it for potentially blocking calls to open() that use the O_WRONLY flags.
Diffstat (limited to 'src/shell_manager.cc')
-rw-r--r--src/shell_manager.cc30
1 files changed, 6 insertions, 24 deletions
diff --git a/src/shell_manager.cc b/src/shell_manager.cc
index 6b656191..0baf77c8 100644
--- a/src/shell_manager.cc
+++ b/src/shell_manager.cc
@@ -14,6 +14,7 @@
#include "regex.hh"
#include <array>
+#include <chrono>
#include <cstring>
#include <sys/types.h>
#include <sys/wait.h>
@@ -316,24 +317,11 @@ std::pair<String, int> ShellManager::eval(
bool failed = false;
using namespace std::chrono;
- static constexpr seconds wait_timeout{1};
- Optional<DisplayLine> previous_status;
- Timer wait_timer{wait_time + wait_timeout, [&](Timer& timer) {
- if (not context.has_client())
- return;
-
- const auto now = Clock::now();
- timer.set_next_date(now + wait_timeout);
- auto& client = context.client();
- if (not previous_status)
- previous_status = client.current_status();
-
- client.print_status({format("waiting for shell command to finish{} ({}s)",
- terminated ? " (shell terminated)" : "",
- duration_cast<seconds>(now - wait_time).count()),
- context.faces()[failed ? "Error" : "Information"]});
- client.redraw_ifn();
- }, EventMode::Urgent};
+ BusyIndicator busy_indicator{context, [&](seconds elapsed) {
+ return DisplayLine{format("waiting for shell command to finish{} ({}s)",
+ terminated ? " (shell terminated)" : "", elapsed.count()),
+ context.faces()[failed ? "Error" : "Information"]};
+ }};
bool cancelling = false;
while (not terminated or shell.in or
@@ -373,12 +361,6 @@ std::pair<String, int> ShellManager::eval(
if (cancelling)
throw cancel{};
- if (previous_status) // restore the status line
- {
- context.print_status(std::move(*previous_status));
- context.client().redraw_ifn();
- }
-
return { std::move(stdout_contents), WIFEXITED(status) ? WEXITSTATUS(status) : -1 };
}