diff --git a/tui/src/floating_text.rs b/tui/src/floating_text.rs index cde1e519..2b8d07bd 100644 --- a/tui/src/floating_text.rs +++ b/tui/src/floating_text.rs @@ -37,7 +37,7 @@ pub struct FloatingText { max_line_width: usize, v_scroll: usize, h_scroll: usize, - mode: FloatingTextMode, + mode_title: &'static str, } macro_rules! style { @@ -139,10 +139,9 @@ impl FloatingText { .collect::>(); let max_line_width = max_width!(src); - Self { src, - mode, + mode_title: Self::get_mode_title(mode), max_line_width, v_scroll: 0, h_scroll: 0, @@ -172,13 +171,20 @@ impl FloatingText { Some(Self { src, - mode, + mode_title: Self::get_mode_title(mode), max_line_width, h_scroll: 0, v_scroll: 0, }) } + fn get_mode_title(mode: FloatingTextMode) -> &'static str { + match mode { + FloatingTextMode::Preview => "Command Preview", + FloatingTextMode::Description => "Command Description", + } + } + fn scroll_down(&mut self) { if self.v_scroll + 1 < self.src.len() { self.v_scroll += 1; @@ -207,14 +213,9 @@ impl FloatingText { impl FloatContent for FloatingText { fn draw(&mut self, frame: &mut Frame, area: Rect) { // Define the Block with a border and background color - let block_title = match self.mode { - FloatingTextMode::Preview => "Command Preview", - FloatingTextMode::Description => "Command Description", - }; - let block = Block::default() .borders(Borders::ALL) - .title(block_title) + .title(self.mode_title) .title_alignment(ratatui::layout::Alignment::Center) .title_style(Style::default().reversed()) .style(Style::default()); @@ -292,7 +293,7 @@ impl FloatContent for FloatingText { fn get_shortcut_list(&self) -> ShortcutList { ShortcutList { - scope_name: "Floating text", + scope_name: self.mode_title, hints: vec![ Shortcut::new(vec!["j", "Down"], "Scroll down"), Shortcut::new(vec!["k", "Up"], "Scroll up"), diff --git a/tui/src/hint.rs b/tui/src/hint.rs index cfdce25f..651d144c 100644 --- a/tui/src/hint.rs +++ b/tui/src/hint.rs @@ -35,7 +35,7 @@ pub fn span_vec_len(span_vec: &[Span]) -> usize { impl ShortcutList { pub fn draw(&self, frame: &mut Frame, area: Rect) { let block = Block::default() - .title(self.scope_name) + .title(format!(" {} ", self.scope_name)) .borders(Borders::all()); let inner_area = area.inner(Margin::new(1, 1)); let shortcut_spans: Vec> = self.hints.iter().map(|h| h.to_spans()).collect(); @@ -145,7 +145,7 @@ pub fn draw_shortcuts(state: &AppState, frame: &mut Frame, area: Rect) { hints.push(Shortcut::new(vec!["Tab"], "Next tab")); hints.push(Shortcut::new(vec!["Shift-Tab"], "Previous tab")); ShortcutList { - scope_name: "Item list", + scope_name: "Command list", hints, } }