summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/commands.rs214
-rw-r--r--src/main.rs51
-rw-r--r--src/tests/e2e/cases.rs80
-rw-r--r--src/tests/e2e/remote_runner.rs56
-rw-r--r--src/tests/e2e/snapshots/zellij__tests__e2e__cases__bracketed_paste.snap4
-rw-r--r--src/tests/e2e/snapshots/zellij__tests__e2e__cases__close_pane.snap2
-rw-r--r--src/tests/e2e/snapshots/zellij__tests__e2e__cases__close_tab.snap4
-rw-r--r--src/tests/e2e/snapshots/zellij__tests__e2e__cases__detach_and_attach_session.snap2
-rw-r--r--src/tests/e2e/snapshots/zellij__tests__e2e__cases__focus_pane_with_mouse.snap4
-rw-r--r--src/tests/e2e/snapshots/zellij__tests__e2e__cases__mirrored_sessions.snap4
-rw-r--r--src/tests/e2e/snapshots/zellij__tests__e2e__cases__multiple_users_in_different_panes_and_same_tab-2.snap4
-rw-r--r--src/tests/e2e/snapshots/zellij__tests__e2e__cases__multiple_users_in_different_panes_and_same_tab.snap4
-rw-r--r--src/tests/e2e/snapshots/zellij__tests__e2e__cases__multiple_users_in_different_tabs-2.snap4
-rw-r--r--src/tests/e2e/snapshots/zellij__tests__e2e__cases__multiple_users_in_different_tabs.snap4
-rw-r--r--src/tests/e2e/snapshots/zellij__tests__e2e__cases__multiple_users_in_same_pane_and_tab-2.snap4
-rw-r--r--src/tests/e2e/snapshots/zellij__tests__e2e__cases__multiple_users_in_same_pane_and_tab.snap4
-rw-r--r--src/tests/e2e/snapshots/zellij__tests__e2e__cases__open_new_tab.snap2
-rw-r--r--src/tests/e2e/snapshots/zellij__tests__e2e__cases__resize_pane.snap2
-rw-r--r--src/tests/e2e/snapshots/zellij__tests__e2e__cases__resize_terminal_window.snap4
-rw-r--r--src/tests/e2e/snapshots/zellij__tests__e2e__cases__scrolling_inside_a_pane_with_mouse.snap4
-rw-r--r--src/tests/e2e/snapshots/zellij__tests__e2e__cases__split_terminals_vertically.snap2
-rw-r--r--src/tests/e2e/snapshots/zellij__tests__e2e__cases__start_without_pane_frames.snap4
-rw-r--r--src/tests/e2e/snapshots/zellij__tests__e2e__cases__starts_with_one_terminal.snap2
-rw-r--r--src/tests/e2e/snapshots/zellij__tests__e2e__cases__tmux_mode.snap4
-rw-r--r--src/tests/e2e/snapshots/zellij__tests__e2e__cases__typing_exit_closes_pane.snap2
-rw-r--r--src/tests/e2e/snapshots/zellij__tests__e2e__cases__undo_rename_pane.snap4
-rw-r--r--src/tests/e2e/snapshots/zellij__tests__e2e__cases__undo_rename_tab.snap4
-rw-r--r--src/tests/fixtures/configs/changed_keys.kdl12
-rw-r--r--src/tests/fixtures/configs/changed_keys.yaml26
-rw-r--r--src/tests/fixtures/layouts/focus-tab-layout.yaml92
-rw-r--r--src/tests/fixtures/layouts/parts-total-less-than-100-percent.yaml19
-rw-r--r--src/tests/fixtures/layouts/parts-total-more-than-100-percent.yaml20
-rw-r--r--src/tests/fixtures/layouts/three-panes-with-nesting.yaml17
33 files changed, 246 insertions, 419 deletions
diff --git a/src/commands.rs b/src/commands.rs
index 58a464d77..b4e2e1da2 100644
--- a/src/commands.rs
+++ b/src/commands.rs
@@ -6,13 +6,18 @@ use crate::sessions::{
session_exists, ActiveSession, SessionNameMatch,
};
use dialoguer::Confirm;
-use miette::Result;
+use miette::{Report, Result};
use std::path::PathBuf;
use std::process;
+use zellij_client::old_config_converter::{
+ config_yaml_to_config_kdl, convert_old_yaml_files, layout_yaml_to_layout_kdl,
+};
use zellij_client::start_client as start_client_impl;
use zellij_client::{os_input_output::get_client_os_input, ClientInfo};
use zellij_server::os_input_output::get_server_os_input;
use zellij_server::start_server as start_server_impl;
+use zellij_utils::input::actions::Action;
+use zellij_utils::input::config::ConfigError;
use zellij_utils::input::options::Options;
use zellij_utils::nix;
use zellij_utils::{
@@ -21,10 +26,7 @@ use zellij_utils::{
setup::{get_default_data_dir, Setup},
};
-#[cfg(feature = "unstable")]
-use miette::IntoDiagnostic;
-#[cfg(feature = "unstable")]
-use zellij_utils::input::actions::ActionsFromYaml;
+use std::{fs::File, io::prelude::*};
pub(crate) use crate::sessions::list_sessions;
@@ -118,69 +120,133 @@ fn find_indexed_session(
}
}
-/// Send a vec of `[Action]` to a currently running session.
-#[cfg(feature = "unstable")]
-pub(crate) fn send_action_to_session(opts: zellij_utils::cli::CliArgs) {
+pub(crate) fn send_action_to_session(
+ cli_action: zellij_utils::cli::CliAction,
+ requested_session_name: Option<String>,
+) {
match get_active_session() {
ActiveSession::None => {
eprintln!("There is no active session!");
std::process::exit(1);
},
ActiveSession::One(session_name) => {
- attach_with_fake_client(opts, &session_name);
+ if let Some(requested_session_name) = requested_session_name {
+ if requested_session_name != session_name {
+ eprintln!(
+ "Session '{}' not found. The following sessions are active:",
+ requested_session_name
+ );
+ eprintln!("{}", session_name);
+ std::process::exit(1);
+ }
+ }
+ attach_with_cli_client(cli_action, &session_name);
},
ActiveSession::Many => {
- if let Some(session_name) = opts.session.clone() {
- attach_with_fake_client(opts, &session_name);
+ let existing_sessions = get_sessions().unwrap();
+ if let Some(session_name) = requested_session_name {
+ if existing_sessions.contains(&session_name) {
+ attach_with_cli_client(cli_action, &session_name);
+ } else {
+ eprintln!(
+ "Session '{}' not found. The following sessions are active:",
+ session_name
+ );
+ print_sessions(existing_sessions);
+ std::process::exit(1);
+ }
} else if let Ok(session_name) = envs::get_session_name() {
- attach_with_fake_client(opts, &session_name);
+ attach_with_cli_client(cli_action, &session_name);
} else {
- println!("Please specify the session name to send actions to. The following sessions are active:");
- print_sessions(get_sessions().unwrap());
+ eprintln!("Please specify the session name to send actions to. The following sessions are active:");
+ print_sessions(existing_sessions);
std::process::exit(1);
}
},
};
}
+pub(crate) fn convert_old_config_file(old_config_file: PathBuf) {
+ match File::open(&old_config_file) {
+ Ok(mut handle) => {
+ let mut raw_config_file = String::new();
+ let _ = handle.read_to_string(&mut raw_config_file);
+ match config_yaml_to_config_kdl(&raw_config_file, false) {
+ Ok(kdl_config) => {
+ println!("{}", kdl_config);
+ process::exit(0);
+ },
+ Err(e) => {
+ eprintln!("Failed to convert config: {}", e);
+ process::exit(1);
+ },
+ }
+ },
+ Err(e) => {
+ eprintln!("Failed to open file: {}", e);
+ process::exit(1);
+ },
+ }
+}
-#[cfg(feature = "unstable")]
-fn attach_with_fake_client(opts: zellij_utils::cli::CliArgs, name: &str) {
- if let Some(zellij_utils::cli::Command::Sessions(zellij_utils::cli::Sessions::Action {
- action: Some(action),
- })) = opts.command.clone()
- {
- let action = format!("[{}]", action);
- match zellij_utils::serde_yaml::from_str::<ActionsFromYaml>(&action).into_diagnostic() {
- Ok(parsed) => {
- let (config, _, config_options) = match Setup::from_options(&opts) {
- Ok(results) => results,
- Err(e) => {
- eprintln!("{}", e);
- process::exit(1);
- },
- };
- let os_input = get_os_input(zellij_client::os_input_output::get_client_os_input);
+pub(crate) fn convert_old_layout_file(old_layout_file: PathBuf) {
+ match File::open(&old_layout_file) {
+ Ok(mut handle) => {
+ let mut raw_layout_file = String::new();
+ let _ = handle.read_to_string(&mut raw_layout_file);
+ match layout_yaml_to_layout_kdl(&raw_layout_file) {
+ Ok(kdl_layout) => {
+ println!("{}", kdl_layout);
+ process::exit(0);
+ },
+ Err(e) => {
+ eprintln!("Failed to convert layout: {}", e);
+ process::exit(1);
+ },
+ }
+ },
+ Err(e) => {
+ eprintln!("Failed to open file: {}", e);
+ process::exit(1);
+ },
+ }
+}
- let actions = parsed.actions().to_vec();
- log::debug!("Starting fake Zellij client!");
- zellij_client::fake_client::start_fake_client(
- Box::new(os_input),
- opts,
- *Box::new(config),
- config_options,
- ClientInfo::New(name.to_string()),
- None,
- actions,
- );
- log::debug!("Quitting fake client now.");
- std::process::exit(0);
- },
- Err(e) => {
- eprintln!("{:?}", e);
- std::process::exit(1);
- },
- };
- };
+pub(crate) fn convert_old_theme_file(old_theme_file: PathBuf) {
+ match File::open(&old_theme_file) {
+ Ok(mut handle) => {
+ let mut raw_config_file = String::new();
+ let _ = handle.read_to_string(&mut raw_config_file);
+ match config_yaml_to_config_kdl(&raw_config_file, true) {
+ Ok(kdl_config) => {
+ println!("{}", kdl_config);
+ process::exit(0);
+ },
+ Err(e) => {
+ eprintln!("Failed to convert config: {}", e);
+ process::exit(1);
+ },
+ }
+ },
+ Err(e) => {
+ eprintln!("Failed to open file: {}", e);
+ process::exit(1);
+ },
+ }
+}
+
+fn attach_with_cli_client(cli_action: zellij_utils::cli::CliAction, session_name: &str) {
+ let os_input = get_os_input(zellij_client::os_input_output::get_client_os_input);
+ match Action::actions_from_cli(cli_action) {
+ Ok(actions) => {
+ zellij_client::cli_client::start_cli_client(Box::new(os_input), session_name, actions);
+ std::process::exit(0);
+ },
+ Err(e) => {
+ eprintln!("{}", e);
+ log::error!("Error sending action: {}", e);
+ std::process::exit(2);
+ },
+ }
}
fn attach_with_session_index(config_options: Options, index: usize, create: bool) -> ClientInfo {
@@ -249,10 +315,17 @@ fn attach_with_session_name(
}
pub(crate) fn start_client(opts: CliArgs) {
- let (config, layout, config_options) = match Setup::from_options(&opts) {
+ // 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) => {
- eprintln!("{}", e);
+ if let ConfigError::KdlError(error) = e {
+ let report: Report = error.into();
+ eprintln!("{:?}", report);
+ } else {
+ eprintln!("{}", e);
+ }
process::exit(1);
},
};
@@ -285,7 +358,7 @@ pub(crate) fn start_client(opts: CliArgs) {
let attach_layout = match client {
ClientInfo::Attach(_, _) => None,
- ClientInfo::New(_) => layout,
+ ClientInfo::New(_) => Some(layout),
};
if create {
@@ -314,23 +387,21 @@ pub(crate) fn start_client(opts: CliArgs) {
config,
config_options,
ClientInfo::New(session_name),
- layout,
+ Some(layout),
);
} else {
- if let Some(layout_some) = layout.clone() {
- if let Some(session_name) = layout_some.session.name {
- if layout_some.session.attach.unwrap() {
+ if let Some(session_name) = config_options.session_name.as_ref() {
+ match config_options.attach_to_session {
+ Some(true) => {
let client = attach_with_session_name(
- Some(session_name),
+ Some(session_name.clone()),
config_options.clone(),
true,
);
-
let attach_layout = match client {
ClientInfo::Attach(_, _) => None,
- ClientInfo::New(_) => layout,
+ ClientInfo::New(_) => Some(layout),
};
-
start_client_impl(
Box::new(os_input),
opts,
@@ -339,20 +410,23 @@ pub(crate) fn start_client(opts: CliArgs) {
client,
attach_layout,
);
- } else {
+ },
+ _ => {
start_client_plan(session_name.clone());
start_client_impl(
Box::new(os_input),
opts,
config,
- config_options,
- ClientInfo::New(session_name),
- layout,
+ config_options.clone(),
+ ClientInfo::New(session_name.clone()),
+ Some(layout),
);
- }
-
- process::exit(0);
+ },
}
+ // after we detach, this happens and so we need to exit before the rest of the
+ // function happens
+ // TODO: offload this to a different function
+ process::exit(0);
}
let session_name = names::Generator::default().next().unwrap();
@@ -363,7 +437,7 @@ pub(crate) fn start_client(opts: CliArgs) {
config,
config_options,
ClientInfo::New(session_name),
- layout,
+ Some(layout),
);
}
}
diff --git a/src/main.rs b/src/main.rs
index ca05dbf10..d2363e7bb 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -6,7 +6,7 @@ mod tests;
use zellij_utils::{
clap::Parser,
- cli::{CliArgs, Command, Sessions},
+ cli::{CliAction, CliArgs, Command, Sessions},
logging::*,
};
@@ -14,10 +14,53 @@ fn main() {
configure_logger();
let opts = CliArgs::parse();
- #[cfg(feature = "unstable")]
{
- if let Some(Command::Sessions(Sessions::Action { .. })) = opts.command {
- commands::send_action_to_session(opts);
+ if let Some(Command::Sessions(Sessions::Action(cli_action))) = opts.command {
+ commands::send_action_to_session(cli_action, opts.session);
+ std::process::exit(0);
+ }
+ if let Some(Command::Sessions(Sessions::Command {
+ command,
+ direction,
+ cwd,
+ floating,
+ })) = opts.command
+ {
+ let command_cli_action = CliAction::NewPane {
+ command,
+ direction,
+ cwd,
+ floating,
+ };
+ commands::send_action_to_session(command_cli_action, opts.session);
+ std::process::exit(0);
+ }
+ if let Some(Command::Sessions(Sessions::Edit {
+ file,
+ direction,
+ line_number,
+ floating,
+ })) = opts.command
+ {
+ let command_cli_action = CliAction::Edit {
+ file,
+ direction,
+ line_number,
+ floating,
+ };
+ commands::send_action_to_session(command_cli_action, opts.session);
+ std::process::exit(0);
+ }
+ if let Some(Command::Sessions(Sessions::ConvertConfig { old_config_file })) = opts.command {
+ commands::convert_old_config_file(old_config_file);
+ std::process::exit(0);
+ }
+ if let Some(Command::Sessions(Sessions::ConvertLayout { old_layout_file })) = opts.command {
+ commands::convert_old_layout_file(old_layout_file);
+ std::process::exit(0);
+ }
+ if let Some(Command::Sessions(Sessions::ConvertTheme { old_theme_file })) = opts.command {
+ commands::convert_old_theme_file(old_theme_file);
std::process::exit(0);
}
}
diff --git a/src/tests/e2e/cases.rs b/src/tests/e2e/cases.rs
index 7457ed544..63e2d6778 100644
--- a/src/tests/e2e/cases.rs
+++ b/src/tests/e2e/cases.rs
@@ -458,9 +458,8 @@ pub fn close_tab() {
name: "Wait for tab to close",
instruction: |mut remote_terminal: RemoteTerminal| -> bool {
let mut step_is_complete = false;
- if remote_terminal.cursor_position_is(3, 2)
+ if remote_terminal.snapshot_contains("Tab #1")
&& !remote_terminal.snapshot_contains("Tab #2")
- && remote_terminal.tip_appears()
{
// cursor is in the first tab again
step_is_complete = true;
@@ -475,7 +474,8 @@ pub fn close_tab() {
break last_snapshot;
}
};
- assert_snapshot!(last_snapshot);
+ assert!(last_snapshot.contains("Tab #1"));
+ assert!(!last_snapshot.contains("Tab #2"));
}
#[test]
@@ -950,47 +950,12 @@ pub fn detach_and_attach_session() {
#[test]
#[ignore]
-pub fn accepts_basic_layout() {
- let fake_win_size = Size {
- cols: 120,
- rows: 24,
- };
- let layout_file_name = "three-panes-with-nesting.yaml";
- let mut test_attempts = 10;
- let last_snapshot = loop {
- RemoteRunner::kill_running_sessions(fake_win_size);
- let mut runner = RemoteRunner::new_with_layout(fake_win_size, layout_file_name);
- runner.run_all_steps();
- let last_snapshot = runner.take_snapshot_after(Step {
- name: "Wait for app to load",
- instruction: |remote_terminal: RemoteTerminal| -> bool {
- let mut step_is_complete = false;
- if remote_terminal.cursor_position_is(3, 1)
- && remote_terminal.snapshot_contains("$ █ ││$")
- && remote_terminal.snapshot_contains("$ ") {
- step_is_complete = true;
- }
- step_is_complete
- },
- });
- if runner.test_timed_out && test_attempts > 0 {
- test_attempts -= 1;
- continue;
- } else {
- break last_snapshot;
- }
- };
- assert_snapshot!(last_snapshot);
-}
-
-#[test]
-#[ignore]
pub fn status_bar_loads_custom_keybindings() {
let fake_win_size = Size {
cols: 120,
rows: 24,
};
- let config_file_name = "changed_keys.yaml";
+ let config_file_name = "changed_keys.kdl";
let mut test_attempts = 10;
let last_snapshot = loop {
RemoteRunner::kill_running_sessions(fake_win_size);
@@ -1720,43 +1685,6 @@ pub fn toggle_floating_panes() {
#[test]
#[ignore]
-pub fn focus_tab_with_layout() {
- let fake_win_size = Size {
- cols: 120,
- rows: 24,
- };
- let layout_file_name = "focus-tab-layout.yaml";
- let mut test_attempts = 10;
- let last_snapshot