diff options
| author | lukeflo | 2024-11-14 15:54:58 +0100 |
|---|---|---|
| committer | lukeflo | 2024-11-14 15:54:58 +0100 |
| commit | f251969044036ecfbc2cd4774c9ecb97b1992bb3 (patch) | |
| tree | a5d3fc06f4eeee62280dced32eca47d297577935 /src/tui | |
| parent | ca51eea300b84a6fa865c6f3e00823a8099bb9bc (diff) | |
| download | bibiman-f251969044036ecfbc2cd4774c9ecb97b1992bb3.tar.gz bibiman-f251969044036ecfbc2cd4774c9ecb97b1992bb3.zip | |
refined complicated code parts
Diffstat (limited to 'src/tui')
| -rw-r--r-- | src/tui/popup.rs | 49 | ||||
| -rw-r--r-- | src/tui/ui.rs | 29 |
2 files changed, 15 insertions, 63 deletions
diff --git a/src/tui/popup.rs b/src/tui/popup.rs index fe76956..9011a3b 100644 --- a/src/tui/popup.rs +++ b/src/tui/popup.rs @@ -30,7 +30,7 @@ pub enum PopupKind { Selection, } -#[derive(Debug)] +#[derive(Debug, Default)] pub struct PopupArea { pub is_popup: bool, pub popup_kind: Option<PopupKind>, @@ -40,19 +40,6 @@ pub struct PopupArea { pub popup_state: ListState, } -impl Default for PopupArea { - fn default() -> Self { - PopupArea { - is_popup: false, - popup_kind: None, - popup_message: String::new(), - popup_scroll_pos: 0, - popup_list: Vec::new(), - popup_state: ListState::default(), - } - } -} - impl PopupArea { pub fn popup_help<'a>() -> Text<'a> { let help = [ @@ -78,36 +65,11 @@ impl PopupArea { ("ENTER: ", "Filter by selected keyword"), ("Search", "sub"), ("↓,↑,←,→: ", "Move cursor"), + ("BACKSPACE: ", "Delete Character"), ("ENTER: ", "Confirm search"), ("ESC: ", "Abort search"), ]; - // let help_text: Vec<Line<'_>> = help - // .into_iter() - // .map(|(keys, help)| { - // if help == "first" { - // Line::from( - // Span::raw(keys) - // .bold() - // .fg(Color::Indexed(MAIN_BLUE_COLOR_INDEX)), - // ) - // } else if help == "sub" { - // Line::from( - // Span::raw(keys) - // .bold() - // .fg(Color::Indexed(MAIN_BLUE_COLOR_INDEX)), - // ) - // } else { - // Line::from(vec![ - // Span::raw(keys) - // .bold() - // .fg(Color::Indexed(MAIN_PURPLE_COLOR_INDEX)), - // Span::raw(help), - // ]) - // } - // }) - // .collect(); - let mut helptext: Vec<Line<'_>> = vec![]; for (keys, help) in help { @@ -134,13 +96,12 @@ impl PopupArea { } } - let text = Text::from(helptext); - text + Text::from(helptext) } - pub fn popup_message(&mut self, message: &str, object: String) { + pub fn popup_message(&mut self, message: String, object: String) { if object.is_empty() { - self.popup_message = message.into(); + self.popup_message = message; } else { self.popup_message = format!("{} \"{}\"", message, object); } diff --git a/src/tui/ui.rs b/src/tui/ui.rs index dd08291..fbfd40a 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -107,8 +107,8 @@ pub const fn color_list(list_item: i32, sel_item: i32, highlight: u8, max_diff: Color::Indexed(highlight) } else if (list_item - sel_item) > max_diff || (sel_item - list_item) > max_diff - || (-1 * (list_item - sel_item)) > max_diff - || (-1 * (sel_item - list_item)) > max_diff + || -(list_item - sel_item) > max_diff + || -(sel_item - list_item) > max_diff { Color::Indexed(highlight - max_diff as u8) } else if list_item < sel_item { @@ -152,7 +152,7 @@ pub fn render_ui(app: &mut App, frame: &mut Frame) { pub fn render_popup(app: &mut App, frame: &mut Frame) { if let Some(PopupKind::Help) = app.bibiman.popup_area.popup_kind { - let text: Text = Text::from(PopupArea::popup_help()); + let text: Text = PopupArea::popup_help(); // Calculate max scroll position depending on hight of terminal window let scroll_pos = if app.bibiman.popup_area.popup_scroll_pos @@ -175,7 +175,7 @@ pub fn render_popup(app: &mut App, frame: &mut Frame) { }; let popup = Popup::new(sized_par) - .title(" Keybindings ".bold().into_centered_line()) + .title(" Keybindings (j,k|↓,↑)".bold().into_centered_line()) .style(POPUP_HELP_BOX) .border_style(Style::new().fg(MAIN_BLUE)); @@ -204,18 +204,9 @@ pub fn render_footer(app: &mut App, frame: &mut Frame, rect: Rect) { CurrentArea::SearchArea => { let search_title = { match app.bibiman.former_area { - Some(FormerArea::EntryArea) => { - let search_title = " Search Entries ".to_string(); - search_title - } - Some(FormerArea::TagArea) => { - let search_title = " Search Keywords ".to_string(); - search_title - } - _ => { - let search_title = " Search ".to_string(); - search_title - } + Some(FormerArea::EntryArea) => " Search Entries ".to_string(), + Some(FormerArea::TagArea) => " Search Keywords ".to_string(), + _ => " Search ".to_string(), } }; @@ -520,7 +511,7 @@ pub fn render_entrytable(app: &mut App, frame: &mut Frame, rect: Rect) { .map(|(i, data)| { let item = data.ref_vec(); item.into_iter() - .map(|content| Cell::from(Text::from(format!("{content}")))) + .map(|content| Cell::from(Text::from(content.to_string()))) .collect::<Row>() .style( Style::new().fg(color_list( @@ -529,7 +520,7 @@ pub fn render_entrytable(app: &mut App, frame: &mut Frame, rect: Rect) { .entry_table .entry_table_state .selected() - .unwrap() as i32, + .unwrap_or(0) as i32, TEXT_HIGHLIGHT_COLOR_INDEX, 20, )), @@ -681,7 +672,7 @@ pub fn render_selected_item(app: &mut App, frame: &mut Frame, rect: Rect) { } else { let lines = vec![ Line::from(" "), - Line::from("No entry selected".bold().into_centered_line().red()), + "No entry selected".bold().into_centered_line().red(), ]; lines } |
