* feat: add capability to dispatch actions from cli Add capability to dispatch actions from the cli. Can be invoked through `zellij action [actions]` Automatically sends the action either to the current session, or if there is only one session to the single session. If there are multiple sessions, and no session is specified it will error out. Example: 1. ``` zellij action "[NewTab: , NewTab: ]" ``` 2. ``` zellij -s fluffy-cat action '[NewPane: , WriteChars: "echo Purrr\n" ]' ``` 3. ``` zellij -s fluffy-cat action '[ CloseTab, ] ``` * add: error message on malformed input Add an error message on malformed input, for the `action`'s dispatch. Rather than resulting in a panic. * add: function to query the client id * add: send specific actions to certain clients Adds ability to send actions, that don't impact the server state to all connected clients. For example `MoveFocus` * add: client_id to non blocking actions * chore(fmt): `cargo fmt` * add: pick correct session, if there is exactly one * add: use correct `client_id` for detach action * add: make `[ ]` opaque to the user * add: miette to toplevel to improve error message * add: fake client reading configuration Add the fake client reading configuration files, this allows actions, that rely on configuration work correctly. This is an intermediate solution, and should ideally not be needed. It would be better if most of this state would be handled by the server itself. * chore(fmt): rustmt * add: ability to detach multiple clients Add ability to detach multiple clients at the same time. * remove: obsolete functionality * remove: unused functionality * add: send correct action upon exiting * chore(update): cargo update
141 lines
4.1 KiB
Rust
141 lines
4.1 KiB
Rust
//! Definition of the actions that can be bound to keys.
|
|
|
|
use super::command::RunCommandAction;
|
|
use super::layout::TabLayout;
|
|
use crate::input::options::OnForceClose;
|
|
use serde::{Deserialize, Serialize};
|
|
use zellij_tile::data::InputMode;
|
|
|
|
use crate::position::Position;
|
|
|
|
/// The four directions (left, right, up, down).
|
|
#[derive(Eq, Clone, Debug, PartialEq, Deserialize, Serialize)]
|
|
pub enum Direction {
|
|
Left,
|
|
Right,
|
|
Up,
|
|
Down,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
|
pub enum ResizeDirection {
|
|
Left,
|
|
Right,
|
|
Up,
|
|
Down,
|
|
Increase,
|
|
Decrease,
|
|
}
|
|
|
|
// As these actions are bound to the default config, please
|
|
// do take care when refactoring - or renaming.
|
|
// They might need to be adjusted in the default config
|
|
// as well `../../assets/config/default.yaml`
|
|
/// Actions that can be bound to keys.
|
|
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
|
pub enum Action {
|
|
/// Quit Zellij.
|
|
Quit,
|
|
/// Write to the terminal.
|
|
Write(Vec<u8>),
|
|
/// Write Characters to the terminal.
|
|
WriteChars(String),
|
|
/// Switch to the specified input mode.
|
|
SwitchToMode(InputMode),
|
|
/// Resize focus pane in specified direction.
|
|
Resize(ResizeDirection),
|
|
/// Switch focus to next pane in specified direction.
|
|
FocusNextPane,
|
|
FocusPreviousPane,
|
|
/// Move the focus pane in specified direction.
|
|
SwitchFocus,
|
|
MoveFocus(Direction),
|
|
/// Tries to move the focus pane in specified direction.
|
|
/// If there is no pane in the direction, move to previous/next Tab.
|
|
MoveFocusOrTab(Direction),
|
|
MovePane(Option<Direction>),
|
|
/// Dumps the screen to a file
|
|
DumpScreen(String),
|
|
/// Scroll up in focus pane.
|
|
EditScrollback,
|
|
ScrollUp,
|
|
/// Scroll up at point
|
|
ScrollUpAt(Position),
|
|
/// Scroll down in focus pane.
|
|
ScrollDown,
|
|
/// Scroll down at point
|
|
ScrollDownAt(Position),
|
|
/// Scroll down to bottom in focus pane.
|
|
ScrollToBottom,
|
|
/// Scroll up one page in focus pane.
|
|
PageScrollUp,
|
|
/// Scroll down one page in focus pane.
|
|
PageScrollDown,
|
|
/// Scroll up half page in focus pane.
|
|
HalfPageScrollUp,
|
|
/// Scroll down half page in focus pane.
|
|
HalfPageScrollDown,
|
|
/// Toggle between fullscreen focus pane and normal layout.
|
|
ToggleFocusFullscreen,
|
|
/// Toggle frames around panes in the UI
|
|
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 (relative to focus).
|
|
/// If no direction is specified, will try to use the biggest available space.
|
|
NewPane(Option<Direction>),
|
|
/// Embed focused pane in tab if floating or float focused pane if embedded
|
|
TogglePaneEmbedOrFloating,
|
|
/// Toggle the visibility of all floating panes (if any) in the current Tab
|
|
ToggleFloatingPanes,
|
|
/// Close the focus pane.
|
|
CloseFocus,
|
|
PaneNameInput(Vec<u8>),
|
|
/// Create a new tab, optionally with a specified tab layout.
|
|
NewTab(Option<TabLayout>),
|
|
/// Do nothing.
|
|
NoOp,
|
|
/// Go to the next tab.
|
|
GoToNextTab,
|
|
/// Go to the previous tab.
|
|
GoToPreviousTab,
|
|
/// Close the current tab.
|
|
CloseTab,
|
|
GoToTab(u32),
|
|
ToggleTab,
|
|
TabNameInput(Vec<u8>),
|
|
/// Run specified command in new pane.
|
|
Run(RunCommandAction),
|
|
/// Detach session and exit
|
|
Detach,
|
|
LeftClick(Position),
|
|
RightClick(Position),
|
|
MouseRelease(Position),
|
|
MouseHold(Position),
|
|
Copy,
|
|
/// Confirm a prompt
|
|
Confirm,
|
|
/// Deny a prompt
|
|
Deny,
|
|
/// Confirm an action that invokes a prompt automatically
|
|
SkipConfirm(Box<Action>),
|
|
}
|
|
|
|
impl From<OnForceClose> for Action {
|
|
fn from(ofc: OnForceClose) -> Action {
|
|
match ofc {
|
|
OnForceClose::Quit => Action::Quit,
|
|
OnForceClose::Detach => Action::Detach,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
|
pub struct ActionsFromYaml(Vec<Action>);
|
|
|
|
impl ActionsFromYaml {
|
|
/// Get a reference to the actions from yaml's actions.
|
|
pub fn actions(&self) -> &[Action] {
|
|
self.0.as_ref()
|
|
}
|
|
}
|