Add 'copy to clipboard' function for view page
This commit is contained in:
parent
605d5f5792
commit
4f57c01693
5 changed files with 430 additions and 3 deletions
38
src/app.rs
38
src/app.rs
|
|
@ -45,6 +45,7 @@ pub struct App {
|
|||
pub log_view_content: Vec<String>,
|
||||
pub log_view_scroll: usize,
|
||||
pub log_view_selected: usize,
|
||||
pub clipboard: Option<arboard::Clipboard>,
|
||||
pub status_message: Option<(String, std::time::Instant)>,
|
||||
}
|
||||
|
||||
|
|
@ -71,6 +72,7 @@ impl App {
|
|||
log_view_content: Vec::new(),
|
||||
log_view_scroll: 0,
|
||||
log_view_selected: 0,
|
||||
clipboard: arboard::Clipboard::new().ok(),
|
||||
status_message: None,
|
||||
})
|
||||
}
|
||||
|
|
@ -329,6 +331,9 @@ impl App {
|
|||
KeyCode::Char('x') => {
|
||||
self.delete_selected_frame()?;
|
||||
}
|
||||
KeyCode::Char('c') => {
|
||||
self.copy_log_to_clipboard()?;
|
||||
}
|
||||
KeyCode::PageDown => {
|
||||
self.log_view_selected = (self.log_view_selected + 10)
|
||||
.min(self.log_view_frames.len().saturating_sub(1));
|
||||
|
|
@ -461,6 +466,39 @@ impl App {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn copy_log_to_clipboard(&mut self) -> anyhow::Result<()> {
|
||||
if self.log_view_content.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Join all the formatted log content
|
||||
let text = self.log_view_content.join("\n");
|
||||
|
||||
// Copy to clipboard using the persistent clipboard instance
|
||||
if let Some(ref mut clipboard) = self.clipboard {
|
||||
if let Err(e) = clipboard.set_text(&text) {
|
||||
self.set_status_message(format!("Failed to copy: {}", e));
|
||||
}
|
||||
// Success - clipboard instance stays alive in App struct
|
||||
} else {
|
||||
// Try to create a new clipboard if we don't have one
|
||||
match arboard::Clipboard::new() {
|
||||
Ok(mut clipboard) => {
|
||||
if let Err(e) = clipboard.set_text(&text) {
|
||||
self.set_status_message(format!("Failed to copy: {}", e));
|
||||
}
|
||||
// Store it for future use
|
||||
self.clipboard = Some(clipboard);
|
||||
}
|
||||
Err(e) => {
|
||||
self.set_status_message(format!("Failed to access clipboard: {}", e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn move_selection(&mut self, delta: i32) {
|
||||
let items_len = match self.state.current_pane {
|
||||
0 => self.state.permanent_items.len(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue