Added error windows with scrolling text, and a colorized Radarr logo. Also added header row with header tabs
This commit is contained in:
+77
-10
@@ -1,12 +1,12 @@
|
||||
use tui::backend::Backend;
|
||||
use tui::layout::{Constraint, Rect};
|
||||
use tui::layout::{Alignment, Constraint, Rect};
|
||||
use tui::text::{Span, Spans, Text};
|
||||
use tui::widgets::Block;
|
||||
use tui::widgets::Clear;
|
||||
use tui::widgets::Paragraph;
|
||||
use tui::widgets::Row;
|
||||
use tui::widgets::Table;
|
||||
use tui::widgets::Tabs;
|
||||
use tui::widgets::{Block, Borders, Wrap};
|
||||
use tui::Frame;
|
||||
|
||||
use crate::app::models::{StatefulTable, TabState};
|
||||
@@ -15,7 +15,8 @@ use crate::logos::{
|
||||
BAZARR_LOGO, LIDARR_LOGO, PROWLARR_LOGO, RADARR_LOGO, READARR_LOGO, SONARR_LOGO,
|
||||
};
|
||||
use crate::ui::utils::{
|
||||
centered_rect, layout_block_top_border, style_default_bold, style_highlight, style_secondary,
|
||||
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,
|
||||
};
|
||||
|
||||
@@ -25,18 +26,83 @@ mod utils;
|
||||
static HIGHLIGHT_SYMBOL: &str = "=> ";
|
||||
|
||||
pub fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
|
||||
let main_chunks = vertical_chunks_with_margin(
|
||||
vec![Constraint::Length(16), Constraint::Length(0)],
|
||||
f.size(),
|
||||
1,
|
||||
);
|
||||
let main_chunks = if !app.error.is_empty() {
|
||||
let chunks = vertical_chunks_with_margin(
|
||||
vec![
|
||||
Constraint::Length(3),
|
||||
Constraint::Length(3),
|
||||
Constraint::Length(16),
|
||||
Constraint::Length(0),
|
||||
],
|
||||
f.size(),
|
||||
1,
|
||||
);
|
||||
|
||||
draw_context_row(f, app, main_chunks[0]);
|
||||
draw_error(f, app, chunks[1]);
|
||||
|
||||
vec![chunks[0], chunks[2], chunks[3]]
|
||||
} else {
|
||||
vertical_chunks_with_margin(
|
||||
vec![
|
||||
Constraint::Length(3),
|
||||
Constraint::Length(16),
|
||||
Constraint::Length(0),
|
||||
],
|
||||
f.size(),
|
||||
1,
|
||||
)
|
||||
};
|
||||
|
||||
draw_header_row(f, app, main_chunks[0]);
|
||||
draw_context_row(f, app, main_chunks[1]);
|
||||
match app.get_current_route() {
|
||||
Route::Radarr(_) => radarr_ui::draw_radarr_ui(f, app, main_chunks[1]),
|
||||
Route::Radarr(_) => radarr_ui::draw_radarr_ui(f, app, main_chunks[2]),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
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 titles = app
|
||||
.server_tabs
|
||||
.tabs
|
||||
.iter()
|
||||
.map(|tab| Spans::from(Span::styled(&tab.title, style_default_bold())))
|
||||
.collect();
|
||||
let tabs = Tabs::new(titles)
|
||||
.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);
|
||||
|
||||
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()
|
||||
.title("Error | <esc> to close")
|
||||
.style(style_failure())
|
||||
.borders(Borders::ALL);
|
||||
|
||||
let mut text = Text::from(app.error.clone());
|
||||
text.patch_style(style_failure());
|
||||
|
||||
let paragraph = Paragraph::new(text)
|
||||
.block(block)
|
||||
.wrap(Wrap { trim: true })
|
||||
.style(style_primary());
|
||||
|
||||
f.render_widget(paragraph, area);
|
||||
}
|
||||
|
||||
pub fn draw_popup_over<B: Backend>(
|
||||
f: &mut Frame<'_, B>,
|
||||
app: &mut App,
|
||||
@@ -86,6 +152,7 @@ pub fn draw_large_popup_over<B: Backend>(
|
||||
fn draw_context_row<B: Backend>(f: &mut Frame<'_, B>, app: &App, area: Rect) {
|
||||
match app.get_current_route() {
|
||||
Route::Radarr(_) => radarr_ui::draw_radarr_context_row(f, app, area),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-8
@@ -5,7 +5,7 @@ use chrono::{Duration, Utc};
|
||||
use log::debug;
|
||||
use tui::backend::Backend;
|
||||
use tui::layout::{Alignment, Constraint, Rect};
|
||||
use tui::style::Style;
|
||||
use tui::style::{Color, Style};
|
||||
use tui::text::Text;
|
||||
use tui::widgets::{Block, Cell, Paragraph, Row, Wrap};
|
||||
use tui::Frame;
|
||||
@@ -15,7 +15,7 @@ use crate::app::{App, Route};
|
||||
use crate::logos::RADARR_LOGO;
|
||||
use crate::network::radarr_network::{DiskSpace, DownloadRecord, Movie, MovieHistoryItem};
|
||||
use crate::ui::utils::{
|
||||
horizontal_chunks_with_margin, layout_block_top_border, line_gague_with_label,
|
||||
horizontal_chunks, horizontal_chunks_with_margin, layout_block_top_border, line_gague_with_label,
|
||||
line_gague_with_title, style_bold, style_failure, style_success, style_warning, title_block,
|
||||
vertical_chunks_with_margin,
|
||||
};
|
||||
@@ -38,11 +38,7 @@ pub(super) fn draw_radarr_ui<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, ar
|
||||
}
|
||||
|
||||
pub(super) fn draw_radarr_context_row<B: Backend>(f: &mut Frame<'_, B>, app: &App, area: Rect) {
|
||||
let chunks = horizontal_chunks_with_margin(
|
||||
vec![Constraint::Ratio(1, 2), Constraint::Ratio(1, 2)],
|
||||
area,
|
||||
1,
|
||||
);
|
||||
let chunks = horizontal_chunks(vec![Constraint::Ratio(1, 2), Constraint::Ratio(1, 2)], area);
|
||||
|
||||
draw_stats_context(f, app, chunks[0]);
|
||||
draw_downloads_context(f, app, chunks[1]);
|
||||
@@ -332,7 +328,9 @@ fn draw_stats_context<B: Backend>(f: &mut Frame<'_, B>, app: &App, area: Rect) {
|
||||
)))
|
||||
.block(Block::default());
|
||||
|
||||
let logo = Paragraph::new(Text::from(RADARR_LOGO))
|
||||
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())
|
||||
.alignment(Alignment::Center);
|
||||
let storage =
|
||||
|
||||
@@ -106,6 +106,10 @@ pub fn style_failure() -> Style {
|
||||
Style::default().fg(Color::Red)
|
||||
}
|
||||
|
||||
pub fn style_help() -> Style {
|
||||
Style::default().fg(Color::LightBlue)
|
||||
}
|
||||
|
||||
pub fn title_style(title: &str) -> Span<'_> {
|
||||
Span::styled(title, style_bold())
|
||||
}
|
||||
@@ -114,6 +118,17 @@ pub fn title_block(title: &str) -> Block<'_> {
|
||||
layout_block_with_title(title_style(title))
|
||||
}
|
||||
|
||||
pub fn logo_block<'a>() -> Block<'a> {
|
||||
Block::default().borders(Borders::ALL).title(Span::styled(
|
||||
"Managarr - A Servarr management TUI",
|
||||
Style::default()
|
||||
.fg(Color::Black)
|
||||
.bg(Color::LightGreen)
|
||||
.add_modifier(Modifier::BOLD)
|
||||
.add_modifier(Modifier::ITALIC),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect {
|
||||
let popup_layout = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
|
||||
Reference in New Issue
Block a user