added src/output.rs to handle command output
adjusted todo.md
This commit is contained in:
+31
-81
@@ -6,17 +6,10 @@
|
||||
use dirs::config_dir;
|
||||
use std::fs;
|
||||
use std::io::{Error, Result};
|
||||
use std::path::PathBuf;
|
||||
use config_parser::*;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Config {
|
||||
conf_file: PathBuf,
|
||||
pub settings: Settings,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, ConfigParser)]
|
||||
pub struct Settings {
|
||||
pub struct Config {
|
||||
#[nested_config]
|
||||
pub general: GeneralSettings,
|
||||
#[nested_config]
|
||||
@@ -41,6 +34,10 @@ pub struct FormatSettings {
|
||||
|
||||
#[derive(Debug, Clone, Default, ConfigParser)]
|
||||
pub struct StyleSettings {
|
||||
#[style_config]
|
||||
pub warning_style: String,
|
||||
#[style_config]
|
||||
pub error_style: String,
|
||||
#[style_config]
|
||||
pub stack_number_style: String,
|
||||
#[style_config]
|
||||
@@ -61,30 +58,29 @@ impl Config {
|
||||
/// generates and populates a new instance of Config
|
||||
pub fn new(styles_as_ansi_sequences: bool) -> Result<Self> {
|
||||
let mut config = Config {
|
||||
conf_file: PathBuf::new(),
|
||||
settings: Settings {
|
||||
general: GeneralSettings {
|
||||
show_stack_on_push: false,
|
||||
show_stack_on_pop: false,
|
||||
show_books_on_bookmark: false,
|
||||
},
|
||||
format: FormatSettings {
|
||||
bookmarks_separator: String::new(),
|
||||
stack_separator: String::new(),
|
||||
align_separators: false,
|
||||
},
|
||||
styles: StyleSettings {
|
||||
stack_number_style: String::new(),
|
||||
stack_separator_style: String::new(),
|
||||
stack_path_style: String::new(),
|
||||
bookmarks_name_style: String::new(),
|
||||
bookmarks_seperator_style: String::new(),
|
||||
bookmarks_path_style: String::new(),
|
||||
},
|
||||
general: GeneralSettings {
|
||||
show_stack_on_push: false,
|
||||
show_stack_on_pop: false,
|
||||
show_books_on_bookmark: false,
|
||||
},
|
||||
format: FormatSettings {
|
||||
bookmarks_separator: String::new(),
|
||||
stack_separator: String::new(),
|
||||
align_separators: false,
|
||||
},
|
||||
styles: StyleSettings {
|
||||
warning_style: String::new(),
|
||||
error_style: String::new(),
|
||||
stack_number_style: String::new(),
|
||||
stack_separator_style: String::new(),
|
||||
stack_path_style: String::new(),
|
||||
bookmarks_name_style: String::new(),
|
||||
bookmarks_seperator_style: String::new(),
|
||||
bookmarks_path_style: String::new(),
|
||||
},
|
||||
};
|
||||
// get configuration directory
|
||||
config.conf_file = match config_dir() {
|
||||
let mut conf_file = match config_dir() {
|
||||
Some(value) => value,
|
||||
None => {
|
||||
return Err(Error::other(
|
||||
@@ -93,27 +89,21 @@ impl Config {
|
||||
}
|
||||
};
|
||||
// expand path to configuration file
|
||||
config
|
||||
.conf_file
|
||||
.push(format!("navigate/{}", Self::CONFIG_FILE_NAME));
|
||||
conf_file.push(format!("navigate/{}", Self::CONFIG_FILE_NAME));
|
||||
|
||||
// parse configuration file and populate config struct
|
||||
if config.conf_file.is_file() {
|
||||
let config_str = match fs::read_to_string(&config.conf_file) {
|
||||
if conf_file.is_file() {
|
||||
let config_str = match fs::read_to_string(&conf_file) {
|
||||
Ok(value) => value,
|
||||
Err(error) => return Err(error),
|
||||
};
|
||||
_ = config.settings.parse_from_string(&config_str);
|
||||
_ = config.parse_from_string(&config_str);
|
||||
} else {
|
||||
// TODO: write default configuration
|
||||
}
|
||||
|
||||
// TODO: ALSDKJFJFJASDkk
|
||||
//config.set_default_settings()?;
|
||||
//config.parse_color_settings()?;
|
||||
|
||||
if styles_as_ansi_sequences {
|
||||
config.settings.to_ansi_sequences()?;
|
||||
config.to_ansi_sequences()?;
|
||||
}
|
||||
|
||||
Ok(config)
|
||||
@@ -121,47 +111,7 @@ impl Config {
|
||||
|
||||
/// formats and prints config to string
|
||||
pub fn to_formatted_string(&self) -> Result<String> {
|
||||
Ok(format!("{:#?}", self.settings))
|
||||
Ok(format!("{:#?}", self))
|
||||
}
|
||||
|
||||
/// reads and parses the configuration file
|
||||
fn build_settings(&mut self) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// sets defaults for settings not found in the configuration file
|
||||
fn set_default_settings(&mut self) -> Result<()> {
|
||||
let default_separator = " - ".to_owned();
|
||||
let default_number_color = "default".to_owned();
|
||||
let default_separator_color = "cyan".to_owned();
|
||||
let default_path_color = "default".to_owned();
|
||||
|
||||
if self.settings.format.stack_separator.is_empty() {
|
||||
self.settings.format.stack_separator = default_separator.clone();
|
||||
}
|
||||
if self.settings.format.bookmarks_separator.is_empty() {
|
||||
self.settings.format.bookmarks_separator = default_separator.clone();
|
||||
}
|
||||
|
||||
if self.settings.styles.stack_number_style.is_empty() {
|
||||
self.settings.styles.stack_number_style = default_number_color.clone();
|
||||
}
|
||||
if self.settings.styles.stack_separator_style.is_empty() {
|
||||
self.settings.styles.stack_separator_style = default_separator_color.clone();
|
||||
}
|
||||
if self.settings.styles.stack_path_style.is_empty() {
|
||||
self.settings.styles.stack_path_style = default_path_color.clone();
|
||||
}
|
||||
if self.settings.styles.bookmarks_name_style.is_empty() {
|
||||
self.settings.styles.bookmarks_name_style = default_number_color.clone();
|
||||
}
|
||||
if self.settings.styles.bookmarks_seperator_style.is_empty() {
|
||||
self.settings.styles.bookmarks_seperator_style = default_separator_color.clone();
|
||||
}
|
||||
if self.settings.styles.bookmarks_path_style.is_empty() {
|
||||
self.settings.styles.bookmarks_path_style = default_path_color.clone();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user