summaryrefslogtreecommitdiffstats
path: root/src/commands.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands.rs')
-rw-r--r--src/commands.rs71
1 files changed, 55 insertions, 16 deletions
diff --git a/src/commands.rs b/src/commands.rs
index 6074ea7d6..52dff211b 100644
--- a/src/commands.rs
+++ b/src/commands.rs
@@ -18,16 +18,17 @@ use zellij_client::{
use zellij_server::{os_input_output::get_server_os_input, start_server as start_server_impl};
use zellij_utils::{
cli::{CliArgs, Command, SessionCommand, Sessions},
- data::ConnectToSession,
+ data::{ConnectToSession, LayoutInfo},
envs,
input::{
actions::Action,
config::{Config, ConfigError},
+ layout::Layout,
options::Options,
},
miette::{Report, Result},
nix,
- setup::Setup,
+ setup::{find_default_config_dir, get_layout_dir, Setup},
};
pub(crate) use crate::sessions::list_sessions;
@@ -383,24 +384,25 @@ fn attach_with_session_name(
pub(crate) fn start_client(opts: CliArgs) {
// look for old YAML config/layout/theme files and convert them to KDL
convert_old_yaml_files(&opts);
- let (config, layout, config_options) = match Setup::from_cli_args(&opts) {
- Ok(results) => results,
- Err(e) => {
- if let ConfigError::KdlError(error) = e {
- let report: Report = error.into();
- eprintln!("{:?}", report);
- } else {
- eprintln!("{}", e);
- }
- process::exit(1);
- },
- };
+ let (config, layout, config_options, config_without_layout, config_options_without_layout) =
+ match Setup::from_cli_args(&opts) {
+ Ok(results) => results,
+ Err(e) => {
+ if let ConfigError::KdlError(error) = e {
+ let report: Report = error.into();
+ eprintln!("{:?}", report);
+ } else {
+ eprintln!("{}", e);
+ }
+ process::exit(1);
+ },
+ };
let mut reconnect_to_session: Option<ConnectToSession> = None;
let os_input = get_os_input(get_client_os_input);
loop {
let os_input = os_input.clone();
- let config = config.clone();
- let layout = layout.clone();
+ let mut config = config.clone();
+ let mut layout = layout.clone();
let mut config_options = config_options.clone();
let mut opts = opts.clone();
let mut is_a_reconnect = false;
@@ -423,6 +425,43 @@ pub(crate) fn start_client(opts: CliArgs) {
opts.session = None;
config_options.attach_to_session = None;
}
+
+ if let Some(reconnect_layout) = &reconnect_to_session.layout {
+ let layout_dir = config.options.layout_dir.clone().or_else(|| {
+ get_layout_dir(opts.config_dir.clone().or_else(find_default_config_dir))
+ });
+ let new_session_layout = match reconnect_layout {
+ LayoutInfo::BuiltIn(layout_name) => Layout::from_default_assets(
+ &PathBuf::from(layout_name),
+ layout_dir.clone(),
+ config_without_layout.clone(),
+ ),
+ LayoutInfo::File(layout_name) => Layout::from_path_or_default(
+ Some(&PathBuf::from(layout_name)),
+ layout_dir.clone(),
+ config_without_layout.clone(),
+ ),
+ };
+ match new_session_layout {
+ Ok(new_session_layout) => {
+ // here we make sure to override both the layout and the config, but we do
+ // this with an instance of the config before it was merged with the
+ // layout configuration of the previous iteration of the loop, since we do
+ // not want it to mix with the config of this session
+ let (new_layout, new_layout_config) = new_session_layout;
+ layout = new_layout;
+ let mut new_config = config_without_layout.clone();
+ let _ = new_config.merge(new_layout_config.clone());
+ config = new_config;
+ config_options =
+ config_options_without_layout.merge(new_layout_config.options);
+ },
+ Err(e) => {
+ log::error!("Failed to parse new session layout: {:?}", e);
+ },
+ }
+ }
+
is_a_reconnect = true;
}