summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2023-10-21 13:51:48 +0200
committerqkzk <qu3nt1n@gmail.com>2023-10-21 13:51:48 +0200
commit1ba111f594824bbeb2c7cb8cf759b1d0594bb29e (patch)
tree87c10ea255e8438e0aa63441e70af10600aa020d /src
parenteef896c21734079eacbdb8f0e10f7a5055514eb9 (diff)
refactor config & args
Diffstat (limited to 'src')
-rw-r--r--src/args.rs14
-rw-r--r--src/config.rs5
-rw-r--r--src/status.rs26
3 files changed, 26 insertions, 19 deletions
diff --git a/src/args.rs b/src/args.rs
index 0c3bbc3..209460d 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -12,18 +12,14 @@ pub struct Args {
#[arg(short, long, default_value_t = String::from(""))]
pub server: String,
- /// Dual pane ? default to true
- #[arg(short, long, default_value_t = false)]
- pub dual: bool,
+ /// Dual pane ?
+ #[arg(short = 'D', long)]
+ pub dual: Option<bool>,
- /// Display file metadata ? default to true
- #[arg(group = "full", conflicts_with = "metadata", short = 'S', long)]
+ /// Display files metadata ?
+ #[arg(short = 'S', long)]
pub simple: Option<bool>,
- /// Display file metadata ? default to true
- #[arg(group = "full", conflicts_with = "simple", short = 'M', long)]
- pub metadata: Option<bool>,
-
/// Use second pane as preview ? default to false
#[arg(short = 'P', long, default_value_t = false)]
pub preview: bool,
diff --git a/src/config.rs b/src/config.rs
index 00b8e41..e986cd3 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -16,6 +16,7 @@ pub struct Settings {
pub dual: bool,
pub full: bool,
pub all: bool,
+ pub preview: bool,
}
impl Settings {
@@ -32,6 +33,10 @@ impl Settings {
serde_yaml::Value::Bool(false) => self.all = false,
_ => self.all = true,
}
+ match yaml["preview"] {
+ serde_yaml::Value::Bool(true) => self.all = true,
+ _ => self.all = false,
+ }
}
}
diff --git a/src/status.rs b/src/status.rs
index 3dae017..bc69984 100644
--- a/src/status.rs
+++ b/src/status.rs
@@ -112,8 +112,8 @@ impl Status {
let preview_second = args.preview;
let start_folder = std::fs::canonicalize(std::path::PathBuf::from(&args.path))?;
let nvim_server = args.server.clone();
- let display_full = Self::parse_display_full(args.simple, args.metadata, settings.full);
- let dual_pane = (args.dual || settings.dual) && Self::display_wide_enough(&term)?;
+ let display_full = Self::parse_display_full(args.simple, settings.full);
+ let dual_pane = Self::parse_dual_pane(args.dual, settings.dual, &term)?;
let Ok(shell_menu) = ShellMenu::new(TUIS_PATH) else {
Self::quit()
@@ -182,20 +182,26 @@ impl Status {
std::process::exit(1);
}
- fn parse_display_full(
- simple_args: Option<bool>,
- metadata_args: Option<bool>,
- full_config: bool,
- ) -> bool {
+ fn parse_display_full(simple_args: Option<bool>, full_config: bool) -> bool {
if let Some(simple_args) = simple_args {
return !simple_args;
}
- if let Some(metadata_args) = metadata_args {
- return metadata_args;
- }
full_config
}
+ fn parse_dual_pane(
+ args_dual: Option<bool>,
+ dual_config: bool,
+ term: &Arc<Term>,
+ ) -> Result<bool> {
+ if !Self::display_wide_enough(term)? {
+ return Ok(false);
+ }
+ if let Some(args_dual) = args_dual {
+ return Ok(args_dual);
+ }
+ Ok(dual_config)
+ }
/// Select the other tab if two are displayed. Does nother otherwise.
pub fn next(&mut self) {
if !self.dual_pane {