aboutsummaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authora-kenji <aks.kenji@protonmail.com>2021-05-12 09:42:05 +0200
committera-kenji <aks.kenji@protonmail.com>2021-05-12 09:57:47 +0200
commit6ffd698d0a1a974f0cb80cb256f4d58e2c3d97f6 (patch)
tree47d16f195a9cb7e26750fcadb51f61a41e96788b /src/common
parentdocs(changelog): Add Option for Simplified Layout (diff)
downloadsl0ppij-6ffd698d0a1a974f0cb80cb256f4d58e2c3d97f6.tar.gz
sl0ppij-6ffd698d0a1a974f0cb80cb256f4d58e2c3d97f6.tar.xz
sl0ppij-6ffd698d0a1a974f0cb80cb256f4d58e2c3d97f6.zip
Slight rework of config loading.
Merges the cli and file configuration
Diffstat (limited to 'src/common')
-rw-r--r--src/common/input/options.rs44
-rw-r--r--src/common/screen.rs13
2 files changed, 47 insertions, 10 deletions
diff --git a/src/common/input/options.rs b/src/common/input/options.rs
index 3ff2fd8e..3bd3fc31 100644
--- a/src/common/input/options.rs
+++ b/src/common/input/options.rs
@@ -1,12 +1,23 @@
+//! Handles cli and configuration options
+use crate::cli::ConfigCli;
use serde::{Deserialize, Serialize};
use structopt::StructOpt;
#[derive(Clone, Default, Debug, PartialEq, Deserialize, Serialize, StructOpt)]
/// Options that can be set either through the config file,
/// or cli flags
+/// intermediate struct
pub struct Options {
- /// Allow plugins to use a more compatible font type
+ /// Allow plugins to use a more simplified layout
+ /// that is compatible with more fonts
#[structopt(long)]
+ pub simplified_ui: Option<bool>,
+}
+
+#[derive(Clone, Default, Debug, PartialEq, Deserialize, Serialize)]
+/// Merged version of the [`Options`] struct
+// TODO: Maybe a good candidate for a macro?
+pub struct ConfigOptions {
pub simplified_ui: bool,
}
@@ -18,4 +29,35 @@ impl Options {
Options::default()
}
}
+
+ /// Merges two [`Options`] structs, a `Some` in `other`
+ /// will supercede a `Some` in `self`
+ // TODO: Maybe a good candidate for a macro?
+ pub fn merge(&self, other: Options) -> Options {
+ let simplified_ui = if let Some(bool) = other.simplified_ui {
+ Some(bool)
+ } else {
+ self.simplified_ui
+ };
+
+ Options { simplified_ui }
+ }
+
+ pub fn from_cli(&self, other: Option<ConfigCli>) -> Options {
+ if let Some(ConfigCli::Options(options)) = other {
+ Options::merge(&self, options)
+ } else {
+ self.to_owned()
+ }
+ }
+}
+
+impl From<Options> for ConfigOptions {
+ fn from(options: Options) -> ConfigOptions {
+ let simplified_ui = options.simplified_ui;
+
+ ConfigOptions {
+ simplified_ui: simplified_ui.unwrap_or_default(),
+ }
+ }
}
diff --git a/src/common/screen.rs b/src/common/screen.rs
index 6f5a4cb3..804730d0 100644
--- a/src/common/screen.rs
+++ b/src/common/screen.rs
@@ -4,8 +4,7 @@ use std::collections::BTreeMap;
use std::os::unix::io::RawFd;
use std::str;
-use crate::cli::ConfigCli;
-use crate::common::input::options::Options;
+use crate::common::input::options::ConfigOptions;
use crate::common::pty::{PtyInstruction, VteBytes};
use crate::common::thread_bus::Bus;
use crate::errors::{ContextType, ScreenContext};
@@ -330,15 +329,11 @@ pub fn screen_thread_main(
bus: Bus<ScreenInstruction>,
max_panes: Option<usize>,
full_screen_ws: PositionAndSize,
- options: Option<ConfigCli>,
- config_options: Options,
+ config_options: ConfigOptions,
) {
let colors = bus.os_input.as_ref().unwrap().load_palette();
- let capabilities = if let Some(ConfigCli::Options(options)) = options {
- options.simplified_ui
- } else {
- config_options.simplified_ui
- };
+ let capabilities = config_options.simplified_ui;
+
let mut screen = Screen::new(
bus,
&full_screen_ws,