From fb50df52de380dfb4fd4bf19c6c0699b2994b33a Mon Sep 17 00:00:00 2001 From: Builditluc <37375448+Builditluc@users.noreply.github.com> Date: Sun, 26 May 2024 12:11:58 +0200 Subject: [PATCH] implement statusbar - remove old static bar - add search status bar - add page status bar --- src/app.rs | 9 ++------- src/components/mod.rs | 1 - src/components/page.rs | 16 +++++++++++++++- src/components/search.rs | 2 +- src/components/status.rs | 26 -------------------------- src/page_loader.rs | 2 +- 6 files changed, 19 insertions(+), 37 deletions(-) delete mode 100644 src/components/status.rs diff --git a/src/app.rs b/src/app.rs index d30c3e3b..a2114c69 100644 --- a/src/app.rs +++ b/src/app.rs @@ -14,7 +14,6 @@ use crate::{ page_viewer::PageViewer, search::SearchComponent, search_bar::{SearchBarComponent, SEARCH_BAR_HEIGTH}, - status::{StatusComponent, STATUS_HEIGHT}, Component, }, has_modifier, key_event, @@ -31,7 +30,6 @@ pub struct AppComponent { search: SearchComponent, page: PageViewer, logger: LoggerComponent, - status: StatusComponent, search_bar: SearchBarComponent, help: HelpComponent, @@ -212,20 +210,17 @@ impl Component for AppComponent { } fn render(&mut self, f: &mut Frame<'_>, area: Rect) { - let (search_bar_area, area, status_area) = { + let (search_bar_area, area) = { let chunks = Layout::default() .direction(Direction::Vertical) .constraints([ Constraint::Min(SEARCH_BAR_HEIGTH), Constraint::Percentage(100), - Constraint::Min(STATUS_HEIGHT), ]) .split(area); - (chunks[0], chunks[1], chunks[2]) + (chunks[0], chunks[1]) }; - self.status.render(f, status_area); - if self.is_help { self.help.render(f, centered_rect(area, 30, 50)); return; diff --git a/src/components/mod.rs b/src/components/mod.rs index 0d29ce95..09d36dc3 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -17,7 +17,6 @@ pub mod page; pub mod page_viewer; pub mod search; pub mod search_bar; -pub mod status; #[macro_export] macro_rules! key_event { diff --git a/src/components/page.rs b/src/components/page.rs index ea2189ce..bb744329 100644 --- a/src/components/page.rs +++ b/src/components/page.rs @@ -478,7 +478,21 @@ impl Component for PageComponent { } fn render(&mut self, f: &mut Frame, area: Rect) { - let area = padded_rect(area, 1, 1); + let (area, status_area) = { + let splits = Layout::default() + .direction(Direction::Vertical) + .constraints([Constraint::Percentage(100), Constraint::Min(1)]) + .split(padded_rect(area, 1, 1)); + (splits[0], splits[1]) + }; + + let status_msg = format!( + " wiki-tui | Page '{}' | Language '{}' | '{}' other languages available", + self.page.title, + self.page.language.name(), + self.page.available_languages().unwrap_or_default() + ); + f.render_widget(Paragraph::new(status_msg), status_area); let area = { let splits = Layout::default() diff --git a/src/components/search.rs b/src/components/search.rs index 2630b893..a4952bc6 100644 --- a/src/components/search.rs +++ b/src/components/search.rs @@ -347,7 +347,7 @@ impl Component for SearchComponent { if let Some(ref search_info) = self.search_info { let info = Paragraph::new(format!( - "Results: {} | Language: {} | [c]ontinue", + " wiki-tui | Results: '{}' | Language: '{}' | [c]ontinue", search_info.total_hits.unwrap_or_default(), search_info.language.name() )); diff --git a/src/components/status.rs b/src/components/status.rs deleted file mode 100644 index bb2a45ab..00000000 --- a/src/components/status.rs +++ /dev/null @@ -1,26 +0,0 @@ -use ratatui::{ - prelude::{Constraint, Direction, Layout, Rect}, - widgets::Paragraph, -}; - -use crate::terminal::Frame; - -use super::Component; - -const HELP_MSG: &str = "DEVELOPMENT VERSION - Press [?] for help"; -const HELP_MSG_LEN: u16 = HELP_MSG.len() as u16; - -pub const STATUS_HEIGHT: u16 = 1; - -#[derive(Default)] -pub struct StatusComponent; -impl Component for StatusComponent { - fn render(&mut self, f: &mut Frame<'_>, area: Rect) { - let chunks = Layout::default() - .direction(Direction::Horizontal) - .constraints([Constraint::Percentage(100), Constraint::Min(HELP_MSG_LEN)]) - .split(area); - - f.render_widget(Paragraph::new(HELP_MSG), chunks[1]); - } -} diff --git a/src/page_loader.rs b/src/page_loader.rs index 5c24ad22..0ba491a8 100644 --- a/src/page_loader.rs +++ b/src/page_loader.rs @@ -28,7 +28,7 @@ impl PageLoader { pub fn load_page(&self, title: String) { let page_request = Page::builder() .page(title) - .properties(vec![Property::Text, Property::Sections]) + .properties(vec![Property::Text, Property::Sections, Property::LangLinks]) .endpoint(self.endpoint.clone()) .language(self.language.clone());