aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2024-10-08 16:57:54 +0200
committerGitHub <noreply@github.com>2024-10-08 16:57:54 +0200
commit203fbf7a491d1abc3cd9e05c1e39858af8395032 (patch)
tree94c48ef5063b4b40d8ba5741320b8edd4c143955 /src
parentdocs(changelog): http fix (diff)
downloadsl0ppij-203fbf7a491d1abc3cd9e05c1e39858af8395032.tar.gz
sl0ppij-203fbf7a491d1abc3cd9e05c1e39858af8395032.tar.xz
sl0ppij-203fbf7a491d1abc3cd9e05c1e39858af8395032.zip
feat(cli): make --layout idempotent(-ish) (#3650)
* feat(cli): if inside a session, apply --layout to the session * fix(screen): some focusing races when switching tab focus * style(fmt): rustfmt
Diffstat (limited to 'src')
-rw-r--r--src/main.rs26
-rw-r--r--src/tests/e2e/remote_runner.rs4
2 files changed, 28 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index eacefc8a..18370985 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -6,8 +6,10 @@ mod tests;
use zellij_utils::{
clap::Parser,
cli::{CliAction, CliArgs, Command, Sessions},
+ envs,
input::config::Config,
logging::*,
+ setup::Setup,
};
fn main() {
@@ -190,6 +192,30 @@ fn main() {
commands::delete_session(target_session, force);
} else if let Some(path) = opts.server {
commands::start_server(path, opts.debug);
+ } else if let Some(layout) = &opts.layout {
+ if let Some(session_name) = opts
+ .session
+ .as_ref()
+ .cloned()
+ .or_else(|| envs::get_session_name().ok())
+ {
+ let config = Config::try_from(&opts).ok();
+ let options = Setup::from_cli_args(&opts).ok().map(|r| r.2);
+ let new_layout_cli_action = CliAction::NewTab {
+ layout: Some(layout.clone()),
+ layout_dir: options.as_ref().and_then(|o| o.layout_dir.clone()),
+ name: None,
+ cwd: options.as_ref().and_then(|o| o.default_cwd.clone()),
+ };
+ commands::send_action_to_session(new_layout_cli_action, Some(session_name), config);
+ } else {
+ commands::start_client(opts);
+ }
+ } else if let Some(layout_for_new_session) = &opts.new_session_with_layout {
+ let mut opts = opts.clone();
+ opts.new_session_with_layout = None;
+ opts.layout = Some(layout_for_new_session.clone());
+ commands::start_client(opts);
} else {
commands::start_client(opts);
}
diff --git a/src/tests/e2e/remote_runner.rs b/src/tests/e2e/remote_runner.rs
index 40feeb21..6b702f01 100644
--- a/src/tests/e2e/remote_runner.rs
+++ b/src/tests/e2e/remote_runner.rs
@@ -111,7 +111,7 @@ fn start_zellij_mirrored_session_with_layout(channel: &mut ssh2::Channel, layout
channel
.write_all(
format!(
- "{} {} --session {} --data-dir {} --layout {} options --mirror-session true --serialization-interval 1\n",
+ "{} {} --session {} --data-dir {} --new-session-with-layout {} options --mirror-session true --serialization-interval 1\n",
SET_ENV_VARIABLES,
ZELLIJ_EXECUTABLE_LOCATION,
SESSION_NAME,
@@ -133,7 +133,7 @@ fn start_zellij_mirrored_session_with_layout_and_viewport_serialization(
channel
.write_all(
format!(
- "{} {} --session {} --data-dir {} --layout {} options --mirror-session true --serialize-pane-viewport true --serialization-interval 1\n",
+ "{} {} --session {} --data-dir {} --new-session-with-layout {} options --mirror-session true --serialize-pane-viewport true --serialization-interval 1\n",
SET_ENV_VARIABLES,
ZELLIJ_EXECUTABLE_LOCATION,
SESSION_NAME,