diff options
| author | Johannes Altmanninger <aclopte@gmail.com> | 2024-11-24 10:19:32 +0100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2024-12-09 22:23:35 +1100 |
| commit | 7105584538f84d1c244809601fd3e573e8d6080c (patch) | |
| tree | ca1e38b5fb7fd6862fb917212af817e3328f1412 /src/client.cc | |
| parent | 816a8c35a8cfa0cc8b7f9d80dd3c0e721ba3c273 (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/client.cc')
| -rw-r--r-- | src/client.cc | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/client.cc b/src/client.cc index 611216a7..2fa8e8fb 100644 --- a/src/client.cc +++ b/src/client.cc @@ -1,5 +1,6 @@ #include "client.hh" +#include "clock.hh" #include "context.hh" #include "buffer_utils.hh" #include "debug.hh" @@ -509,4 +510,35 @@ void Client::clear_pending() m_pending_clear = PendingClear::None; } +constexpr std::chrono::seconds wait_timeout{1}; + +BusyIndicator::BusyIndicator(const Context& context, + std::function<DisplayLine(std::chrono::seconds)> status_message, + TimePoint wait_time) + : m_context(context), + m_timer{wait_time + wait_timeout, + [this, status_message = std::move(status_message), wait_time](Timer& timer) { + if (not m_context.has_client()) + return; + using namespace std::chrono; + const auto now = Clock::now(); + timer.set_next_date(now + wait_timeout); + + auto& client = m_context.client(); + if (not m_previous_status) + m_previous_status = client.current_status(); + + client.print_status(status_message(duration_cast<seconds>(now - wait_time))); + client.redraw_ifn(); + }, EventMode::Urgent} {} + +BusyIndicator::~BusyIndicator() +{ + if (m_previous_status and std::uncaught_exceptions() == 0) // restore the status line + { + m_context.print_status(std::move(*m_previous_status)); + m_context.client().redraw_ifn(); + } +} + } |
