reached usable state with procedural macro
This commit is contained in:
+5
-6
@@ -9,9 +9,8 @@ use std::io::{Error, Result};
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
|
||||
use config_parser::format::make_padding_string;
|
||||
|
||||
use super::{apply_format, config::*};
|
||||
use super::config::*;
|
||||
use config_parser::{make_padding_string, apply_format};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Bookmarks {
|
||||
@@ -132,12 +131,12 @@ impl Bookmarks {
|
||||
};
|
||||
for (mark, path) in &self.bookmarks {
|
||||
let padding = make_padding_string(max_name_len - mark.len());
|
||||
let name = apply_format(mark, &config.styles.bookmarks_name);
|
||||
let name = apply_format(mark, &config.styles.bookmarks_name_style);
|
||||
let separator = apply_format(
|
||||
&config.format.bookmarks_separator,
|
||||
&config.styles.bookmarks_seperator,
|
||||
&config.styles.bookmarks_seperator_style,
|
||||
);
|
||||
let path = apply_format(path.to_str().unwrap(), &config.styles.bookmarks_path);
|
||||
let path = apply_format(path.to_str().unwrap(), &config.styles.bookmarks_path_style);
|
||||
if config.format.align_separators {
|
||||
buffer.push_str(&format!("{}{}{}{}\n", name, padding, separator, path));
|
||||
} else {
|
||||
|
||||
+38
-48
@@ -7,8 +7,9 @@ use dirs::config_dir;
|
||||
use std::fs;
|
||||
use std::io::{Error, Result};
|
||||
use std::path::PathBuf;
|
||||
use config_parser::ConfigParser;
|
||||
use config_parser::format::*;
|
||||
use config_parser::*;
|
||||
|
||||
use crate::debug::debug_print;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Config {
|
||||
@@ -42,25 +43,25 @@ pub struct FormatSettings {
|
||||
|
||||
#[derive(Debug, Clone, Default, ConfigParser)]
|
||||
pub struct StyleSettings {
|
||||
#[color_config]
|
||||
pub stack_number: String,
|
||||
#[color_config]
|
||||
pub stack_separator: String,
|
||||
#[color_config]
|
||||
pub stack_path: String,
|
||||
#[color_config]
|
||||
pub bookmarks_name: String,
|
||||
#[color_config]
|
||||
pub bookmarks_seperator: String,
|
||||
#[color_config]
|
||||
pub bookmarks_path: String,
|
||||
#[style_config]
|
||||
pub stack_number_style: String,
|
||||
#[style_config]
|
||||
pub stack_separator_style: String,
|
||||
#[style_config]
|
||||
pub stack_path_style: String,
|
||||
#[style_config]
|
||||
pub bookmarks_name_style: String,
|
||||
#[style_config]
|
||||
pub bookmarks_seperator_style: String,
|
||||
#[style_config]
|
||||
pub bookmarks_path_style: String,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
const CONFIG_FILE_NAME: &str = "navigate.conf";
|
||||
|
||||
/// generates and populates a new instance of Config
|
||||
pub fn new() -> Result<Self> {
|
||||
pub fn new(styles_as_ansi_sequences: bool) -> Result<Self> {
|
||||
let mut config = Config {
|
||||
conf_file: PathBuf::new(),
|
||||
settings: Settings {
|
||||
@@ -75,12 +76,12 @@ impl Config {
|
||||
align_separators: false,
|
||||
},
|
||||
styles: StyleSettings {
|
||||
stack_number: String::new(),
|
||||
stack_separator: String::new(),
|
||||
stack_path: String::new(),
|
||||
bookmarks_name: String::new(),
|
||||
bookmarks_seperator: String::new(),
|
||||
bookmarks_path: 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(),
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -113,6 +114,10 @@ impl Config {
|
||||
//config.set_default_settings()?;
|
||||
//config.parse_color_settings()?;
|
||||
|
||||
if styles_as_ansi_sequences {
|
||||
config.settings.to_ansi_sequences()?;
|
||||
}
|
||||
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
@@ -140,40 +145,25 @@ impl Config {
|
||||
self.settings.format.bookmarks_separator = default_separator.clone();
|
||||
}
|
||||
|
||||
if self.settings.styles.stack_number.is_empty() {
|
||||
self.settings.styles.stack_number = default_number_color.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.is_empty() {
|
||||
self.settings.styles.stack_separator = default_separator_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.is_empty() {
|
||||
self.settings.styles.stack_path = default_path_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.is_empty() {
|
||||
self.settings.styles.bookmarks_name = default_number_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.is_empty() {
|
||||
self.settings.styles.bookmarks_seperator = default_separator_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.is_empty() {
|
||||
self.settings.styles.bookmarks_path = default_path_color.clone();
|
||||
if self.settings.styles.bookmarks_path_style.is_empty() {
|
||||
self.settings.styles.bookmarks_path_style = default_path_color.clone();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// convert color settings to ansi escape sequences
|
||||
pub fn parse_color_settings(&mut self) -> Result<()> {
|
||||
self.settings.styles.stack_number = parse_style(self.settings.styles.stack_number.clone())?;
|
||||
self.settings.styles.stack_separator =
|
||||
parse_style(self.settings.styles.stack_separator.clone())?;
|
||||
self.settings.styles.stack_path = parse_style(self.settings.styles.stack_path.clone())?;
|
||||
self.settings.styles.bookmarks_name =
|
||||
parse_style(self.settings.styles.bookmarks_name.clone())?;
|
||||
self.settings.styles.bookmarks_seperator =
|
||||
parse_style(self.settings.styles.bookmarks_seperator.clone())?;
|
||||
self.settings.styles.bookmarks_path =
|
||||
parse_style(self.settings.styles.bookmarks_path.clone())?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -8,7 +8,7 @@ use arguments::*;
|
||||
use clap::Parser;
|
||||
use config::*;
|
||||
use bookmarks::*;
|
||||
use config_parser::format::*;
|
||||
use config_parser::*;
|
||||
use stack::Stack;
|
||||
use std::env::{current_dir, var};
|
||||
use std::io::{Error, Result};
|
||||
@@ -25,7 +25,7 @@ fn main() -> Result<()> {
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
let config = match Config::new() {
|
||||
let config = match Config::new(true) {
|
||||
Ok(value) => value,
|
||||
Err(error) => {
|
||||
print!("echo '{}{}{}' && false", style_error, error, RESET_SEQ);
|
||||
|
||||
+3
-3
@@ -41,12 +41,12 @@ impl Stack {
|
||||
let max_num_len = self.stack.len().to_string().len();
|
||||
for (n, item) in self.stack.iter().rev().enumerate() {
|
||||
let padding = make_padding_string(max_num_len - n.to_string().len());
|
||||
let number = apply_format(&n.to_string(), &config.styles.stack_number);
|
||||
let number = apply_format(&n.to_string(), &config.styles.stack_number_style);
|
||||
let separator = apply_format(
|
||||
&config.format.stack_separator,
|
||||
&config.styles.stack_separator,
|
||||
&config.styles.stack_separator_style,
|
||||
);
|
||||
let path = apply_format(item.to_str().unwrap(), &config.styles.stack_path);
|
||||
let path = apply_format(item.to_str().unwrap(), &config.styles.stack_path_style);
|
||||
if config.format.align_separators {
|
||||
buffer.push_str(&format!("{}{}{}{}\n", number, padding, separator, path));
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user