mirror of
https://github.com/zellij-org/zellij.git
synced 2024-11-29 23:31:03 +03:00
Slight rework of config loading.
Merges the cli and file configuration
This commit is contained in:
parent
2c2ab15ee7
commit
6ffd698d0a
@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
|||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
* Change Switch default config loading order of `HOME` and system (https://github.com/zellij-org/zellij/pull/488)
|
* Change Switch default config loading order of `HOME` and system (https://github.com/zellij-org/zellij/pull/488)
|
||||||
* Add support for requesting a simpler layout from plugins, move `clean` flag from `options` to `setup` (https://github.com/zellij-org/zellij/pull/479)
|
* Add support for requesting a simpler layout from plugins, move `clean` flag from `options` to `setup` (https://github.com/zellij-org/zellij/pull/479)
|
||||||
|
* Improve config loading slightly (https://github.com/zellij-org/zellij/pull/492)
|
||||||
|
|
||||||
## [0.9.0] - 2021-05-11
|
## [0.9.0] - 2021-05-11
|
||||||
* Add more functionality to unbinding the default keybindings (https://github.com/zellij-org/zellij/pull/468)
|
* Add more functionality to unbinding the default keybindings (https://github.com/zellij-org/zellij/pull/468)
|
||||||
|
@ -11,10 +11,6 @@ pub struct CliArgs {
|
|||||||
#[structopt(long)]
|
#[structopt(long)]
|
||||||
pub max_panes: Option<usize>,
|
pub max_panes: Option<usize>,
|
||||||
|
|
||||||
/// Speficy, if a simplified layout should be used that is compatible with more fonts
|
|
||||||
#[structopt(long)]
|
|
||||||
pub simplified: bool,
|
|
||||||
|
|
||||||
/// Change where zellij looks for layouts and plugins
|
/// Change where zellij looks for layouts and plugins
|
||||||
#[structopt(long)]
|
#[structopt(long)]
|
||||||
pub data_dir: Option<PathBuf>,
|
pub data_dir: Option<PathBuf>,
|
||||||
|
@ -15,6 +15,7 @@ use crate::common::{
|
|||||||
errors::{ClientContext, ContextType},
|
errors::{ClientContext, ContextType},
|
||||||
input::config::Config,
|
input::config::Config,
|
||||||
input::handler::input_loop,
|
input::handler::input_loop,
|
||||||
|
input::options::{ConfigOptions, Options},
|
||||||
os_input_output::ClientOsApi,
|
os_input_output::ClientOsApi,
|
||||||
thread_bus::{SenderType, SenderWithContext, SyncChannelWithContext},
|
thread_bus::{SenderType, SenderWithContext, SyncChannelWithContext},
|
||||||
};
|
};
|
||||||
@ -40,12 +41,15 @@ pub fn start_client(mut os_input: Box<dyn ClientOsApi>, opts: CliArgs, config: C
|
|||||||
|
|
||||||
let mut command_is_executing = CommandIsExecuting::new();
|
let mut command_is_executing = CommandIsExecuting::new();
|
||||||
|
|
||||||
|
let config_options: ConfigOptions =
|
||||||
|
Options::from_cli(&config.options, opts.option.clone()).into();
|
||||||
|
|
||||||
let full_screen_ws = os_input.get_terminal_size_using_fd(0);
|
let full_screen_ws = os_input.get_terminal_size_using_fd(0);
|
||||||
os_input.connect_to_server();
|
os_input.connect_to_server();
|
||||||
os_input.send_to_server(ServerInstruction::NewClient(
|
os_input.send_to_server(ServerInstruction::NewClient(
|
||||||
full_screen_ws,
|
full_screen_ws,
|
||||||
opts,
|
opts,
|
||||||
config.options.clone(),
|
config_options,
|
||||||
));
|
));
|
||||||
os_input.set_raw_mode(0);
|
os_input.set_raw_mode(0);
|
||||||
|
|
||||||
|
@ -1,12 +1,23 @@
|
|||||||
|
//! Handles cli and configuration options
|
||||||
|
use crate::cli::ConfigCli;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
#[derive(Clone, Default, Debug, PartialEq, Deserialize, Serialize, StructOpt)]
|
#[derive(Clone, Default, Debug, PartialEq, Deserialize, Serialize, StructOpt)]
|
||||||
/// Options that can be set either through the config file,
|
/// Options that can be set either through the config file,
|
||||||
/// or cli flags
|
/// or cli flags
|
||||||
|
/// intermediate struct
|
||||||
pub struct Options {
|
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)]
|
#[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,
|
pub simplified_ui: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,4 +29,35 @@ impl Options {
|
|||||||
Options::default()
|
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(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,7 @@ use std::collections::BTreeMap;
|
|||||||
use std::os::unix::io::RawFd;
|
use std::os::unix::io::RawFd;
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
use crate::cli::ConfigCli;
|
use crate::common::input::options::ConfigOptions;
|
||||||
use crate::common::input::options::Options;
|
|
||||||
use crate::common::pty::{PtyInstruction, VteBytes};
|
use crate::common::pty::{PtyInstruction, VteBytes};
|
||||||
use crate::common::thread_bus::Bus;
|
use crate::common::thread_bus::Bus;
|
||||||
use crate::errors::{ContextType, ScreenContext};
|
use crate::errors::{ContextType, ScreenContext};
|
||||||
@ -330,15 +329,11 @@ pub fn screen_thread_main(
|
|||||||
bus: Bus<ScreenInstruction>,
|
bus: Bus<ScreenInstruction>,
|
||||||
max_panes: Option<usize>,
|
max_panes: Option<usize>,
|
||||||
full_screen_ws: PositionAndSize,
|
full_screen_ws: PositionAndSize,
|
||||||
options: Option<ConfigCli>,
|
config_options: ConfigOptions,
|
||||||
config_options: Options,
|
|
||||||
) {
|
) {
|
||||||
let colors = bus.os_input.as_ref().unwrap().load_palette();
|
let colors = bus.os_input.as_ref().unwrap().load_palette();
|
||||||
let capabilities = if let Some(ConfigCli::Options(options)) = options {
|
let capabilities = config_options.simplified_ui;
|
||||||
options.simplified_ui
|
|
||||||
} else {
|
|
||||||
config_options.simplified_ui
|
|
||||||
};
|
|
||||||
let mut screen = Screen::new(
|
let mut screen = Screen::new(
|
||||||
bus,
|
bus,
|
||||||
&full_screen_ws,
|
&full_screen_ws,
|
||||||
|
@ -12,7 +12,7 @@ use crate::client::ClientInstruction;
|
|||||||
use crate::common::thread_bus::{Bus, ThreadSenders};
|
use crate::common::thread_bus::{Bus, ThreadSenders};
|
||||||
use crate::common::{
|
use crate::common::{
|
||||||
errors::{ContextType, ServerContext},
|
errors::{ContextType, ServerContext},
|
||||||
input::{actions::Action, options::Options},
|
input::{actions::Action, options::ConfigOptions},
|
||||||
os_input_output::{set_permissions, ServerOsApi},
|
os_input_output::{set_permissions, ServerOsApi},
|
||||||
pty::{pty_thread_main, Pty, PtyInstruction},
|
pty::{pty_thread_main, Pty, PtyInstruction},
|
||||||
screen::{screen_thread_main, ScreenInstruction},
|
screen::{screen_thread_main, ScreenInstruction},
|
||||||
@ -30,7 +30,7 @@ use route::route_thread_main;
|
|||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub enum ServerInstruction {
|
pub enum ServerInstruction {
|
||||||
TerminalResize(PositionAndSize),
|
TerminalResize(PositionAndSize),
|
||||||
NewClient(PositionAndSize, CliArgs, Options),
|
NewClient(PositionAndSize, CliArgs, ConfigOptions),
|
||||||
Action(Action),
|
Action(Action),
|
||||||
Render(Option<String>),
|
Render(Option<String>),
|
||||||
UnblockInputThread,
|
UnblockInputThread,
|
||||||
@ -155,7 +155,7 @@ pub fn start_server(os_input: Box<dyn ServerOsApi>) -> thread::JoinHandle<()> {
|
|||||||
fn init_session(
|
fn init_session(
|
||||||
os_input: Box<dyn ServerOsApi>,
|
os_input: Box<dyn ServerOsApi>,
|
||||||
opts: CliArgs,
|
opts: CliArgs,
|
||||||
config_options: Options,
|
config_options: ConfigOptions,
|
||||||
to_server: SenderWithContext<ServerInstruction>,
|
to_server: SenderWithContext<ServerInstruction>,
|
||||||
full_screen_ws: PositionAndSize,
|
full_screen_ws: PositionAndSize,
|
||||||
) -> SessionMetaData {
|
) -> SessionMetaData {
|
||||||
@ -214,16 +214,9 @@ fn init_session(
|
|||||||
Some(os_input.clone()),
|
Some(os_input.clone()),
|
||||||
);
|
);
|
||||||
let max_panes = opts.max_panes;
|
let max_panes = opts.max_panes;
|
||||||
let options = opts.option;
|
|
||||||
|
|
||||||
move || {
|
move || {
|
||||||
screen_thread_main(
|
screen_thread_main(screen_bus, max_panes, full_screen_ws, config_options);
|
||||||
screen_bus,
|
|
||||||
max_panes,
|
|
||||||
full_screen_ws,
|
|
||||||
options,
|
|
||||||
config_options,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user