Skip to content

Commit

Permalink
implement statusbar
Browse files Browse the repository at this point in the history
- remove old static bar
- add search status bar
- add page status bar
  • Loading branch information
Builditluc committed May 26, 2024
1 parent ec8e53d commit fb50df5
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 37 deletions.
9 changes: 2 additions & 7 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -31,7 +30,6 @@ pub struct AppComponent {
search: SearchComponent,
page: PageViewer,
logger: LoggerComponent,
status: StatusComponent,
search_bar: SearchBarComponent,
help: HelpComponent,

Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 15 additions & 1 deletion src/components/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/components/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
));
Expand Down
26 changes: 0 additions & 26 deletions src/components/status.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/page_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down

0 comments on commit fb50df5

Please sign in to comment.