Skip to content

Commit

Permalink
Merge pull request #33 from lusingander/color
Browse files Browse the repository at this point in the history
Change color definitions to use theme variables
  • Loading branch information
lusingander authored Sep 28, 2024
2 parents 02a9867 + ef08696 commit b28b7af
Show file tree
Hide file tree
Showing 22 changed files with 654 additions and 200 deletions.
22 changes: 17 additions & 5 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use tokio::spawn;

use crate::{
client::Client,
color::ColorTheme,
config::Config,
error::{AppError, Result},
event::{
Expand Down Expand Up @@ -57,17 +58,19 @@ pub struct App {
app_objects: AppObjects,
client: Option<Arc<Client>>,
config: Config,
pub theme: ColorTheme,
tx: Sender,
}

impl App {
pub fn new(config: Config, tx: Sender, width: usize, height: usize) -> App {
pub fn new(config: Config, theme: ColorTheme, tx: Sender, width: usize, height: usize) -> App {
App {
app_view_state: AppViewState::new(width, height),
app_objects: AppObjects::default(),
page_stack: PageStack::new(tx.clone()),
page_stack: PageStack::new(theme.clone(), tx.clone()),
client: None,
config,
theme,
tx,
}
}
Expand Down Expand Up @@ -95,8 +98,11 @@ impl App {
Ok(CompleteInitializeResult { buckets }) => {
self.app_objects.set_bucket_items(buckets);

let bucket_list_page =
Page::of_bucket_list(self.app_objects.get_bucket_items(), self.tx.clone());
let bucket_list_page = Page::of_bucket_list(
self.app_objects.get_bucket_items(),
self.theme.clone(),
self.tx.clone(),
);
self.page_stack.pop(); // remove initializing page
self.page_stack.push(bucket_list_page);
}
Expand Down Expand Up @@ -145,6 +151,7 @@ impl App {
current_object_items,
object_key,
self.config.ui.clone(),
self.theme.clone(),
self.tx.clone(),
);
self.page_stack.push(object_list_page);
Expand Down Expand Up @@ -178,6 +185,7 @@ impl App {
current_object_key,
object_list_page.list_state(),
self.config.ui.clone(),
self.theme.clone(),
self.tx.clone(),
);
self.page_stack.push(object_detail_page);
Expand All @@ -194,6 +202,7 @@ impl App {
current_object_items,
object_key,
self.config.ui.clone(),
self.theme.clone(),
self.tx.clone(),
);
self.page_stack.push(new_object_list_page);
Expand Down Expand Up @@ -261,6 +270,7 @@ impl App {
items,
current_object_key,
self.config.ui.clone(),
self.theme.clone(),
self.tx.clone(),
);
self.page_stack.push(object_list_page);
Expand Down Expand Up @@ -329,6 +339,7 @@ impl App {
map_key,
object_page.list_state(),
self.config.ui.clone(),
self.theme.clone(),
self.tx.clone(),
);
self.page_stack.push(object_detail_page);
Expand Down Expand Up @@ -403,7 +414,7 @@ impl App {
Page::ObjectDetail(page) => page.helps(),
Page::ObjectPreview(page) => page.helps(),
};
let help_page = Page::of_help(helps, self.tx.clone());
let help_page = Page::of_help(helps, self.theme.clone(), self.tx.clone());
self.page_stack.push(help_page);
}

Expand Down Expand Up @@ -524,6 +535,7 @@ impl App {
path,
current_object_key,
self.config.preview.clone(),
self.theme.clone(),
self.tx.clone(),
);
self.page_stack.push(object_preview_page);
Expand Down
58 changes: 58 additions & 0 deletions src/color.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use ratatui::style::Color;

#[derive(Debug, Clone)]
pub struct ColorTheme {
pub bg: Color,
pub fg: Color,

pub divider: Color,
pub link: Color,

pub list_selected_bg: Color,
pub list_selected_fg: Color,
pub list_selected_inactive_bg: Color,
pub list_selected_inactive_fg: Color,
pub list_filter_match: Color,

pub detail_selected: Color,

pub dialog_selected: Color,

pub preview_line_number: Color,

pub status_help: Color,
pub status_info: Color,
pub status_success: Color,
pub status_warn: Color,
pub status_error: Color,
}

impl Default for ColorTheme {
fn default() -> Self {
Self {
bg: Color::Reset,
fg: Color::Reset,

divider: Color::DarkGray,
link: Color::Blue,

list_selected_bg: Color::Cyan,
list_selected_fg: Color::Black,
list_selected_inactive_bg: Color::DarkGray,
list_selected_inactive_fg: Color::Black,
list_filter_match: Color::Red,

detail_selected: Color::Cyan,

dialog_selected: Color::Cyan,

preview_line_number: Color::DarkGray,

status_help: Color::DarkGray,
status_info: Color::Blue,
status_success: Color::Green,
status_warn: Color::Yellow,
status_error: Color::Red,
}
}
}
8 changes: 6 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod app;
mod cache;
mod client;
mod color;
mod config;
mod constant;
mod error;
Expand All @@ -24,6 +25,7 @@ use tracing_subscriber::fmt::time::ChronoLocal;

use crate::app::App;
use crate::client::Client;
use crate::color::ColorTheme;
use crate::config::Config;

/// STU - S3 Terminal UI
Expand Down Expand Up @@ -55,11 +57,12 @@ struct Args {
async fn main() -> anyhow::Result<()> {
let args = Args::parse();
let config = Config::load()?;
let theme = ColorTheme::default();

initialize_debug_log(&args, &config)?;

let mut terminal = ratatui::try_init()?;
let ret = run(&mut terminal, args, config).await;
let ret = run(&mut terminal, args, config, theme).await;

ratatui::try_restore()?;

Expand All @@ -70,12 +73,13 @@ async fn run<B: Backend>(
terminal: &mut Terminal<B>,
args: Args,
config: Config,
theme: ColorTheme,
) -> anyhow::Result<()> {
let (tx, rx) = event::new();
let (width, height) = get_frame_size(terminal);
let default_region_fallback = config.default_region.clone();

let mut app = App::new(config, tx.clone(), width, height);
let mut app = App::new(config, theme, tx.clone(), width, height);

spawn(async move {
let client = Client::new(
Expand Down
Loading

0 comments on commit b28b7af

Please sign in to comment.