From 18709acde974736492972b2892f69cea5f55716f Mon Sep 17 00:00:00 2001 From: Thomas Linford Date: Wed, 2 Feb 2022 15:22:34 +0100 Subject: feat(copy): allow osc52 copy destination configuration (#1022) add copy_cliboard option to allow configuring copy destination to primary selection instead of default clipboard --- default-plugins/status-bar/src/main.rs | 96 ++++++++++----------------- default-plugins/status-bar/src/second_line.rs | 11 ++- 2 files changed, 43 insertions(+), 64 deletions(-) (limited to 'default-plugins/status-bar') diff --git a/default-plugins/status-bar/src/main.rs b/default-plugins/status-bar/src/main.rs index 1a26ca14f..27dc3262d 100644 --- a/default-plugins/status-bar/src/main.rs +++ b/default-plugins/status-bar/src/main.rs @@ -24,7 +24,7 @@ struct State { tabs: Vec, tip_name: String, mode_info: ModeInfo, - diplay_text_copied_hint: bool, + text_copy_destination: Option, display_system_clipboard_failure: bool, } @@ -156,14 +156,14 @@ impl ZellijPlugin for State { Event::TabUpdate(tabs) => { self.tabs = tabs; } - Event::CopyToClipboard => { - self.diplay_text_copied_hint = true; + Event::CopyToClipboard(copy_destination) => { + self.text_copy_destination = Some(copy_destination); } Event::SystemClipboardFailure => { self.display_system_clipboard_failure = true; } Event::InputReceived => { - self.diplay_text_copied_hint = false; + self.text_copy_destination = None; self.display_system_clipboard_failure = false; } _ => {} @@ -186,64 +186,7 @@ impl ZellijPlugin for State { ); let first_line = format!("{}{}", superkey, ctrl_keys); - - let mut second_line = LinePart::default(); - for t in &mut self.tabs { - if t.active { - match self.mode_info.mode { - InputMode::Normal => { - if t.is_fullscreen_active { - second_line = if self.diplay_text_copied_hint { - text_copied_hint(&self.mode_info.palette) - } else if self.display_system_clipboard_failure { - system_clipboard_error(&self.mode_info.palette) - } else { - fullscreen_panes_to_hide(&self.mode_info.palette, t.panes_to_hide) - } - } else { - second_line = if self.diplay_text_copied_hint { - text_copied_hint(&self.mode_info.palette) - } else if self.display_system_clipboard_failure { - system_clipboard_error(&self.mode_info.palette) - } else { - keybinds(&self.mode_info, &self.tip_name, cols) - } - } - } - InputMode::Locked => { - if t.is_fullscreen_active { - second_line = if self.diplay_text_copied_hint { - text_copied_hint(&self.mode_info.palette) - } else if self.display_system_clipboard_failure { - system_clipboard_error(&self.mode_info.palette) - } else { - locked_fullscreen_panes_to_hide( - &self.mode_info.palette, - t.panes_to_hide, - ) - } - } else { - second_line = if self.diplay_text_copied_hint { - text_copied_hint(&self.mode_info.palette) - } else if self.display_system_clipboard_failure { - system_clipboard_error(&self.mode_info.palette) - } else { - keybinds(&self.mode_info, &self.tip_name, cols) - } - } - } - _ => { - second_line = if self.diplay_text_copied_hint { - text_copied_hint(&self.mode_info.palette) - } else if self.display_system_clipboard_failure { - system_clipboard_error(&self.mode_info.palette) - } else { - keybinds(&self.mode_info, &self.tip_name, cols) - } - } - } - } - } + let second_line = self.second_line(cols); // [48;5;238m is gray background, [0K is so that it fills the rest of the line // [m is background reset, [0K is so that it clears the rest of the line @@ -258,3 +201,32 @@ impl ZellijPlugin for State { println!("\u{1b}[m{}\u{1b}[0K", second_line); } } + +impl State { + fn second_line(&self, cols: usize) -> LinePart { + let active_tab = self.tabs.iter().find(|t| t.active); + + if let Some(copy_destination) = self.text_copy_destination { + text_copied_hint(&self.mode_info.palette, copy_destination) + } else if self.display_system_clipboard_failure { + system_clipboard_error(&self.mode_info.palette) + } else if let Some(active_tab) = active_tab { + if active_tab.is_fullscreen_active { + match self.mode_info.mode { + InputMode::Normal => { + fullscreen_panes_to_hide(&self.mode_info.palette, active_tab.panes_to_hide) + } + InputMode::Locked => locked_fullscreen_panes_to_hide( + &self.mode_info.palette, + active_tab.panes_to_hide, + ), + _ => keybinds(&self.mode_info, &self.tip_name, cols), + } + } else { + keybinds(&self.mode_info, &self.tip_name, cols) + } + } else { + LinePart::default() + } + } +} diff --git a/default-plugins/status-bar/src/second_line.rs b/default-plugins/status-bar/src/second_line.rs index 32a444255..13e847b99 100644 --- a/default-plugins/status-bar/src/second_line.rs +++ b/default-plugins/status-bar/src/second_line.rs @@ -229,12 +229,19 @@ pub fn keybinds(help: &ModeInfo, tip_name: &str, max_width: usize) -> LinePart { best_effort_shortcut_list(help, tip_body.short, max_width) } -pub fn text_copied_hint(palette: &Palette) -> LinePart { - let hint = " Text copied to clipboard"; +pub fn text_copied_hint(palette: &Palette, copy_destination: CopyDestination) -> LinePart { let green_color = match palette.green { PaletteColor::Rgb((r, g, b)) => RGB(r, g, b), PaletteColor::EightBit(color) => Fixed(color), }; + let hint = match copy_destination { + CopyDestination::Command => "Text piped to external command", + #[cfg(not(target_os = "macos"))] + CopyDestination::Primary => "Text copied to primary selection", + #[cfg(target_os = "macos")] // primary selection does not exist on macos + CopyDestination::Primary => "Text copied to clipboard", + CopyDestination::System => "Text copied to clipboard", + }; LinePart { part: Style::new().fg(green_color).bold().paint(hint).to_string(), len: hint.len(), -- cgit v1.2.3