Skip to content

Commit a72d597

Browse files
committed
[ui] refresh status bars when waiting for init command
1 parent 1e31b65 commit a72d597

5 files changed

Lines changed: 74 additions & 66 deletions

File tree

src/base/func_util.hh

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
#include <functional>
3434
#include <utility>
3535

36-
#include "progress.hh"
37-
3836
template<typename F, typename FrontArg>
3937
decltype(auto)
4038
bind_mem(F&& f, FrontArg&& frontArg)
@@ -69,63 +67,6 @@ struct noop_func {
6967

7068
namespace lnav::func {
7169

72-
enum class op_type {
73-
blocking,
74-
interactive,
75-
};
76-
77-
class scoped_cb {
78-
public:
79-
using callback_type = std::function<progress_result_t(op_type)>;
80-
81-
class guard {
82-
public:
83-
explicit guard(scoped_cb* owner) : g_owner(owner) {}
84-
85-
guard(const guard&) = delete;
86-
guard& operator=(const guard&) = delete;
87-
88-
guard(guard&& gu) noexcept : g_owner(std::exchange(gu.g_owner, nullptr))
89-
{
90-
}
91-
92-
guard& operator=(guard&& gu) noexcept
93-
{
94-
this->g_owner = std::exchange(gu.g_owner, nullptr);
95-
return *this;
96-
}
97-
98-
~guard()
99-
{
100-
if (this->g_owner != nullptr) {
101-
this->g_owner->s_callback = {};
102-
}
103-
}
104-
105-
private:
106-
scoped_cb* g_owner;
107-
};
108-
109-
guard install(callback_type cb)
110-
{
111-
this->s_callback = std::move(cb);
112-
113-
return guard{this};
114-
}
115-
116-
progress_result_t operator()(op_type ot) const
117-
{
118-
if (s_callback) {
119-
return s_callback(ot);
120-
}
121-
122-
return progress_result_t::ok;
123-
}
124-
125-
private:
126-
callback_type s_callback;
127-
};
128-
12970
template<typename Fn,
13071
typename... Args,
13172
std::enable_if_t<std::is_member_pointer<std::decay_t<Fn>>{}, int> = 0>

src/base/progress.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
#include "progress.hh"
3131

32+
using namespace std::chrono_literals;
33+
3234
namespace lnav {
3335

3436
progress_tracker&
@@ -46,7 +48,7 @@ progress_tracker::get_tasks()
4648
}
4749

4850
void
49-
progress_tracker::wait_for_completion()
51+
progress_tracker::wait_for_completion(func::scoped_cb* scoped_cb)
5052
{
5153
std::unique_lock<std::mutex> lock(this->pt_mutex);
5254

@@ -65,9 +67,12 @@ progress_tracker::wait_for_completion()
6567
}
6668

6769
auto init_version = this->pt_version;
68-
this->pt_cv.wait(lock, [&] {
69-
return this->pt_abort || init_version != this->pt_version;
70-
});
70+
while (!this->pt_abort && init_version == this->pt_version) {
71+
this->pt_cv.wait_for(lock, 100ms);
72+
if (scoped_cb != nullptr) {
73+
(*scoped_cb)(func::op_type::blocking);
74+
}
75+
}
7176
}
7277

7378
void

src/base/progress.hh

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <vector>
3838

3939
#include "distributed_slice.hh"
40+
#include "func_util.hh"
4041
#include "lnav.console.hh"
4142
#include "safe/safe.h"
4243

@@ -52,6 +53,67 @@ enum class progress_status_t : uint8_t {
5253
working,
5354
};
5455

56+
namespace func {
57+
58+
enum class op_type {
59+
blocking,
60+
interactive,
61+
};
62+
63+
class scoped_cb {
64+
public:
65+
using callback_type = std::function<progress_result_t(op_type)>;
66+
67+
class guard {
68+
public:
69+
explicit guard(scoped_cb* owner) : g_owner(owner) {}
70+
71+
guard(const guard&) = delete;
72+
guard& operator=(const guard&) = delete;
73+
74+
guard(guard&& gu) noexcept : g_owner(std::exchange(gu.g_owner, nullptr))
75+
{
76+
}
77+
78+
guard& operator=(guard&& gu) noexcept
79+
{
80+
this->g_owner = std::exchange(gu.g_owner, nullptr);
81+
return *this;
82+
}
83+
84+
~guard()
85+
{
86+
if (this->g_owner != nullptr) {
87+
this->g_owner->s_callback = {};
88+
}
89+
}
90+
91+
private:
92+
scoped_cb* g_owner;
93+
};
94+
95+
guard install(callback_type cb)
96+
{
97+
this->s_callback = std::move(cb);
98+
99+
return guard{this};
100+
}
101+
102+
progress_result_t operator()(op_type ot) const
103+
{
104+
if (s_callback) {
105+
return s_callback(ot);
106+
}
107+
108+
return progress_result_t::ok;
109+
}
110+
111+
private:
112+
callback_type s_callback;
113+
};
114+
115+
} // namespace func
116+
55117
struct task_progress {
56118
std::string tp_id;
57119
progress_status_t tp_status{progress_status_t::idle};
@@ -73,7 +135,7 @@ struct progress_tracker {
73135

74136
static safe_task_container& get_tasks();
75137

76-
void wait_for_completion();
138+
void wait_for_completion(func::scoped_cb* scoped_cb);
77139

78140
void notify_completion();
79141

src/command_executor.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ execute_init_commands(
10091009
setup_initial_view_stack();
10101010
}
10111011

1012-
lnav::progress_tracker::instance().wait_for_completion();
1012+
lnav::progress_tracker::instance().wait_for_completion(&lnav_data.ld_status_refresher);
10131013
}
10141014
}
10151015
}

src/third-party/lnav-rs-ext/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)