From 618779102bfd5903a4f957d262f8d7fe9deb4ccb Mon Sep 17 00:00:00 2001 From: Benjamyn Love Date: Tue, 11 Jun 2024 13:36:05 +1000 Subject: [PATCH] List testing --- src/app.rs | 2 ++ src/fsutil.rs | 13 +++++++------ src/ui.rs | 11 +++++++++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/app.rs b/src/app.rs index 3c93a43..ea4bbc1 100644 --- a/src/app.rs +++ b/src/app.rs @@ -25,6 +25,7 @@ pub struct App { pub current_state: CurrentState, pub menu_state: MenuState, pub config: Config, + pub state: ListState, } impl App { @@ -37,6 +38,7 @@ impl App { current_state: CurrentState::Lookup, menu_state: MenuState::Main, config: Config::from_file("test.ini".to_string()), + state: ListState::default(), } } } diff --git a/src/fsutil.rs b/src/fsutil.rs index e272f9b..f2cf425 100644 --- a/src/fsutil.rs +++ b/src/fsutil.rs @@ -50,14 +50,15 @@ impl DomainData { // println!("{}", output); } - pub fn list_lookups(config: &Config) -> Vec { - let mut items: Vec = vec![]; + pub fn list_lookups(config: &Config) -> Vec { + let mut items: Vec = vec![]; for item in fs::read_dir(format!("{}/lookups", config.data_dir)).unwrap() { let item_name = item.unwrap(); - items.push(ListItem::new(Line::from(Span::styled( - String::from(item_name.path().to_string_lossy().clone()), - Style::default(), - )))); + // items.push(ListItem::new(Line::from(Span::styled( + // String::from(item_name.path().to_string_lossy().clone()), + // Style::default(), + // )))); + items.push(String::from(item_name.path().to_string_lossy().clone())) } return items; diff --git a/src/ui.rs b/src/ui.rs index 699bf96..5a213f5 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -336,6 +336,17 @@ pub fn ui(f: &mut Frame, app: &mut App) { .repeat_highlight_symbol(true); // f.render_stateful_widget(items, chunks[1], &mut app.state); + // let t_list = StatefulList::with_items(item_list); + // f.render_stateful_widget(t_list, chunks[1], t_list.state); + let items = ["Item 1", "Item 2", "Item 3"]; + let list = List::new(items) + .block(Block::default().title("List").borders(Borders::ALL)) + .highlight_style(Style::new().add_modifier(Modifier::REVERSED)) + .highlight_symbol(">>") + .repeat_highlight_symbol(true); + + f.render_stateful_widget(list, chunks[1], &mut app.state); + let footer_block = Block::new().borders(Borders::ALL).style(Style::default()); let footer = Paragraph::new(Text::styled(