Skip to content

Commit c617fce

Browse files
committed
Add info about connection into status bar
1 parent 479ae29 commit c617fce

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

src/view/navigation.rs

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,14 @@ pub trait Navigation {
5252
fn show_fuzzy_actions(&mut self);
5353
fn show_server_flamegraph(&mut self, tui: bool, trace_type: Option<TraceType>);
5454
fn show_jemalloc_flamegraph(&mut self, tui: bool);
55-
fn show_host_filter_dialog(&mut self);
55+
fn show_connection_dialog(&mut self);
5656

5757
fn drop_main_view(&mut self);
5858
fn set_main_view<V: IntoBoxedView + 'static>(&mut self, view: V);
5959

6060
fn set_statusbar_version(&mut self, main_content: impl Into<SpannedString<Style>>);
6161
fn set_statusbar_content(&mut self, content: impl Into<SpannedString<Style>>);
62+
fn set_statusbar_connection(&mut self, content: impl Into<SpannedString<Style>>);
6263

6364
// TODO: move into separate trait
6465
fn call_on_name_or_render_error<V, F>(&mut self, name: &str, callback: F)
@@ -217,14 +218,26 @@ impl Navigation for Cursive {
217218
.child(DummyView.full_width())
218219
.child(TextView::new("").with_name("status"))
219220
.child(DummyView.fixed_width(1))
221+
.child(TextView::new("").with_name("connection"))
222+
.child(DummyView.fixed_width(1))
220223
.child(TextView::new("").with_name("version")),
221224
)
222225
.child(view::SummaryView::new(context.clone()).with_name("summary"))
223226
.with_name("main"),
224227
),
225228
);
226229

227-
self.set_statusbar_version(context.lock().unwrap().server_version.clone());
230+
{
231+
let ctx = context.lock().unwrap();
232+
self.set_statusbar_version(ctx.server_version.clone());
233+
self.set_statusbar_connection(
234+
ctx.options
235+
.clickhouse
236+
.connection
237+
.clone()
238+
.unwrap_or(ctx.options.clickhouse.url_safe.clone()),
239+
);
240+
}
228241

229242
let start_view = context
230243
.lock()
@@ -253,7 +266,7 @@ impl Navigation for Cursive {
253266
context.add_global_action(self, "Fuzzy actions", Event::CtrlChar('p'), |siv| siv.show_fuzzy_actions());
254267

255268
if context.options.clickhouse.cluster.is_some() {
256-
context.add_global_action(self, "Filter by host", Event::CtrlChar('h'), |siv| siv.show_host_filter_dialog());
269+
context.add_global_action(self, "Filter by host", Event::CtrlChar('h'), |siv| siv.show_connection_dialog());
257270
}
258271

259272
context.add_global_action(self, "Server CPU Flamegraph", 'F', |siv| siv.show_server_flamegraph(true, Some(TraceType::CPU)));
@@ -597,7 +610,7 @@ impl Navigation for Cursive {
597610
.send(true, WorkerEvent::JemallocFlameGraph(tui));
598611
}
599612

600-
fn show_host_filter_dialog(&mut self) {
613+
fn show_connection_dialog(&mut self) {
601614
let context_arc = self.user_data::<ContextArc>().unwrap().clone();
602615
let context = context_arc.lock().unwrap();
603616

@@ -634,15 +647,17 @@ impl Navigation for Cursive {
634647
let current_view = {
635648
let mut context = context_arc.lock().unwrap();
636649

650+
let url_safe = context.options.clickhouse.url_safe.clone();
637651
if selected_host.is_empty() {
638652
context.selected_host = None;
639653
log::info!("Reset host filter");
640-
siv.set_statusbar_content("");
654+
siv.set_statusbar_connection(url_safe);
641655
} else {
642656
context.selected_host = Some(selected_host.clone());
643657
log::info!("Set host filter to: {}", selected_host);
644-
let status_msg = format!("Host filter: {}", selected_host);
645-
siv.set_statusbar_content(status_msg);
658+
siv.set_statusbar_connection(format!(
659+
"{url_safe} (host: {selected_host})"
660+
));
646661
}
647662

648663
// Get current view name to re-open it
@@ -733,6 +748,13 @@ impl Navigation for Cursive {
733748
.expect("set_status")
734749
}
735750

751+
fn set_statusbar_connection(&mut self, content: impl Into<SpannedString<Style>>) {
752+
self.call_on_name("connection", |text_view: &mut TextView| {
753+
text_view.set_content(content);
754+
})
755+
.expect("connection");
756+
}
757+
736758
fn call_on_name_or_render_error<V, F>(&mut self, name: &str, callback: F)
737759
where
738760
V: View,

0 commit comments

Comments
 (0)