checkpoint
modified: src/file_system.rs modified: src/loading_screen.rs modified: src/main.rs modified: src/main_screen.rs modified: src/screen.rs new file: src/theme.rs modified: src/wait_screen.rs
This commit is contained in:
parent
e4061dde2d
commit
edfbbce03e
@ -1,11 +1,11 @@
|
||||
use crate::screen::AppScreen;
|
||||
use crate::{screen::AppScreen, theme::Theme};
|
||||
|
||||
pub struct FileSystem {}
|
||||
|
||||
impl AppScreen for FileSystem {
|
||||
fn handle_key_event(&mut self, key_event: crossterm::event::KeyEvent) {}
|
||||
|
||||
fn render(&self, frame: &mut ratatui::Frame) {
|
||||
fn render(&self, frame: &mut ratatui::Frame, theme: &Theme) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ use ratatui::{
|
||||
Frame,
|
||||
};
|
||||
|
||||
use crate::{dlp::DownloadProgress, screen::AppScreen};
|
||||
use crate::{dlp::DownloadProgress, screen::AppScreen, theme::Theme};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct LoadingScreen {
|
||||
@ -17,7 +17,7 @@ pub struct LoadingScreen {
|
||||
impl AppScreen for LoadingScreen {
|
||||
fn handle_key_event(&mut self, key_event: crossterm::event::KeyEvent) {}
|
||||
|
||||
fn render(&self, frame: &mut ratatui::Frame) {
|
||||
fn render(&self, frame: &mut ratatui::Frame, theme: &Theme) {
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([
|
||||
|
@ -1,5 +1,6 @@
|
||||
use std::{collections::HashMap, error::Error, io};
|
||||
|
||||
use crate::theme::Theme;
|
||||
use color_eyre::Result;
|
||||
use crossterm::{
|
||||
event::{
|
||||
@ -31,6 +32,7 @@ mod loading_screen;
|
||||
mod main_screen;
|
||||
mod screen;
|
||||
mod sync;
|
||||
mod theme;
|
||||
mod util;
|
||||
mod wait_screen;
|
||||
|
||||
@ -48,6 +50,7 @@ pub struct App {
|
||||
receiver: Receiver<AppEvent>,
|
||||
sender: UnboundedSender<AppEvent>,
|
||||
token: CancellationToken,
|
||||
theme: Theme,
|
||||
}
|
||||
|
||||
impl Default for App {
|
||||
@ -71,6 +74,7 @@ impl Default for App {
|
||||
token,
|
||||
state: AppState::IPodWait,
|
||||
screens,
|
||||
theme: Theme::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -86,7 +90,10 @@ impl App {
|
||||
}
|
||||
|
||||
fn draw(&mut self, frame: &mut Frame) {
|
||||
self.screens.get(&self.state).unwrap().render(frame);
|
||||
self.screens
|
||||
.get(&self.state)
|
||||
.unwrap()
|
||||
.render(frame, &self.theme);
|
||||
}
|
||||
|
||||
async fn handle_events(&mut self, reader: &mut EventStream) {
|
||||
|
@ -1,5 +1,4 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use color_eyre::owo_colors::OwoColorize;
|
||||
use crossterm::event::{KeyCode, KeyEvent};
|
||||
use ratatui::{
|
||||
layout::{Constraint, Direction, Layout, Rect},
|
||||
@ -9,10 +8,9 @@ use ratatui::{
|
||||
Frame,
|
||||
};
|
||||
use soundcloud::sobjects::{CloudPlaylist, CloudPlaylists};
|
||||
use strum::IntoEnumIterator;
|
||||
use tokio::sync::mpsc::UnboundedSender;
|
||||
|
||||
use crate::{db::Track, screen::AppScreen, sync::AppEvent};
|
||||
use crate::{db::Track, screen::AppScreen, sync::AppEvent, theme::Theme};
|
||||
|
||||
pub struct MainScreen {
|
||||
selected_tab: i8,
|
||||
@ -36,7 +34,7 @@ impl AppScreen for MainScreen {
|
||||
}
|
||||
}
|
||||
|
||||
fn render(&self, frame: &mut Frame) {
|
||||
fn render(&self, frame: &mut Frame, theme: &Theme) {
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([
|
||||
@ -55,11 +53,11 @@ impl AppScreen for MainScreen {
|
||||
.block(Block::default().borders(Borders::ALL))
|
||||
.highlight_style(
|
||||
Style::default()
|
||||
.fg(Color::Cyan)
|
||||
.fg(Color::LightBlue)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.select(self.selected_tab as usize)
|
||||
.style(Style::default().fg(Color::White));
|
||||
.style(Style::default().fg(Color::Black));
|
||||
|
||||
frame.render_widget(tabs, chunks[0]);
|
||||
|
||||
@ -179,7 +177,7 @@ impl MainScreen {
|
||||
"NO".to_string(),
|
||||
]);
|
||||
if self.selected_row == i as i32 {
|
||||
row = row.style(Style::default().bg(Color::Yellow));
|
||||
row = row.style(Style::default().bg(Color::LightBlue).fg(Color::White));
|
||||
}
|
||||
v.push(row);
|
||||
}
|
||||
@ -203,7 +201,7 @@ impl MainScreen {
|
||||
format!("{:X}", track.dbid),
|
||||
]);
|
||||
if self.selected_row == i as i32 {
|
||||
row = row.style(Style::default().bg(Color::Yellow));
|
||||
row = row.style(Style::default().bg(Color::LightBlue).fg(Color::White));
|
||||
}
|
||||
v.push(row);
|
||||
}
|
||||
@ -225,7 +223,7 @@ impl MainScreen {
|
||||
],
|
||||
)
|
||||
.block(Block::default().borders(Borders::ALL).title(" Playlists "))
|
||||
.style(Style::default().fg(Color::White));
|
||||
.style(Style::default().fg(Color::Black));
|
||||
|
||||
frame.render_widget(table, area);
|
||||
}
|
||||
|
@ -3,10 +3,12 @@ use std::any::Any;
|
||||
use crossterm::event::KeyEvent;
|
||||
use ratatui::Frame;
|
||||
|
||||
use crate::theme::Theme;
|
||||
|
||||
pub trait AppScreen {
|
||||
fn handle_key_event(&mut self, key_event: KeyEvent);
|
||||
|
||||
fn render(&self, frame: &mut Frame);
|
||||
fn render(&self, frame: &mut Frame, theme: &Theme);
|
||||
|
||||
fn as_any(&mut self) -> &mut dyn Any;
|
||||
}
|
||||
}
|
||||
|
29
src/theme.rs
Normal file
29
src/theme.rs
Normal file
@ -0,0 +1,29 @@
|
||||
use ratatui::style::Color;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Theme {
|
||||
background: u32,
|
||||
foreground: u32,
|
||||
}
|
||||
|
||||
impl Theme {
|
||||
pub fn background(&self) -> Color {
|
||||
Color::from_u32(self.background)
|
||||
}
|
||||
|
||||
pub fn foreground(&self) -> Color {
|
||||
Color::from_u32(self.foreground)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Theme {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
background: 0x00D75FAF,
|
||||
foreground: u32::MAX,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn load_theme() {}
|
@ -1,44 +1,39 @@
|
||||
use ratatui::{style::Stylize, symbols::border, text::{Line, Text}, widgets::{Block, Paragraph}, Frame};
|
||||
use color_eyre::owo_colors::OwoColorize;
|
||||
use ratatui::{
|
||||
style::{Style, Stylize},
|
||||
symbols::border,
|
||||
text::{Line, Text},
|
||||
widgets::{Block, Paragraph},
|
||||
Frame,
|
||||
};
|
||||
|
||||
use crate::screen::AppScreen;
|
||||
use crate::{screen::AppScreen, theme::Theme};
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct WaitScreen {}
|
||||
|
||||
impl AppScreen for WaitScreen {
|
||||
fn handle_key_event(&mut self, key_event: crossterm::event::KeyEvent) {
|
||||
todo!()
|
||||
}
|
||||
fn handle_key_event(&mut self, key_event: crossterm::event::KeyEvent) {}
|
||||
|
||||
fn render(&self, frame: &mut Frame) {
|
||||
fn render(&self, frame: &mut Frame, theme: &Theme) {
|
||||
let title = Line::from(" Lyrica ".bold());
|
||||
let instructions = Line::from(vec![
|
||||
" Quit ".into(),
|
||||
"<Q> ".red().bold(),
|
||||
]);
|
||||
let instructions = Line::from(vec![" Quit ".into(), "<Q> ".red().bold()]);
|
||||
let block = Block::bordered()
|
||||
.title(title.centered())
|
||||
.title_bottom(instructions.centered())
|
||||
.border_set(border::ROUNDED);
|
||||
|
||||
let counter_text = Text::from(
|
||||
vec![
|
||||
Line::from(
|
||||
vec![
|
||||
"Searching for iPod...".into()
|
||||
]
|
||||
)
|
||||
]
|
||||
);
|
||||
let counter_text = Text::from(vec![Line::from(vec!["Searching for iPod...".into()])]);
|
||||
|
||||
let par = Paragraph::new(counter_text)
|
||||
.style(Style::new().bg(theme.background()))
|
||||
.centered()
|
||||
.block(block);
|
||||
|
||||
frame.render_widget(par, frame.area());
|
||||
}
|
||||
|
||||
|
||||
fn as_any(&mut self) -> &mut dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user