diff options
-rw-r--r-- | zellij-tile/src/ui_components/nested_list.rs | 38 | ||||
-rw-r--r-- | zellij-tile/src/ui_components/ribbon.rs | 57 | ||||
-rw-r--r-- | zellij-tile/src/ui_components/table.rs | 23 | ||||
-rw-r--r-- | zellij-tile/src/ui_components/text.rs | 23 |
4 files changed, 141 insertions, 0 deletions
diff --git a/zellij-tile/src/ui_components/nested_list.rs b/zellij-tile/src/ui_components/nested_list.rs index 15bb890c5..442c27fb6 100644 --- a/zellij-tile/src/ui_components/nested_list.rs +++ b/zellij-tile/src/ui_components/nested_list.rs @@ -1,4 +1,5 @@ use super::Text; +use std::borrow::Borrow; use std::ops::RangeBounds; #[derive(Debug, Default, Clone)] @@ -71,3 +72,40 @@ pub fn print_nested_list_with_coordinates( x, y, width, height, items ) } + +pub fn serialize_nested_list<I>(items: I) -> String +where + I: IntoIterator, + I::Item: Borrow<NestedListItem>, +{ + let items = items + .into_iter() + .map(|i| i.borrow().serialize()) + .collect::<Vec<_>>() + .join(";"); + format!("\u{1b}Pznested_list;{}\u{1b}\\", items) +} + +pub fn serialize_nested_list_with_coordinates<I>( + items: I, + x: usize, + y: usize, + width: Option<usize>, + height: Option<usize>, +) -> String +where + I: IntoIterator, + I::Item: Borrow<NestedListItem>, +{ + let width = width.map(|w| w.to_string()).unwrap_or_default(); + let height = height.map(|h| h.to_string()).unwrap_or_default(); + let items = items + .into_iter() + .map(|i| i.borrow().serialize()) + .collect::<Vec<_>>() + .join(";"); + format!( + "\u{1b}Pznested_list;{}/{}/{}/{};{}\u{1b}\\", + x, y, width, height, items + ) +} diff --git a/zellij-tile/src/ui_components/ribbon.rs b/zellij-tile/src/ui_components/ribbon.rs index c0c1880e4..f1922fa74 100644 --- a/zellij-tile/src/ui_components/ribbon.rs +++ b/zellij-tile/src/ui_components/ribbon.rs @@ -1,4 +1,5 @@ use super::Text; +use std::borrow::Borrow; pub fn print_ribbon(text: Text) { print!("\u{1b}Pzribbon;{}\u{1b}\\", text.serialize()); @@ -22,3 +23,59 @@ pub fn print_ribbon_with_coordinates( text.serialize() ); } + +pub fn serialize_ribbon(text: &Text) -> String { + format!("\u{1b}Pzribbon;{}\u{1b}\\", text.serialize()) +} + +pub fn serialize_ribbon_with_coordinates( + text: &Text, + x: usize, + y: usize, + width: Option<usize>, + height: Option<usize>, +) -> String { + let width = width.map(|w| w.to_string()).unwrap_or_default(); + let height = height.map(|h| h.to_string()).unwrap_or_default(); + + format!( + "\u{1b}Pzribbon;{}/{}/{}/{};{}\u{1b}\\", + x, + y, + width, + height, + text.serialize() + ) +} + +pub fn serialize_ribbon_line<I>(ribbons: I) -> String +where + I: IntoIterator, + I::Item: Borrow<Text>, +{ + ribbons + .into_iter() + .map(|r| serialize_ribbon(r.borrow())) + .collect() +} + +pub fn serialize_ribbon_line_with_coordinates<I>( + ribbons: I, + x: usize, + y: usize, + width: Option<usize>, + height: Option<usize>, +) -> String +where + I: IntoIterator, + I::Item: Borrow<Text>, +{ + let mut ribbons = ribbons.into_iter(); + let Some(first) = ribbons.next() else { + return String::new(); + }; + + let mut result = serialize_ribbon_with_coordinates(first.borrow(), x, y, width, height); + result.push_str(&serialize_ribbon_line(ribbons)); + result +} diff --git a/zellij-tile/src/ui_components/table.rs b/zellij-tile/src/ui_components/table.rs index df1b833bf..5ef07d7a3 100644 --- a/zellij-tile/src/ui_components/table.rs +++ b/zellij-tile/src/ui_components/table.rs @@ -59,3 +59,26 @@ pub fn print_table_with_coordinates( table.serialize() ) } + +pub fn serialize_table(table: &Table) -> String { + format!("\u{1b}Pztable;{}", table.serialize()) +} + +pub fn serialize_table_with_coordinates( + table: &Table, + x: usize, + y: usize, + width: Option<usize>, + height: Option<usize>, +) -> String { + let width = width.map(|w| w.to_string()).unwrap_or_default(); + let height = height.map(|h| h.to_string()).unwrap_or_default(); + format!( + "\u{1b}Pztable;{}/{}/{}/{};{}\u{1b}\\", + x, + y, + width, + height, + table.serialize() + ) +} diff --git a/zellij-tile/src/ui_components/text.rs b/zellij-tile/src/ui_components/text.rs index e9ae25aaa..da934dd43 100644 --- a/zellij-tile/src/ui_components/text.rs +++ b/zellij-tile/src/ui_components/text.rs @@ -105,3 +105,26 @@ pub fn print_text_with_coordinates( text.serialize() ) } + +pub fn serialize_text(text: &Text) -> String { + format!("\u{1b}Pztext;{}\u{1b}\\", text.serialize()) +} + +pub fn serialize_text_with_coordinates( + text: &Text, + x: usize, + y: usize, + width: Option<usize>, + height: Option<usize>, +) -> String { + let width = width.map(|w| w.to_string()).unwrap_or_default(); + let height = height.map(|h| h.to_string()).unwrap_or_default(); + format!( + "\u{1b}Pztext;{}/{}/{}/{};{}\u{1b}\\", + x, + y, + width, + height, + text.serialize() + ) +} |