diff --git a/tui/src/floating_text.rs b/tui/src/floating_text.rs index 8ef9ad3a7..719bc2e0b 100644 --- a/tui/src/floating_text.rs +++ b/tui/src/floating_text.rs @@ -32,6 +32,7 @@ pub enum FloatingTextMode { pub struct FloatingText { pub src: Vec, + name: Option, max_line_width: usize, v_scroll: usize, h_scroll: usize, @@ -130,7 +131,7 @@ fn get_lines_owned(s: &str) -> Vec { } impl FloatingText { - pub fn new(text: String, mode: FloatingTextMode) -> Self { + pub fn new(text: String, name: Option, mode: FloatingTextMode) -> Self { let src = get_lines(&text) .into_iter() .map(|s| s.to_string()) @@ -139,6 +140,7 @@ impl FloatingText { let max_line_width = max_width!(src); Self { src, + name, mode_title: Self::get_mode_title(mode), max_line_width, v_scroll: 0, @@ -146,12 +148,13 @@ impl FloatingText { } } - pub fn from_command(command: &Command, mode: FloatingTextMode) -> Option { + pub fn from_command(command: &Command, name: Option, mode: FloatingTextMode) -> Option { let (max_line_width, src) = match command { Command::Raw(cmd) => { // just apply highlights directly (max_width!(get_lines(cmd)), Some(cmd.clone())) } + Command::LocalFile { file, .. } => { // have to read from tmp dir to get cmd src let raw = std::fs::read_to_string(file) @@ -169,6 +172,7 @@ impl FloatingText { Some(Self { src, + name, mode_title: Self::get_mode_title(mode), max_line_width, h_scroll: 0, @@ -211,10 +215,16 @@ impl FloatingText { impl FloatContent for FloatingText { fn top_title(&self) -> Option> { - let title_text = format!(" {} ", self.mode_title); + let mut title_text = format!(" {} ", self.mode_title); + + if let Some(ref name) = self.name { + title_text = format!("{}- {} ", title_text, name); + } + let title_line = Line::from(title_text) .centered() .style(Style::default().reversed()); + Some(title_line) } diff --git a/tui/src/state.rs b/tui/src/state.rs index ce7248685..23e68f82f 100644 --- a/tui/src/state.rs +++ b/tui/src/state.rs @@ -653,7 +653,7 @@ impl AppState { fn enable_preview(&mut self) { if let Some(node) = self.get_selected_node() { if let Some(preview) = - FloatingText::from_command(&node.command, FloatingTextMode::Preview) + FloatingText::from_command(&node.command, Some(node.name.clone()), FloatingTextMode::Preview) { self.spawn_float(preview, 80, 80); } @@ -662,7 +662,9 @@ impl AppState { fn enable_description(&mut self) { if let Some(command_description) = self.get_selected_description() { - let description = FloatingText::new(command_description, FloatingTextMode::Description); + let name = self.get_selected_node().map(|node| node.name.clone()); + + let description = FloatingText::new(command_description, name, FloatingTextMode::Description); self.spawn_float(description, 80, 80); } } @@ -728,7 +730,7 @@ impl AppState { fn toggle_task_list_guide(&mut self) { self.spawn_float( - FloatingText::new(ACTIONS_GUIDE.to_string(), FloatingTextMode::ActionsGuide), + FloatingText::new(ACTIONS_GUIDE.to_string(), None, FloatingTextMode::ActionsGuide), 80, 80, );