aboutsummaryrefslogtreecommitdiffstats
path: root/default-plugins
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2025-02-20 17:14:43 +0100
committerGitHub <noreply@github.com>2025-02-20 17:14:43 +0100
commitf0680fdeb93dd6934cfd52e175428e0cde36fadd (patch)
tree1efb28202afe106acae03871216b8a21c06860ce /default-plugins
parentdocs(changelog): filepicker improvements (diff)
downloadsl0ppij-f0680fdeb93dd6934cfd52e175428e0cde36fadd.tar.gz
sl0ppij-f0680fdeb93dd6934cfd52e175428e0cde36fadd.tar.xz
sl0ppij-f0680fdeb93dd6934cfd52e175428e0cde36fadd.zip
fix(clipboard): clipboard message (#4009)
* fix clipboard message * fix clipboard message gitter * style(fmt): rustfmt
Diffstat (limited to 'default-plugins')
-rw-r--r--default-plugins/compact-bar/src/main.rs179
-rw-r--r--default-plugins/status-bar/src/main.rs2
-rw-r--r--default-plugins/status-bar/src/one_line_ui.rs2
-rw-r--r--default-plugins/status-bar/src/second_line.rs5
4 files changed, 134 insertions, 54 deletions
diff --git a/default-plugins/compact-bar/src/main.rs b/default-plugins/compact-bar/src/main.rs
index 567dc187..3775b12f 100644
--- a/default-plugins/compact-bar/src/main.rs
+++ b/default-plugins/compact-bar/src/main.rs
@@ -24,6 +24,8 @@ struct State {
active_tab_idx: usize,
mode_info: ModeInfo,
tab_line: Vec<LinePart>,
+ text_copy_destination: Option<CopyDestination>,
+ display_system_clipboard_failure: bool,
}
static ARROW_SEPARATOR: &str = "";
@@ -37,6 +39,9 @@ impl ZellijPlugin for State {
EventType::TabUpdate,
EventType::ModeUpdate,
EventType::Mouse,
+ EventType::CopyToClipboard,
+ EventType::InputReceived,
+ EventType::SystemClipboardFailure,
]);
}
@@ -77,6 +82,32 @@ impl ZellijPlugin for State {
},
_ => {},
},
+ Event::CopyToClipboard(copy_destination) => {
+ match self.text_copy_destination {
+ Some(text_copy_destination) => {
+ if text_copy_destination != copy_destination {
+ should_render = true;
+ }
+ },
+ None => {
+ should_render = true;
+ },
+ }
+ self.text_copy_destination = Some(copy_destination);
+ },
+ Event::SystemClipboardFailure => {
+ should_render = true;
+ self.display_system_clipboard_failure = true;
+ },
+ Event::InputReceived => {
+ if self.text_copy_destination.is_some()
+ || self.display_system_clipboard_failure == true
+ {
+ should_render = true;
+ }
+ self.text_copy_destination = None;
+ self.display_system_clipboard_failure = false;
+ },
_ => {
eprintln!("Got unrecognized event: {:?}", event);
},
@@ -85,60 +116,110 @@ impl ZellijPlugin for State {
}
fn render(&mut self, _rows: usize, cols: usize) {
- if self.tabs.is_empty() {
- return;
- }
- let mut all_tabs: Vec<LinePart> = vec![];
- let mut active_tab_index = 0;
- let mut active_swap_layout_name = None;
- let mut is_swap_layout_dirty = false;
- let mut is_alternate_tab = false;
- for t in &mut self.tabs {
- let mut tabname = t.name.clone();
- if t.active && self.mode_info.mode == InputMode::RenameTab {
- if tabname.is_empty() {
- tabname = String::from("Enter name...");
+ if let Some(copy_destination) = self.text_copy_destination {
+ let hint = text_copied_hint(copy_destination).part;
+
+ let background = self.mode_info.style.colors.text_unselected.background;
+ match background {
+ PaletteColor::Rgb((r, g, b)) => {
+ print!("{}\u{1b}[48;2;{};{};{}m\u{1b}[0K", hint, r, g, b);
+ },
+ PaletteColor::EightBit(color) => {
+ print!("{}\u{1b}[48;5;{}m\u{1b}[0K", hint, color);
+ },
+ }
+ } else if self.display_system_clipboard_failure {
+ let hint = system_clipboard_error().part;
+ let background = self.mode_info.style.colors.text_unselected.background;
+ match background {
+ PaletteColor::Rgb((r, g, b)) => {
+ print!("{}\u{1b}[48;2;{};{};{}m\u{1b}[0K", hint, r, g, b);
+ },
+ PaletteColor::EightBit(color) => {
+ print!("{}\u{1b}[48;5;{}m\u{1b}[0K", hint, color);
+ },
+ }
+ } else {
+ if self.tabs.is_empty() {
+ return;
+ }
+ let mut all_tabs: Vec<LinePart> = vec![];
+ let mut active_tab_index = 0;
+ let mut active_swap_layout_name = None;
+ let mut is_swap_layout_dirty = false;
+ let mut is_alternate_tab = false;
+ for t in &mut self.tabs {
+ let mut tabname = t.name.clone();
+ if t.active && self.mode_info.mode == InputMode::RenameTab {
+ if tabname.is_empty() {
+ tabname = String::from("Enter name...");
+ }
+ active_tab_index = t.position;
+ } else if t.active {
+ active_tab_index = t.position;
+ is_swap_layout_dirty = t.is_swap_layout_dirty;
+ active_swap_layout_name = t.active_swap_layout_name.clone();
}
- active_tab_index = t.position;
- } else if t.active {
- active_tab_index = t.position;
- is_swap_layout_dirty = t.is_swap_layout_dirty;
- active_swap_layout_name = t.active_swap_layout_name.clone();
+ let tab = tab_style(
+ tabname,
+ t,
+ is_alternate_tab,
+ self.mode_info.style.colors,
+ self.mode_info.capabilities,
+ );
+ is_alternate_tab = !is_alternate_tab;
+ all_tabs.push(tab);
}
- let tab = tab_style(
- tabname,
- t,
- is_alternate_tab,
+ self.tab_line = tab_line(
+ self.mode_info.session_name.as_deref(),
+ all_tabs,
+ active_tab_index,
+ cols.saturating_sub(1),
self.mode_info.style.colors,
self.mode_info.capabilities,
+ self.mode_info.style.hide_session_name,
+ self.mode_info.mode,
+ &active_swap_layout_name,
+ is_swap_layout_dirty,
);
- is_alternate_tab = !is_alternate_tab;
- all_tabs.push(tab);
- }
- self.tab_line = tab_line(
- self.mode_info.session_name.as_deref(),
- all_tabs,
- active_tab_index,
- cols.saturating_sub(1),
- self.mode_info.style.colors,
- self.mode_info.capabilities,
- self.mode_info.style.hide_session_name,
- self.mode_info.mode,
- &active_swap_layout_name,
- is_swap_layout_dirty,
- );
- let output = self
- .tab_line
- .iter()
- .fold(String::new(), |output, part| output + &part.part);
- let background = self.mode_info.style.colors.text_unselected.background;
- match background {
- PaletteColor::Rgb((r, g, b)) => {
- print!("{}\u{1b}[48;2;{};{};{}m\u{1b}[0K", output, r, g, b);
- },
- PaletteColor::EightBit(color) => {
- print!("{}\u{1b}[48;5;{}m\u{1b}[0K", output, color);
- },
+ let output = self
+ .tab_line
+ .iter()
+ .fold(String::new(), |output, part| output + &part.part);
+ let background = self.mode_info.style.colors.text_unselected.background;
+ match background {
+ PaletteColor::Rgb((r, g, b)) => {
+ print!("{}\u{1b}[48;2;{};{};{}m\u{1b}[0K", output, r, g, b);
+ },
+ PaletteColor::EightBit(color) => {
+ print!("{}\u{1b}[48;5;{}m\u{1b}[0K", output, color);
+ },
+ }
}
}
}
+
+pub fn text_copied_hint(copy_destination: CopyDestination) -> LinePart {
+ let hint = match copy_destination {
+ CopyDestination::Command => "Text piped to external command",
+ #[cfg(not(target_os = "macos"))]
+ CopyDestination::Primary => "Text copied to system primary selection",
+ #[cfg(target_os = "macos")] // primary selection does not exist on macos
+ CopyDestination::Primary => "Text copied to system clipboard",
+ CopyDestination::System => "Text copied to system clipboard",
+ };
+ LinePart {
+ part: serialize_text(&Text::new(&hint).color_range(2, ..).opaque()),
+ len: hint.len(),
+ tab_index: None,
+ }
+}
+
+pub fn system_clipboard_error() -> LinePart {
+ let hint = " Error using the system clipboard.";
+ LinePart {
+ part: serialize_text(&Text::new(&hint).color_range(2, ..).opaque()),
+ len: hint.len(),
+ tab_index: None,
+ }
+}
diff --git a/default-plugins/status-bar/src/main.rs b/default-plugins/status-bar/src/main.rs
index db2b7c6b..65b73819 100644
--- a/default-plugins/status-bar/src/main.rs
+++ b/default-plugins/status-bar/src/main.rs
@@ -329,7 +329,7 @@ impl State {
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.style.colors, copy_destination)
+ text_copied_hint(copy_destination)
} else if self.display_system_clipboard_failure {
system_clipboard_error(&self.mode_info.style.colors)
} else if let Some(active_tab) = active_tab {
diff --git a/default-plugins/status-bar/src/one_line_ui.rs b/default-plugins/status-bar/src/one_line_ui.rs
index b230a25b..4526e6f8 100644
--- a/default-plugins/status-bar/src/one_line_ui.rs
+++ b/default-plugins/status-bar/src/one_line_ui.rs
@@ -24,7 +24,7 @@ pub fn one_line_ui(
clipboard_failure: bool,
) -> LinePart {
if let Some(text_copied_to_clipboard_destination) = text_copied_to_clipboard_destination {
- return text_copied_hint(&help.style.colors, text_copied_to_clipboard_destination);
+ return text_copied_hint(text_copied_to_clipboard_destination);
}
if clipboard_failure {
return system_clipboard_error(&help.style.colors);
diff --git a/default-plugins/status-bar/src/second_line.rs b/default-plugins/status-bar/src/second_line.rs
index 0c13ad14..fbc02b51 100644
--- a/default-plugins/status-bar/src/second_line.rs
+++ b/default-plugins/status-bar/src/second_line.rs
@@ -348,8 +348,7 @@ 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: &Styling, copy_destination: CopyDestination) -> LinePart {
- let green_color = palette_match!(palette.text_unselected.emphasis_2);
+pub fn text_copied_hint(copy_destination: CopyDestination) -> LinePart {
let hint = match copy_destination {
CopyDestination::Command => "Text piped to external command",
#[cfg(not(target_os = "macos"))]
@@ -359,7 +358,7 @@ pub fn text_copied_hint(palette: &Styling, copy_destination: CopyDestination) ->
CopyDestination::System => "Text copied to system clipboard",
};
LinePart {
- part: Style::new().fg(green_color).bold().paint(hint).to_string(),
+ part: serialize_text(&Text::new(&hint).color_range(2, ..).opaque()),
len: hint.len(),
}
}