diff --git a/zellij-server/src/route.rs b/zellij-server/src/route.rs index 285f333c..1a559d08 100644 --- a/zellij-server/src/route.rs +++ b/zellij-server/src/route.rs @@ -10,6 +10,7 @@ use zellij_utils::{ channels::SenderWithContext, input::{ actions::{Action, Direction}, + command::TerminalAction, get_mode_info, }, ipc::{ClientToServerMsg, ExitReason, ServerToClientMsg}, @@ -143,6 +144,18 @@ fn route_action( }; session.senders.send_to_pty(pty_instr).unwrap(); } + Action::Run(command) => { + let run_cmd = Some(TerminalAction::RunCommand(command.clone().into())); + let pty_instr = match command.direction { + Some(Direction::Left) => PtyInstruction::SpawnTerminalVertically(run_cmd), + Some(Direction::Right) => PtyInstruction::SpawnTerminalVertically(run_cmd), + Some(Direction::Up) => PtyInstruction::SpawnTerminalHorizontally(run_cmd), + Some(Direction::Down) => PtyInstruction::SpawnTerminalHorizontally(run_cmd), + // No direction specified - try to put it in the biggest available spot + None => PtyInstruction::SpawnTerminal(run_cmd), + }; + session.senders.send_to_pty(pty_instr).unwrap(); + } Action::CloseFocus => { session .senders diff --git a/zellij-utils/src/input/actions.rs b/zellij-utils/src/input/actions.rs index 615df3c4..36fd93b1 100644 --- a/zellij-utils/src/input/actions.rs +++ b/zellij-utils/src/input/actions.rs @@ -1,5 +1,6 @@ //! Definition of the actions that can be bound to keys. +use super::command::RunCommandAction; use serde::{Deserialize, Serialize}; use zellij_tile::data::InputMode; @@ -65,6 +66,8 @@ pub enum Action { CloseTab, GoToTab(u32), TabNameInput(Vec), + /// Run speficied command in new pane. + Run(RunCommandAction), /// Detach session and exit Detach, } diff --git a/zellij-utils/src/input/command.rs b/zellij-utils/src/input/command.rs index 79bbe5ab..ca505ea2 100644 --- a/zellij-utils/src/input/command.rs +++ b/zellij-utils/src/input/command.rs @@ -1,4 +1,5 @@ //! Trigger a command +use super::actions::Direction; use serde::{Deserialize, Serialize}; use std::path::PathBuf; @@ -8,9 +9,28 @@ pub enum TerminalAction { RunCommand(RunCommand), } -#[derive(Clone, Debug, Deserialize, Default, Serialize, PartialEq)] +#[derive(Clone, Debug, Deserialize, Default, Serialize, PartialEq, Eq)] pub struct RunCommand { pub command: PathBuf, #[serde(default)] pub args: Vec, } + +/// Intermediate representation +#[derive(Clone, Debug, Deserialize, Default, Serialize, PartialEq, Eq)] +pub struct RunCommandAction { + pub command: PathBuf, + #[serde(default)] + pub args: Vec, + #[serde(default)] + pub direction: Option, +} + +impl From for RunCommand { + fn from(action: RunCommandAction) -> Self { + RunCommand { + command: action.command, + args: action.args, + } + } +}