Skip to content

Commit

Permalink
Merge pull request #35 from honhimW/34-breaking-change-configuration
Browse files Browse the repository at this point in the history
update configuration
  • Loading branch information
honhimW authored Dec 12, 2024
2 parents d5e8066 + c7bacec commit f01ae4a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 26 deletions.
16 changes: 4 additions & 12 deletions examples/theme.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
use anyhow::Result;
use ratatui::style::palette::tailwind;
use ron::ser::PrettyConfig;
use ratisui::theme::{get_color, Color, Tab, TailwindColor, TailwindPalette, Theme};
use ratisui::theme::TailwindPalette::C100;
use anyhow::{Context, Result};
use ratisui::theme::{Color, Tab, Theme};

fn main() -> Result<()> {
let mut theme = Theme::default();
let mut tab = Tab::default();
theme.tab = tab;

let result = ron::ser::to_string_pretty(&theme, PrettyConfig::default())?;
println!("{}", result);

let color = get_color(|t| &t.tab.explorer.accent);
println!("{:?}", color);

println!("{:?}", Color::hex("ffffff").to_color());
let r_color = Color::hex("ffffff").to_color().context("")?;
assert!(matches!(r_color, ratatui::style::Color::Rgb(255,255,255)));

Ok(())
}
30 changes: 23 additions & 7 deletions src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,40 @@ fn get_file_path<T: Into<String>>(file_name: T) -> Result<std::path::PathBuf> {

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
pub struct Configuration {
pub fps: Option<u8>,
pub scan_size: Option<u16>,
pub try_format: Option<bool>,
#[serde(default = "fps")]
pub fps: u8,
#[serde(default = "scan_size")]
pub scan_size: u16,
#[serde(default = "try_format")]
pub try_format: bool,
pub theme: Option<String>,
}

fn fps() -> u8 {
30
}

fn scan_size() -> u16 {
2_000
}

fn try_format() -> bool {
false
}


#[derive(Serialize, Deserialize)]
pub struct Databases {
pub default_database: Option<String>,
pub databases: HashMap<String, Database>,
}

impl Configuration {
impl Default for Configuration {
fn default() -> Self {
Self {
fps: Some(30),
scan_size: Some(2_000),
try_format: Some(false),
fps: fps(),
scan_size: scan_size(),
try_format: try_format(),
theme: None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async fn main() -> Result<()> {
}

async fn run(mut app: App, mut terminal: TerminalBackEnd, config: Configuration) -> Result<()> {
let fps = cmp::min(config.fps.clone().unwrap_or(30) as usize, 60);
let fps = cmp::min(config.fps as usize, 60);
let delay_millis = 1000 / fps;
let delay_duration = Duration::from_millis(delay_millis as u64);
let mut fps_calculator = FpsCalculator::default();
Expand Down
8 changes: 2 additions & 6 deletions src/tabs/explorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1215,12 +1215,8 @@ impl Listenable for ExplorerTab {
fn on_app_event(&mut self, _app_event: AppEvent) -> Result<()> {
match _app_event {
AppEvent::InitConfig(configuration) => {
if let Some(scan_size) = configuration.scan_size {
self.scan_size = scan_size;
}
if let Some(try_format) = configuration.try_format {
self.try_format = try_format;
}
self.scan_size = configuration.scan_size;
self.try_format = configuration.try_format;
}
AppEvent::Reset => {
self.show_delete_popup = false;
Expand Down

0 comments on commit f01ae4a

Please sign in to comment.