Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add running commands to an action #596

Merged
merged 1 commit into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions zellij-server/src/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use zellij_utils::{
channels::SenderWithContext,
input::{
actions::{Action, Direction},
command::TerminalAction,
get_mode_info,
},
ipc::{ClientToServerMsg, ExitReason, ServerToClientMsg},
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions zellij-utils/src/input/actions.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -65,6 +66,8 @@ pub enum Action {
CloseTab,
GoToTab(u32),
TabNameInput(Vec<u8>),
/// Run speficied command in new pane.
Run(RunCommandAction),
/// Detach session and exit
Detach,
}
22 changes: 21 additions & 1 deletion zellij-utils/src/input/command.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Trigger a command
use super::actions::Direction;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;

Expand All @@ -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<String>,
}

/// Intermediate representation
#[derive(Clone, Debug, Deserialize, Default, Serialize, PartialEq, Eq)]
pub struct RunCommandAction {
pub command: PathBuf,
#[serde(default)]
pub args: Vec<String>,
#[serde(default)]
pub direction: Option<Direction>,
}

impl From<RunCommandAction> for RunCommand {
fn from(action: RunCommandAction) -> Self {
RunCommand {
command: action.command,
args: action.args,
}
}
}