mirror of
https://github.com/danog/ytop.git
synced 2024-11-30 04:29:10 +01:00
refactor
This commit is contained in:
parent
17a721aa26
commit
58810d1192
@ -118,14 +118,12 @@ fn convert_color(raw: i64) -> Color {
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_colorscheme(
|
||||
config_folder: &Path,
|
||||
colorscheme: &Colorschemes,
|
||||
) -> serde_json::Result<ColorschemeRaw> {
|
||||
fn parse_colorscheme(config_folder: &Path, colorscheme: &Colorschemes) -> ColorschemeRaw {
|
||||
match colorscheme {
|
||||
Colorschemes::Custom(name) => serde_json::from_str(
|
||||
&fs::read_to_string(config_folder.join(name).with_extension("json")).unwrap(),
|
||||
),
|
||||
)
|
||||
.unwrap(),
|
||||
_ => {
|
||||
let json_string = match colorscheme {
|
||||
Colorschemes::Default => include_str!("../colorschemes/default.json"),
|
||||
@ -135,17 +133,12 @@ fn parse_colorscheme(
|
||||
Colorschemes::Vice => include_str!("../colorschemes/vice.json"),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
Ok(serde_json::from_str(json_string)
|
||||
.expect("statically defined and verified json colorschemes"))
|
||||
serde_json::from_str(json_string)
|
||||
.expect("statically defined and verified json colorschemes")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_colorscheme(
|
||||
config_folder: &Path,
|
||||
colorscheme: &Colorschemes,
|
||||
) -> serde_json::Result<Colorscheme> {
|
||||
let raw_colorscheme = parse_colorscheme(config_folder, colorscheme)?;
|
||||
|
||||
Ok(Colorscheme::from(raw_colorscheme))
|
||||
pub fn read_colorscheme(config_folder: &Path, colorscheme: &Colorschemes) -> Colorscheme {
|
||||
parse_colorscheme(config_folder, colorscheme).into()
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ fn main() {
|
||||
let app_dirs = AppDirs::new(Some(PROGRAM_NAME), AppUI::CommandLine).unwrap();
|
||||
let logfile_path = app_dirs.state_dir.join("errors.log");
|
||||
|
||||
let colorscheme = read_colorscheme(&app_dirs.config_dir, &args.colorscheme).unwrap();
|
||||
let colorscheme = read_colorscheme(&app_dirs.config_dir, &args.colorscheme);
|
||||
let mut app = setup_app(&args, update_ratio, &colorscheme, PROGRAM_NAME);
|
||||
setup_logfile(&logfile_path);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user