From 34abfcdc8e148c047ebb2e06539036e514df7046 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Thu, 20 Nov 2025 17:44:49 +0800 Subject: add: utility functions for table and pager - Add insert_item method to SimpleTable for flexible row insertion - Add show_in_pager function for system pager support --- src/utils/display.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/utils/display.rs') diff --git a/src/utils/display.rs b/src/utils/display.rs index 09efe97..cab7477 100644 --- a/src/utils/display.rs +++ b/src/utils/display.rs @@ -55,6 +55,30 @@ impl SimpleTable { self.line.push(processed_items); } + /// Insert a new row of items at the specified index + pub fn insert_item(&mut self, index: usize, items: Vec>) { + let items: Vec = items.into_iter().map(|v| v.into()).collect(); + + let mut processed_items = Vec::with_capacity(self.items.len()); + + for i in 0..self.items.len() { + if i < items.len() { + processed_items.push(items[i].clone()); + } else { + processed_items.push(String::new()); + } + } + + for (i, d) in processed_items.iter().enumerate() { + let d_len = display_width(d); + if d_len > self.length[i] { + self.length[i] = d_len; + } + } + + self.line.insert(index, processed_items); + } + /// Get the current maximum column widths fn get_column_widths(&self) -> &[usize] { &self.length -- cgit