summaryrefslogtreecommitdiffstats
path: root/zellij-tile/src/ui_components/nested_list.rs
diff options
context:
space:
mode:
Diffstat (limited to 'zellij-tile/src/ui_components/nested_list.rs')
-rw-r--r--zellij-tile/src/ui_components/nested_list.rs38
1 files changed, 38 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
+ )
+}