aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-utils
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2022-10-11 16:45:46 +0200
committerGitHub <noreply@github.com>2022-10-11 16:45:46 +0200
commitc64bf5207a0d1b79b305f11a3d73c9da77092b6e (patch)
tree2f5c0efc7c41bc10d96b398c9861d5c7903d2ba8 /zellij-utils
parentchangelog: Add PR 1775 (diff)
downloadsl0ppij-c64bf5207a0d1b79b305f11a3d73c9da77092b6e.tar.gz
sl0ppij-c64bf5207a0d1b79b305f11a3d73c9da77092b6e.tar.xz
sl0ppij-c64bf5207a0d1b79b305f11a3d73c9da77092b6e.zip
feat(ux): rerun command pane (#1787)
* chore(config): default kdl keybindings config * tests * work * refactor(config): move stuff around * work * tab merge layout * work * work * layouts working * work * layout tests * work * work * feat(parsing): kdl layouts without config * refactor(kdl): move stuff around * work * tests(layout): add cases and fix bugs * work * fix(kdl): various bugs * chore(layouts): move all layouts to kdl * feat(kdl): shared keybidns * fix(layout): do not count fixed panes toward percentile * fix(keybinds): missing keybinds and actions * fix(config): adjust default tips * refactor(config): move stuff around * fix(tests): make e2e tests pass * fix(kdl): add verbose parsing errors * fix(kdl): focused tab * fix(layout): corret default_tab_template behavior * style(code): fix compile warnings * feat(cli): send actions through the cli * fix(cli): exit only when action is done * fix(cli): open embedded pane from floating pane * fix(cli): send actions to other sessions * feat(cli): command alias * feat(converter): convert old config * feat(converter): convert old layout and theme files * feat(kdl): pretty errors * feat(client): convert old YAML files on startup * fix: various bugs and styling issues * fix: e2e tests * fix(screen): propagate errors after merge * style(clippy): lower clippy level * fix(tests): own session_name variable * style(fmt): rustfmt * fix(cli): various action fixes * style(fmt): rustfmt * fix(themes): loading of theme files * style(fmt): rustfmt * fix(tests): theme fixtures * fix(layouts): better errors on unknown nodes * fix(kdl): clarify valid node terminator error * fix(e2e): adjust close tab test * fix(e2e): adjust close tab test again * style(code): cleanup some comments * get command panes not to exit on command exit * separate terminal pane_ids from raw_fds * render frame according to exit status * re-run command on enter and close pane on ctrl-c * proper error when command is not found * make ui nicer * initial pane title for command panes * fix pane override bug * reap terminal_ids from os_input_output on pane close * bool floating flag * some ui tweaks * fix tests * make rustfmt happy * e2e test for command pane * fix various concurrency issues * rename command to run in the cli * rustfmt * style(fmt): rustfmt * fix(e2e): command => run * fix(e2e): command => run in snapshot too!
Diffstat (limited to 'zellij-utils')
-rw-r--r--zellij-utils/src/cli.rs26
-rw-r--r--zellij-utils/src/errors.rs2
-rw-r--r--zellij-utils/src/input/actions.rs22
-rw-r--r--zellij-utils/src/input/command.rs21
-rw-r--r--zellij-utils/src/input/unit/layout_test.rs3
-rw-r--r--zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__layout_with_tab_and_pane_templates.snap3
-rw-r--r--zellij-utils/src/kdl/kdl_layout_parser.rs1
-rw-r--r--zellij-utils/src/kdl/mod.rs10
-rw-r--r--zellij-utils/src/shared.rs2
9 files changed, 64 insertions, 26 deletions
diff --git a/zellij-utils/src/cli.rs b/zellij-utils/src/cli.rs
index 24616bd1..bef1afb3 100644
--- a/zellij-utils/src/cli.rs
+++ b/zellij-utils/src/cli.rs
@@ -124,18 +124,18 @@ pub enum Sessions {
#[clap(visible_alias = "ac")]
#[clap(subcommand)]
Action(CliAction),
- /// Send actions to a specific session
- #[clap(visible_alias = "c")]
- Command {
+ /// Run a command in a new pane
+ #[clap(visible_alias = "r")]
+ Run {
command: Option<String>,
#[clap(short, long, value_parser, conflicts_with("floating"))]
direction: Option<Direction>,
#[clap(long, value_parser)]
cwd: Option<PathBuf>,
- #[clap(short, long, value_parser, default_missing_value("true"))]
- floating: Option<bool>,
+ #[clap(short, long, value_parser, default_value("false"), takes_value(false))]
+ floating: bool,
},
- /// Edit file with default $EDITOR / $VISUAL in a specific session
+ /// Edit file with default $EDITOR / $VISUAL
#[clap(visible_alias = "e")]
Edit {
file: PathBuf,
@@ -143,8 +143,8 @@ pub enum Sessions {
line_number: Option<usize>,
#[clap(short, long, value_parser, conflicts_with("floating"))]
direction: Option<Direction>,
- #[clap(short, long, value_parser, default_missing_value("true"))]
- floating: Option<bool>,
+ #[clap(short, long, value_parser, default_value("false"), takes_value(false))]
+ floating: bool,
},
ConvertConfig {
old_config_file: PathBuf,
@@ -201,7 +201,7 @@ pub enum CliAction {
TogglePaneFrames,
/// Toggle between sending text commands to all panes on the current tab and normal mode.
ToggleActiveSyncTab,
- /// Open a new pane in the specified direction [right|left|up|down]
+ /// Open a new pane in the specified direction [right|down]
/// If no direction is specified, will try to use the biggest available space.
NewPane {
#[clap(short, long, value_parser, conflicts_with("floating"))]
@@ -210,8 +210,8 @@ pub enum CliAction {
command: Option<String>,
#[clap(long, value_parser)]
cwd: Option<PathBuf>,
- #[clap(short, long, value_parser, default_missing_value("true"))]
- floating: Option<bool>,
+ #[clap(short, long, value_parser, default_value("false"), takes_value(false))]
+ floating: bool,
},
/// Open the specified file in a new zellij pane with your default EDITOR
Edit {
@@ -220,8 +220,8 @@ pub enum CliAction {
direction: Option<Direction>,
#[clap(short, long, value_parser)]
line_number: Option<usize>,
- #[clap(short, long, value_parser, default_missing_value("true"))]
- floating: Option<bool>,
+ #[clap(short, long, value_parser, default_value("false"), takes_value(false))]
+ floating: bool,
},
/// Switch input mode of all connected clients [locked|pane|tab|resize|move|search|session]
SwitchMode { input_mode: InputMode },
diff --git a/zellij-utils/src/errors.rs b/zellij-utils/src/errors.rs
index 5e961888..5c872741 100644
--- a/zellij-utils/src/errors.rs
+++ b/zellij-utils/src/errors.rs
@@ -273,6 +273,7 @@ pub enum ScreenContext {
SetFixedHeight,
SetFixedWidth,
ClosePane,
+ HoldPane,
UpdatePaneName,
UndoRenamePane,
NewTab,
@@ -326,6 +327,7 @@ pub enum PtyContext {
NewTab,
ClosePane,
CloseTab,
+ ReRunCommandInPane,
Exit,
}
diff --git a/zellij-utils/src/input/actions.rs b/zellij-utils/src/input/actions.rs
index 8dacdc65..de1350dd 100644
--- a/zellij-utils/src/input/actions.rs
+++ b/zellij-utils/src/input/actions.rs
@@ -200,7 +200,7 @@ pub enum Action {
/// If no direction is specified, will try to use the biggest available space.
NewPane(Option<Direction>),
/// Open the file in a new pane using the default editor
- EditFile(PathBuf, Option<usize>, Option<Direction>, Option<bool>), // usize is an optional line number, bool is floating true/false
+ EditFile(PathBuf, Option<usize>, Option<Direction>, bool), // usize is an optional line number, bool is floating true/false
/// Open a new floating pane
NewFloatingPane(Option<RunCommandAction>),
/// Open a new tiled (embedded, non-floating) pane
@@ -288,23 +288,29 @@ impl Action {
} => match command {
Some(command) => {
let (command, args) = split_command_and_args(command);
+ let cwd = cwd.or_else(|| std::env::current_dir().ok());
let run_command_action = RunCommandAction {
command,
args,
cwd,
direction,
+ hold_on_close: true,
};
- match floating {
- Some(true) => Ok(vec![Action::NewFloatingPane(Some(run_command_action))]),
- _ => Ok(vec![Action::NewTiledPane(
+ if floating {
+ Ok(vec![Action::NewFloatingPane(Some(run_command_action))])
+ } else {
+ Ok(vec![Action::NewTiledPane(
direction,
Some(run_command_action),
- )]),
+ )])
}
},
- None => match floating {
- Some(true) => Ok(vec![Action::NewFloatingPane(None)]),
- _ => Ok(vec![Action::NewTiledPane(direction, None)]),
+ None => {
+ if floating {
+ Ok(vec![Action::NewFloatingPane(None)])
+ } else {
+ Ok(vec![Action::NewTiledPane(direction, None)])
+ }
},
},
CliAction::Edit {
diff --git a/zellij-utils/src/input/command.rs b/zellij-utils/src/input/command.rs
index 6f093a4a..abb7c1e7 100644
--- a/zellij-utils/src/input/command.rs
+++ b/zellij-utils/src/input/command.rs
@@ -17,6 +17,24 @@ pub struct RunCommand {
pub args: Vec<String>,
#[serde(default)]
pub cwd: Option<PathBuf>,
+ #[serde(default)]
+ pub hold_on_close: bool,
+}
+
+impl std::fmt::Display for RunCommand {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ let mut command: String = self
+ .command
+ .as_path()
+ .as_os_str()
+ .to_string_lossy()
+ .to_string();
+ for arg in &self.args {
+ command.push(' ');
+ command.push_str(arg);
+ }
+ write!(f, "{}", command)
+ }
}
/// Intermediate representation
@@ -30,6 +48,8 @@ pub struct RunCommandAction {
pub cwd: Option<PathBuf>,
#[serde(default)]
pub direction: Option<Direction>,
+ #[serde(default)]
+ pub hold_on_close: bool,
}
impl From<RunCommandAction> for RunCommand {
@@ -38,6 +58,7 @@ impl From<RunCommandAction> for RunCommand {
command: action.command,
args: action.args,
cwd: action.cwd,
+ hold_on_close: action.hold_on_close,
}
}
}
diff --git a/zellij-utils/src/input/unit/layout_test.rs b/zellij-utils/src/input/unit/layout_test.rs
index b4b309ba..ffd35f20 100644
--- a/zellij-utils/src/input/unit/layout_test.rs
+++ b/zellij-utils/src/input/unit/layout_test.rs
@@ -201,6 +201,7 @@ fn layout_with_command_panes() {
children: vec![PaneLayout {
run: Some(Run::Command(RunCommand {
command: PathBuf::from("htop"),
+ hold_on_close: true,
..Default::default()
})),
..Default::default()
@@ -226,6 +227,7 @@ fn layout_with_command_panes_and_cwd() {
run: Some(Run::Command(RunCommand {
command: PathBuf::from("htop"),
cwd: Some(PathBuf::from("/path/to/my/cwd")),
+ hold_on_close: true,
..Default::default()
})),
..Default::default()
@@ -254,6 +256,7 @@ fn layout_with_command_panes_and_cwd_and_args() {
command: PathBuf::from("htop"),
cwd: Some(PathBuf::from("/path/to/my/cwd")),
args: vec![String::from("-h"), String::from("-v")],
+ hold_on_close: true,
..Default::default()
})),
..Default::default()
diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__layout_with_tab_and_pane_templates.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__layout_with_tab_and_pane_templates.snap
index 72101338..f32b346d 100644
--- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__layout_with_tab_and_pane_templates.snap
+++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__layout_with_tab_and_pane_templates.snap
@@ -1,6 +1,6 @@
---
source: zellij-utils/src/input/./unit/layout_test.rs
-assertion_line: 648
+assertion_line: 570
expression: "format!(\"{:#?}\", layout)"
---
Layout {
@@ -40,6 +40,7 @@ Layout {
command: "htop",
args: [],
cwd: None,
+ hold_on_close: true,
},
),
),
diff --git a/zellij-utils/src/kdl/kdl_layout_parser.rs b/zellij-utils/src/kdl/kdl_layout_parser.rs
index 4bf3aea6..f572c356 100644
--- a/zellij-utils/src/kdl/kdl_layout_parser.rs
+++ b/zellij-utils/src/kdl/kdl_layout_parser.rs
@@ -177,6 +177,7 @@ impl<'a> KdlLayoutParser<'a> {
command,
args: args.unwrap_or_else(|| vec![]),
cwd,
+ hold_on_close: true,
}))),
_ => Ok(None),
}
diff --git a/zellij-utils/src/kdl/mod.rs b/zellij-utils/src/kdl/mod.rs
index 7092653c..b8d76c7b 100644
--- a/zellij-utils/src/kdl/mod.rs
+++ b/zellij-utils/src/kdl/mod.rs
@@ -590,12 +590,10 @@ impl TryFrom<(&str, &KdlDocument)> for PaletteColor {
}
impl TryFrom<&KdlNode> for Action {
- // type Error = Box<dyn std::error::Error>;
type Error = ConfigError;
fn try_from(kdl_action: &KdlNode) -> Result<Self, Self::Error> {
let action_name = kdl_name!(kdl_action);
let action_arguments: Vec<&KdlEntry> = kdl_argument_values!(kdl_action);
- // let action_arguments: Vec<&KdlValue> = kdl_argument_values!(kdl_action);
let action_children: Vec<&KdlDocument> = kdl_children!(kdl_action);
match action_name {
"Quit" => parse_kdl_action_arguments!(action_name, action_arguments, kdl_action),
@@ -744,6 +742,7 @@ impl TryFrom<&KdlNode> for Action {
args,
cwd,
direction,
+ hold_on_close: true,
};
Ok(Action::Run(run_command_action))
},
@@ -1473,7 +1472,12 @@ impl RunCommand {
.collect(),
None => vec![],
};
- Ok(RunCommand { command, args, cwd })
+ Ok(RunCommand {
+ command,
+ args,
+ cwd,
+ hold_on_close: true,
+ })
}
}
diff --git a/zellij-utils/src/shared.rs b/zellij-utils/src/shared.rs
index 37d999d1..f89acaf5 100644
--- a/zellij-utils/src/shared.rs
+++ b/zellij-utils/src/shared.rs
@@ -62,7 +62,7 @@ pub mod colors {
pub const GREEN: u8 = 154;
pub const GRAY: u8 = 238;
pub const BRIGHT_GRAY: u8 = 245;
- pub const RED: u8 = 88;
+ pub const RED: u8 = 124;
pub const ORANGE: u8 = 166;
pub const BLACK: u8 = 16;
pub const MAGENTA: u8 = 201;