summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2020-05-17 22:04:54 +0200
committerCanop <cano.petrole@gmail.com>2020-05-17 22:04:54 +0200
commitc34ab59be7547e2420ff83097594733d8d6c258d (patch)
tree56e4f08ce42f85d331ccccd520255219cadcd58b
parent4f9a94e0322a4bffca9eb247817320638e2dd2a0 (diff)
date/time format configured in conf.toml
Fix #229 Format follows https://docs.rs/chrono/0.4.11/chrono/format/strftime/index.html Example: date_time_format = "%Y-%m-%d %R "
-rw-r--r--src/cli.rs3
-rw-r--r--src/conf.rs14
-rw-r--r--src/display/displayable_tree.rs3
-rw-r--r--src/tree/tree_options.rs10
4 files changed, 29 insertions, 1 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 0782fbc..acc32ff 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -164,6 +164,9 @@ pub fn run() -> Result<Option<Launchable>, ProgramError> {
tree_options.apply(&conf_matches);
}
tree_options.apply(&cli_matches);
+ if let Some(format) = &config.date_time_format {
+ tree_options.set_date_time_format(format.clone());
+ }
// verb store is completed from the config file(s)
let mut verb_store = VerbStore::new();
diff --git a/src/conf.rs b/src/conf.rs
index 5cfb6d3..62e163a 100644
--- a/src/conf.rs
+++ b/src/conf.rs
@@ -23,6 +23,7 @@ use {
#[derive(Default)]
pub struct Conf {
pub default_flags: String, // the flags to apply before cli ones
+ pub date_time_format: Option<String>,
pub verbs: Vec<VerbConf>,
pub skin: HashMap<String, SkinEntry>,
}
@@ -105,8 +106,13 @@ impl Conf {
let root: Value = data.parse::<Value>()?;
// reading default flags
if let Some(s) = string_field(&root, "default_flags") {
+ // it's additive because another config file may have
+ // been read before and we usually want all the flags
+ // (the last ones may reverse the first ones)
self.default_flags.push_str(&s);
}
+ // date/time format
+ self.date_time_format = string_field(&root, "date_time_format");
// reading verbs
if let Some(Value::Array(verbs_value)) = &root.get("verbs") {
for verb_value in verbs_value.iter() {
@@ -194,6 +200,14 @@ const DEFAULT_CONF_FILE: &str = r#"
default_flags = ""
###############################################################
+# Date/Time format
+# If you want to change the format for date/time, uncomment the
+# following line and change it according to
+# https://docs.rs/chrono/0.4.11/chrono/format/strftime/index.html
+#
+# date_time_format = "%Y/%m/%d %R "
+
+###############################################################
# Verbs and shortcuts
# You can define your own commands which would be applied to
# the selection.
diff --git a/src/display/displayable_tree.rs b/src/display/displayable_tree.rs
index 57cd116..8ed212a 100644
--- a/src/display/displayable_tree.rs
+++ b/src/display/displayable_tree.rs
@@ -38,6 +38,7 @@ pub struct DisplayableTree<'s, 't> {
}
impl<'s, 't> DisplayableTree<'s, 't> {
+
pub fn out_of_app(tree: &'t Tree, skin: &'s StyleMap, width: u16) -> DisplayableTree<'s, 't> {
DisplayableTree {
tree,
@@ -123,7 +124,7 @@ impl<'s, 't> DisplayableTree<'s, 't> {
{
let date_time: DateTime<Local> = system_time.into();
cond_bg!(date_style, self, selected, self.skin.dates);
- cw.queue_string(date_style, date_time.format("%Y/%m/%d %R ").to_string())
+ cw.queue_string(date_style, date_time.format(self.tree.options.date_time_format).to_string())
}
#[cfg(unix)]
diff --git a/src/tree/tree_options.rs b/src/tree/tree_options.rs
index c23f879..c2dab49 100644
--- a/src/tree/tree_options.rs
+++ b/src/tree/tree_options.rs
@@ -1,5 +1,6 @@
use {crate::pattern::Pattern, clap::ArgMatches};
+/// Options defining how the tree should be build and|or displayed
#[derive(Debug, Clone)]
pub struct TreeOptions {
pub show_hidden: bool, // whether files whose name starts with a dot should be shown
@@ -12,6 +13,7 @@ pub struct TreeOptions {
pub respect_git_ignore: bool, // hide files as requested by .gitignore ?
pub filter_by_git_status: bool, // only show files whose git status is not nul
pub pattern: Pattern, // an optional filtering/scoring pattern
+ pub date_time_format: &'static str,
}
impl TreeOptions {
@@ -27,8 +29,15 @@ impl TreeOptions {
show_git_file_info: self.show_git_file_info,
trim_root: self.trim_root,
pattern: Pattern::None,
+ date_time_format: self.date_time_format,
}
}
+ /// this method does not exist, you saw nothing
+ /// (at least don't call it other than with the config, once)
+ pub fn set_date_time_format(&mut self, format: String) {
+ self.date_time_format = Box::leak(format.into_boxed_str());
+ }
+ /// change tree options according to broot launch arguments
pub fn apply(&mut self, cli_args: &ArgMatches<'_>) {
if cli_args.is_present("sizes") {
self.show_sizes = true;
@@ -90,6 +99,7 @@ impl Default for TreeOptions {
respect_git_ignore: true,
filter_by_git_status: false,
pattern: Pattern::None,
+ date_time_format: "%Y/%m/%d %R ",
}
}
}