From 7ee9a2f4ae4c2b8ff7b23f07b1761a24ecd86d3e Mon Sep 17 00:00:00 2001 From: bqxbqx Date: Thu, 3 Oct 2024 11:29:14 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E2=9C=A8:=20select=20item=20info?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cli/src/utils/tui/tui.rs | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/cli/src/utils/tui/tui.rs b/cli/src/utils/tui/tui.rs index 216125c..5dc7223 100644 --- a/cli/src/utils/tui/tui.rs +++ b/cli/src/utils/tui/tui.rs @@ -4,7 +4,7 @@ use ratatui::{ layout::Rect, style::{palette::tailwind::SLATE, Color, Modifier, Style}, symbols::border, - widgets::{Block, List, ListItem, Paragraph, StatefulWidget, Widget}, + widgets::{Block, List, ListItem, Paragraph, StatefulWidget, Widget, Wrap}, }; use super::{ @@ -32,10 +32,6 @@ impl Tui { self.exit = true; } - fn select_none(&mut self) { - self.component_list.state.select(None); - } - fn select_next(&mut self) { self.component_list.state.select_next(); } @@ -83,6 +79,21 @@ impl Tui { StatefulWidget::render(list, area, buf, &mut self.component_list.state); } + + fn render_selected_item(&self, area: Rect, buf: &mut Buffer) { + let info = if let Some(select_index) = self.component_list.state.selected() { + self.component_list.components[select_index].info.clone() + } else { + "Nothing selected...".to_string() + }; + + let block = Block::bordered().title(" Info ").border_set(border::THICK); + + Paragraph::new(info) + .block(block) + .wrap(Wrap { trim: false }) + .render(area, buf); + } } impl Widget for &mut Tui { @@ -94,12 +105,6 @@ impl Widget for &mut Tui { .centered() .render(comment[1], buf); - let block = Block::bordered().title(" Info ").border_set(border::THICK); - Paragraph::new("") - .centered() - .block(block) - .render(inner[0], buf); - let block = Block::bordered().title(" State ").border_set(border::THICK); Paragraph::new("") .centered() @@ -107,6 +112,8 @@ impl Widget for &mut Tui { .render(inner[1], buf); self.render_list(outer[0], buf); + + self.render_selected_item(inner[0], buf); } }