Skip to content

Commit

Permalink
feat ✨: select item info
Browse files Browse the repository at this point in the history
  • Loading branch information
BQXBQX committed Oct 3, 2024
1 parent f4e01ae commit 7ee9a2f
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions cli/src/utils/tui/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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 {
Expand All @@ -94,19 +105,15 @@ 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()
.block(block)
.render(inner[1], buf);

self.render_list(outer[0], buf);

self.render_selected_item(inner[0], buf);
}
}

Expand Down

0 comments on commit 7ee9a2f

Please sign in to comment.