Refactored things a bit and added help text support

This commit is contained in:
2023-08-08 10:50:04 -06:00
parent ff6e392af1
commit 3f378fb25a
11 changed files with 307 additions and 257 deletions
+22 -16
View File
@@ -1,4 +1,3 @@
use log::debug;
use tui::backend::Backend;
use tui::layout::{Alignment, Constraint, Rect};
use tui::text::{Span, Spans, Text};
@@ -10,15 +9,12 @@ use tui::widgets::Tabs;
use tui::widgets::{Block, Borders, Wrap};
use tui::Frame;
use crate::app::models::{StatefulTable, TabState};
use crate::app::{App, Route};
use crate::logos::{
BAZARR_LOGO, LIDARR_LOGO, PROWLARR_LOGO, RADARR_LOGO, READARR_LOGO, SONARR_LOGO,
};
use crate::app::App;
use crate::models::{Route, StatefulTable, TabState};
use crate::ui::utils::{
centered_rect, horizontal_chunks_with_margin, layout_block_top_border, logo_block,
style_default_bold, style_failure, style_help, style_highlight, style_primary, style_secondary,
style_system_function, title_block, vertical_chunks_with_margin,
borderless_block, centered_rect, horizontal_chunks_with_margin, layout_block_top_border,
logo_block, style_default_bold, style_failure, style_help, style_highlight, style_primary,
style_secondary, style_system_function, title_block, vertical_chunks_with_margin,
};
mod radarr_ui;
@@ -65,6 +61,7 @@ pub fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
fn draw_header_row<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, area: Rect) {
let chunks =
horizontal_chunks_with_margin(vec![Constraint::Length(75), Constraint::Min(0)], area, 1);
let help_text = Text::from(app.server_tabs.get_active_tab_help());
let titles = app
.server_tabs
@@ -76,19 +73,17 @@ fn draw_header_row<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, area: Rect)
.block(logo_block())
.highlight_style(style_secondary())
.select(app.server_tabs.index);
let help = Paragraph::new(Text::from(
"<↑↓> scroll | <enter> select | <tab> change servarr | <?> help ",
))
.block(Block::default())
.style(style_help())
.alignment(Alignment::Right);
let help = Paragraph::new(help_text)
.block(borderless_block())
.style(style_help())
.alignment(Alignment::Right);
f.render_widget(tabs, area);
f.render_widget(help, chunks[1]);
}
fn draw_error<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, area: Rect) {
let block = Block::default()
let block = borderless_block()
.title("Error | <esc> to close")
.style(style_failure())
.borders(Borders::ALL);
@@ -169,7 +164,14 @@ fn draw_tabs<'a, B: Backend>(
) -> (Rect, Block<'a>) {
let chunks =
vertical_chunks_with_margin(vec![Constraint::Length(2), Constraint::Min(0)], area, 1);
let horizontal_chunks = horizontal_chunks_with_margin(
vec![Constraint::Percentage(10), Constraint::Min(0)],
area,
1,
);
let block = title_block(title);
let mut help_text = Text::from(tab_state.get_active_tab_help());
help_text.patch_style(style_help());
let titles = tab_state
.tabs
@@ -180,8 +182,12 @@ fn draw_tabs<'a, B: Backend>(
.block(block)
.highlight_style(style_secondary())
.select(tab_state.index);
let help = Paragraph::new(help_text)
.block(borderless_block())
.alignment(Alignment::Right);
f.render_widget(tabs, area);
f.render_widget(help, horizontal_chunks[1]);
(chunks[1], layout_block_top_border())
}
+39 -17
View File
@@ -10,14 +10,15 @@ use tui::widgets::{Block, Cell, Paragraph, Row, Wrap};
use tui::Frame;
use crate::app::radarr::{ActiveRadarrBlock, RadarrData};
use crate::app::{App, Route};
use crate::app::App;
use crate::logos::RADARR_LOGO;
use crate::network::radarr_network::{Credit, DiskSpace, DownloadRecord, Movie, MovieHistoryItem};
use crate::models::radarr_models::{Credit, DiskSpace, DownloadRecord, Movie, MovieHistoryItem};
use crate::models::Route;
use crate::ui::utils::{
borderless_block, horizontal_chunks, layout_block_bottom_border, layout_block_top_border,
layout_block_top_border_with_title, layout_block_with_title, line_gauge_with_label,
line_gauge_with_title, spans_info_default, spans_info_primary, spans_info_with_style, style_bold,
style_default, style_default_bold, style_failure, style_primary, style_success, style_warning,
borderless_block, horizontal_chunks, horizontal_chunks_with_margin, layout_block_bottom_border,
layout_block_top_border, layout_block_top_border_with_title, layout_block_with_title,
line_gauge_with_label, line_gauge_with_title, spans_info_default, spans_info_primary, style_bold,
style_default, style_failure, style_help, style_primary, style_success, style_warning,
title_block, title_style, vertical_chunks, vertical_chunks_with_margin,
};
use crate::ui::{
@@ -250,7 +251,11 @@ fn draw_collections<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, area: Rect)
fn draw_collection_details<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, content_area: Rect) {
let chunks = vertical_chunks_with_margin(
vec![Constraint::Length(10), Constraint::Min(0)],
vec![
Constraint::Percentage(20),
Constraint::Percentage(75),
Constraint::Percentage(5),
],
content_area,
1,
);
@@ -262,6 +267,8 @@ fn draw_collection_details<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, cont
.get(&collection_selection.quality_profile_id.as_u64().unwrap())
.unwrap()
.to_owned();
let mut help_text = Text::from("<↑↓> scroll table | <enter> show overview | <esc> close");
help_text.patch_style(style_help());
let collection_description = Text::from(vec![
spans_info_primary(
@@ -285,13 +292,14 @@ fn draw_collection_details<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, cont
let description_paragraph = Paragraph::new(collection_description)
.block(borderless_block())
.wrap(Wrap { trim: false });
let help_paragraph = Paragraph::new(help_text)
.block(borderless_block())
.alignment(Alignment::Center);
f.render_widget(
layout_block_with_title(title_style(&collection_selection.title)),
content_area,
);
f.render_widget(title_block(&collection_selection.title), content_area);
f.render_widget(description_paragraph, chunks[0]);
f.render_widget(help_paragraph, chunks[2]);
draw_table(
f,
@@ -400,6 +408,14 @@ fn draw_movie_info<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, area: Rect)
}
fn draw_movie_overview<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, content_area: Rect) {
let title_block = title_block("Overview");
f.render_widget(title_block, content_area);
let chunks = vertical_chunks_with_margin(
vec![Constraint::Percentage(95), Constraint::Percentage(5)],
content_area,
1,
);
let mut overview = Text::from(
app
.data
@@ -409,12 +425,18 @@ fn draw_movie_overview<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, content_
.overview,
);
overview.patch_style(style_default());
let mut help_text = Text::from("<esc> close");
help_text.patch_style(style_help());
let paragraph = Paragraph::new(overview)
.block(layout_block_with_title(title_style("Overview")))
.block(borderless_block())
.wrap(Wrap { trim: false });
let help_paragraph = Paragraph::new(help_text)
.block(borderless_block())
.alignment(Alignment::Center);
f.render_widget(paragraph, content_area);
f.render_widget(paragraph, chunks[0]);
f.render_widget(help_paragraph, chunks[1]);
}
fn draw_movie_details<B: Backend>(
@@ -678,7 +700,7 @@ fn draw_stats_context<B: Backend>(f: &mut Frame<'_, B>, app: &App, area: Rect) {
"Radarr Version: {}",
app.data.radarr_data.version
)))
.block(Block::default());
.block(borderless_block());
let uptime = Utc::now().sub(start_time.to_owned());
let days = uptime.num_days();
@@ -698,15 +720,15 @@ fn draw_stats_context<B: Backend>(f: &mut Frame<'_, B>, app: &App, area: Rect) {
seconds,
width = 2
)))
.block(Block::default());
.block(borderless_block());
let mut logo_text = Text::from(RADARR_LOGO);
logo_text.patch_style(Style::default().fg(Color::LightYellow));
let logo = Paragraph::new(logo_text)
.block(Block::default())
.block(borderless_block())
.alignment(Alignment::Center);
let storage =
Paragraph::new(Text::from("Storage:")).block(Block::default().style(style_bold()));
Paragraph::new(Text::from("Storage:")).block(borderless_block().style(style_bold()));
f.render_widget(logo, chunks[0]);
f.render_widget(version_paragraph, chunks[1]);