Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 143 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ cursive-syntect = { version = "*", default-features = true }
unicode-width = "0.1"
cursive-flexi-logger-view = { git = "https://github.com/azat-rust/cursive-flexi-logger-view", branch = "next", default-features = false }
syntect = { version = "*", default-features = false, features = ["default-syntaxes", "default-themes"] }
arboard = { version = "*", default-features = false }
clickhouse-rs = { git = "https://github.com/azat-rust/clickhouse-rs", branch = "next", default-features = false, features = ["tokio_io"] }
tokio = { version = "*", default-features = false, features = ["macros"] }
# Flamegraphs
Expand Down
1 change: 1 addition & 0 deletions Documentation/Actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Here is a list of available shortcuts
| | | Show live flamegraph in speedscope |
| | **Alt+E** | Edit query and execute |
| | **S** | Show query |
| | **y** | Copy query to clipboard |
| | **s** | `EXPLAIN SYNTAX` |
| | **e** | `EXPLAIN PLAN` |
| | **E** | `EXPLAIN PIPELINE` |
Expand Down
34 changes: 34 additions & 0 deletions src/view/queries_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ pub struct QueriesView {
filter: Arc<Mutex<String>>,
// Number of queries to render
limit: Arc<Mutex<u64>>,
// Keep clipboard alive so X11 clipboard manager can persist the data
clipboard: Option<arboard::Clipboard>,

#[allow(unused)]
bg_runner: BackgroundRunner,
Expand Down Expand Up @@ -555,6 +557,36 @@ impl QueriesView {
Ok(Some(EventResult::consumed()))
}

fn action_copy_query(&mut self) -> Result<Option<EventResult>> {
let selected_query = self.get_selected_query()?;
let query = selected_query.original_query.clone();

match arboard::Clipboard::new() {
Ok(mut clipboard) => {
if let Err(e) = clipboard.set_text(query) {
return Ok(Some(EventResult::Consumed(Some(Callback::from_fn_once(
move |siv| {
siv.add_layer(Dialog::info(format!(
"Failed to copy to clipboard: {}",
e
)));
},
)))));
}
self.clipboard = Some(clipboard);
}
Err(e) => {
return Ok(Some(EventResult::Consumed(Some(Callback::from_fn_once(
move |siv| {
siv.add_layer(Dialog::info(format!("Failed to access clipboard: {}", e)));
},
)))));
}
}

Ok(Some(EventResult::consumed()))
}

fn action_explain_syntax(&mut self) -> Result<Option<EventResult>> {
let selected_query = self.get_selected_query()?;
let query = selected_query.original_query.clone();
Expand Down Expand Up @@ -981,6 +1013,7 @@ impl QueriesView {
is_system_processes,
filter,
limit,
clipboard: None,
bg_runner,
};

Expand Down Expand Up @@ -1024,6 +1057,7 @@ impl QueriesView {
add_action!(context, &mut event_view, "Query events flamegraph", action_show_flamegraph(true, Some(TraceType::ProfileEvents)));
add_action!(context, &mut event_view, "Edit query and execute", Event::AltChar('E'), action_edit_query_and_execute);
add_action!(context, &mut event_view, "Show query", 'S', action_show_query);
add_action!(context, &mut event_view, "Copy query to clipboard", 'y', action_copy_query);
add_action!(context, &mut event_view, "EXPLAIN SYNTAX", 's', action_explain_syntax);
add_action!(context, &mut event_view, "EXPLAIN PLAN", 'e', action_explain_plan);
add_action!(context, &mut event_view, "EXPLAIN PIPELINE", 'E', action_explain_pipeline);
Expand Down
Loading