fix(cli): measure cwd from cli client rather than the zellij server (#1947)
* fix(cli): measure cwd from cli client rather than the zellij server * style(fmt): rustfmt
This commit is contained in:
parent
ed64cff9b5
commit
cc3ac25c74
4 changed files with 36 additions and 9 deletions
|
|
@ -238,7 +238,8 @@ pub(crate) fn convert_old_theme_file(old_theme_file: PathBuf) {
|
||||||
|
|
||||||
fn attach_with_cli_client(cli_action: zellij_utils::cli::CliAction, session_name: &str) {
|
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_cli_client_os_input);
|
let os_input = get_os_input(zellij_client::os_input_output::get_cli_client_os_input);
|
||||||
match Action::actions_from_cli(cli_action) {
|
let get_current_dir = || std::env::current_dir().unwrap_or_else(|_| PathBuf::from("."));
|
||||||
|
match Action::actions_from_cli(cli_action, Box::new(get_current_dir)) {
|
||||||
Ok(actions) => {
|
Ok(actions) => {
|
||||||
zellij_client::cli_client::start_cli_client(Box::new(os_input), session_name, actions);
|
zellij_client::cli_client::start_cli_client(Box::new(os_input), session_name, actions);
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,8 @@ fn send_cli_action_to_server(
|
||||||
) {
|
) {
|
||||||
let os_input = Box::new(mock_screen.os_input.clone());
|
let os_input = Box::new(mock_screen.os_input.clone());
|
||||||
let to_server = mock_screen.to_server.clone();
|
let to_server = mock_screen.to_server.clone();
|
||||||
let actions = Action::actions_from_cli(cli_action).unwrap();
|
let get_current_dir = || PathBuf::from(".");
|
||||||
|
let actions = Action::actions_from_cli(cli_action, Box::new(get_current_dir)).unwrap();
|
||||||
for action in actions {
|
for action in actions {
|
||||||
route_action(
|
route_action(
|
||||||
action,
|
action,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
---
|
---
|
||||||
source: zellij-server/src/./unit/screen_tests.rs
|
source: zellij-server/src/./unit/screen_tests.rs
|
||||||
assertion_line: 1989
|
assertion_line: 2287
|
||||||
expression: "format!(\"{:#?}\", new_tab_instruction)"
|
expression: "format!(\"{:#?}\", new_tab_instruction)"
|
||||||
---
|
---
|
||||||
NewTab(
|
NewTab(
|
||||||
|
|
@ -15,7 +15,11 @@ NewTab(
|
||||||
name: None,
|
name: None,
|
||||||
children: [],
|
children: [],
|
||||||
split_size: None,
|
split_size: None,
|
||||||
run: None,
|
run: Some(
|
||||||
|
Cwd(
|
||||||
|
".",
|
||||||
|
),
|
||||||
|
),
|
||||||
borderless: false,
|
borderless: false,
|
||||||
focus: None,
|
focus: None,
|
||||||
external_children_index: None,
|
external_children_index: None,
|
||||||
|
|
@ -25,7 +29,11 @@ NewTab(
|
||||||
name: None,
|
name: None,
|
||||||
children: [],
|
children: [],
|
||||||
split_size: None,
|
split_size: None,
|
||||||
run: None,
|
run: Some(
|
||||||
|
Cwd(
|
||||||
|
".",
|
||||||
|
),
|
||||||
|
),
|
||||||
borderless: false,
|
borderless: false,
|
||||||
focus: None,
|
focus: None,
|
||||||
external_children_index: None,
|
external_children_index: None,
|
||||||
|
|
@ -35,7 +43,11 @@ NewTab(
|
||||||
name: None,
|
name: None,
|
||||||
children: [],
|
children: [],
|
||||||
split_size: None,
|
split_size: None,
|
||||||
run: None,
|
run: Some(
|
||||||
|
Cwd(
|
||||||
|
".",
|
||||||
|
),
|
||||||
|
),
|
||||||
borderless: false,
|
borderless: false,
|
||||||
focus: None,
|
focus: None,
|
||||||
external_children_index: None,
|
external_children_index: None,
|
||||||
|
|
|
||||||
|
|
@ -228,7 +228,10 @@ pub enum Action {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Action {
|
impl Action {
|
||||||
pub fn actions_from_cli(cli_action: CliAction) -> Result<Vec<Action>, String> {
|
pub fn actions_from_cli(
|
||||||
|
cli_action: CliAction,
|
||||||
|
get_current_dir: Box<dyn Fn() -> PathBuf>,
|
||||||
|
) -> Result<Vec<Action>, String> {
|
||||||
match cli_action {
|
match cli_action {
|
||||||
CliAction::Write { bytes } => Ok(vec![Action::Write(bytes)]),
|
CliAction::Write { bytes } => Ok(vec![Action::Write(bytes)]),
|
||||||
CliAction::WriteChars { chars } => Ok(vec![Action::WriteChars(chars)]),
|
CliAction::WriteChars { chars } => Ok(vec![Action::WriteChars(chars)]),
|
||||||
|
|
@ -265,7 +268,10 @@ impl Action {
|
||||||
if !command.is_empty() {
|
if !command.is_empty() {
|
||||||
let mut command = command.clone();
|
let mut command = command.clone();
|
||||||
let (command, args) = (PathBuf::from(command.remove(0)), command);
|
let (command, args) = (PathBuf::from(command.remove(0)), command);
|
||||||
let cwd = cwd.or_else(|| std::env::current_dir().ok());
|
let current_dir = get_current_dir();
|
||||||
|
let cwd = cwd
|
||||||
|
.map(|cwd| current_dir.join(cwd))
|
||||||
|
.or_else(|| Some(current_dir));
|
||||||
let hold_on_start = start_suspended;
|
let hold_on_start = start_suspended;
|
||||||
let hold_on_close = !close_on_exit;
|
let hold_on_close = !close_on_exit;
|
||||||
let run_command_action = RunCommandAction {
|
let run_command_action = RunCommandAction {
|
||||||
|
|
@ -304,7 +310,10 @@ impl Action {
|
||||||
cwd,
|
cwd,
|
||||||
} => {
|
} => {
|
||||||
let mut file = file;
|
let mut file = file;
|
||||||
let cwd = cwd.or_else(|| std::env::current_dir().ok());
|
let current_dir = get_current_dir();
|
||||||
|
let cwd = cwd
|
||||||
|
.map(|cwd| current_dir.join(cwd))
|
||||||
|
.or_else(|| Some(current_dir));
|
||||||
if file.is_relative() {
|
if file.is_relative() {
|
||||||
if let Some(cwd) = cwd {
|
if let Some(cwd) = cwd {
|
||||||
file = cwd.join(file);
|
file = cwd.join(file);
|
||||||
|
|
@ -338,6 +347,10 @@ impl Action {
|
||||||
]),
|
]),
|
||||||
CliAction::UndoRenameTab => Ok(vec![Action::UndoRenameTab]),
|
CliAction::UndoRenameTab => Ok(vec![Action::UndoRenameTab]),
|
||||||
CliAction::NewTab { name, layout, cwd } => {
|
CliAction::NewTab { name, layout, cwd } => {
|
||||||
|
let current_dir = get_current_dir();
|
||||||
|
let cwd = cwd
|
||||||
|
.map(|cwd| current_dir.join(cwd))
|
||||||
|
.or_else(|| Some(current_dir));
|
||||||
if let Some(layout_path) = layout {
|
if let Some(layout_path) = layout {
|
||||||
let (path_to_raw_layout, raw_layout) =
|
let (path_to_raw_layout, raw_layout) =
|
||||||
Layout::stringified_from_path_or_default(Some(&layout_path), None)
|
Layout::stringified_from_path_or_default(Some(&layout_path), None)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue