Extends the pane selector to allow:
```
wezterm --config 'keys={{key="p", mods="CTRL", action=wezterm.action{PaneSelect={mode="SwapWithActive"}}}}'
```
to swap the active pane with the selected pane.
Similar to https://wezfurlong.org/wezterm/config/lua/keyassignment/RotatePanes.html
except that only the active and the selected panes have their positions
adjusted.
refs: https://github.com/wez/wezterm/issues/1842
refs: https://github.com/wez/wezterm/issues/1975
474 lines
12 KiB
Rust
474 lines
12 KiB
Rust
use crate::keys::KeyNoAction;
|
|
use luahelper::impl_lua_conversion_dynamic;
|
|
use ordered_float::NotNan;
|
|
use serde::{Deserialize, Serialize};
|
|
use std::collections::HashMap;
|
|
use std::convert::TryFrom;
|
|
use std::path::PathBuf;
|
|
use wezterm_dynamic::{FromDynamic, ToDynamic};
|
|
use wezterm_input_types::{KeyCode, Modifiers};
|
|
use wezterm_term::input::MouseButton;
|
|
|
|
#[derive(Default, Debug, Clone, FromDynamic, ToDynamic, PartialEq, Eq)]
|
|
pub struct LauncherActionArgs {
|
|
pub flags: LauncherFlags,
|
|
pub title: Option<String>,
|
|
}
|
|
|
|
bitflags::bitflags! {
|
|
#[derive(Default, FromDynamic, ToDynamic)]
|
|
#[dynamic(try_from="String", into="String")]
|
|
pub struct LauncherFlags :u32 {
|
|
const ZERO = 0;
|
|
const FUZZY = 1;
|
|
const TABS = 2;
|
|
const LAUNCH_MENU_ITEMS = 4;
|
|
const DOMAINS = 8;
|
|
const KEY_ASSIGNMENTS = 16;
|
|
const WORKSPACES = 32;
|
|
const COMMANDS = 64;
|
|
}
|
|
}
|
|
|
|
impl Into<String> for LauncherFlags {
|
|
fn into(self) -> String {
|
|
self.to_string()
|
|
}
|
|
}
|
|
|
|
impl Into<String> for &LauncherFlags {
|
|
fn into(self) -> String {
|
|
self.to_string()
|
|
}
|
|
}
|
|
|
|
impl ToString for LauncherFlags {
|
|
fn to_string(&self) -> String {
|
|
let mut s = vec![];
|
|
if self.contains(Self::FUZZY) {
|
|
s.push("FUZZY");
|
|
}
|
|
if self.contains(Self::TABS) {
|
|
s.push("TABS");
|
|
}
|
|
if self.contains(Self::LAUNCH_MENU_ITEMS) {
|
|
s.push("LAUNCH_MENU_ITEMS");
|
|
}
|
|
if self.contains(Self::DOMAINS) {
|
|
s.push("DOMAINS");
|
|
}
|
|
if self.contains(Self::KEY_ASSIGNMENTS) {
|
|
s.push("KEY_ASSIGNMENTS");
|
|
}
|
|
if self.contains(Self::WORKSPACES) {
|
|
s.push("WORKSPACES");
|
|
}
|
|
if self.contains(Self::COMMANDS) {
|
|
s.push("COMMANDS");
|
|
}
|
|
s.join("|")
|
|
}
|
|
}
|
|
|
|
impl TryFrom<String> for LauncherFlags {
|
|
type Error = String;
|
|
fn try_from(s: String) -> Result<Self, String> {
|
|
let mut flags = LauncherFlags::default();
|
|
|
|
for ele in s.split('|') {
|
|
let ele = ele.trim();
|
|
match ele {
|
|
"FUZZY" => flags |= Self::FUZZY,
|
|
"TABS" => flags |= Self::TABS,
|
|
"LAUNCH_MENU_ITEMS" => flags |= Self::LAUNCH_MENU_ITEMS,
|
|
"DOMAINS" => flags |= Self::DOMAINS,
|
|
"KEY_ASSIGNMENTS" => flags |= Self::KEY_ASSIGNMENTS,
|
|
"WORKSPACES" => flags |= Self::WORKSPACES,
|
|
"COMMANDS" => flags |= Self::COMMANDS,
|
|
_ => {
|
|
return Err(format!("invalid LauncherFlags `{}` in `{}`", ele, s));
|
|
}
|
|
}
|
|
}
|
|
|
|
Ok(flags)
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Copy, Clone, Eq, PartialEq, FromDynamic, ToDynamic)]
|
|
pub enum SelectionMode {
|
|
Cell,
|
|
Word,
|
|
Line,
|
|
SemanticZone,
|
|
Block,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, FromDynamic, ToDynamic)]
|
|
pub enum Pattern {
|
|
CaseSensitiveString(String),
|
|
CaseInSensitiveString(String),
|
|
Regex(String),
|
|
CurrentSelectionOrEmptyString,
|
|
}
|
|
|
|
impl Pattern {
|
|
pub fn is_empty(&self) -> bool {
|
|
match self {
|
|
Self::CaseSensitiveString(s) | Self::CaseInSensitiveString(s) | Self::Regex(s) => {
|
|
s.is_empty()
|
|
}
|
|
Self::CurrentSelectionOrEmptyString => true,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Default for Pattern {
|
|
fn default() -> Self {
|
|
Self::CurrentSelectionOrEmptyString
|
|
}
|
|
}
|
|
|
|
/// A mouse event that can trigger an action
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash, FromDynamic, ToDynamic)]
|
|
pub enum MouseEventTrigger {
|
|
/// Mouse button is pressed. streak is how many times in a row
|
|
/// it was pressed.
|
|
Down { streak: usize, button: MouseButton },
|
|
/// Mouse button is held down while the cursor is moving. streak is how many times in a row
|
|
/// it was pressed, with the last of those being held to form the drag.
|
|
Drag { streak: usize, button: MouseButton },
|
|
/// Mouse button is being released. streak is how many times
|
|
/// in a row it was pressed and released.
|
|
Up { streak: usize, button: MouseButton },
|
|
}
|
|
|
|
/// When spawning a tab, specify which domain should be used to
|
|
/// host/spawn that tab.
|
|
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, FromDynamic, ToDynamic)]
|
|
pub enum SpawnTabDomain {
|
|
/// Use the default domain
|
|
DefaultDomain,
|
|
/// Use the domain from the current tab in the associated window
|
|
CurrentPaneDomain,
|
|
/// Use a specific domain by name
|
|
DomainName(String),
|
|
/// Use a specific domain by id
|
|
DomainId(usize),
|
|
}
|
|
|
|
impl Default for SpawnTabDomain {
|
|
fn default() -> Self {
|
|
Self::CurrentPaneDomain
|
|
}
|
|
}
|
|
|
|
#[derive(Default, Clone, PartialEq, Eq, FromDynamic, ToDynamic)]
|
|
pub struct SpawnCommand {
|
|
/// Optional descriptive label
|
|
pub label: Option<String>,
|
|
|
|
/// The command line to use.
|
|
/// If omitted, the default command associated with the
|
|
/// domain will be used instead, which is typically the
|
|
/// shell for the user.
|
|
pub args: Option<Vec<String>>,
|
|
|
|
/// Specifies the current working directory for the command.
|
|
/// If omitted, a default will be used; typically that will
|
|
/// be the home directory of the user, but may also be the
|
|
/// current working directory of the wezterm process when
|
|
/// it was launched, or for some domains it may be some
|
|
/// other location appropriate to the domain.
|
|
pub cwd: Option<PathBuf>,
|
|
|
|
/// Specifies a map of environment variables that should be set.
|
|
/// Whether this is used depends on the domain.
|
|
#[dynamic(default)]
|
|
pub set_environment_variables: HashMap<String, String>,
|
|
|
|
#[dynamic(default)]
|
|
pub domain: SpawnTabDomain,
|
|
}
|
|
|
|
impl std::fmt::Debug for SpawnCommand {
|
|
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
write!(fmt, "{}", self)
|
|
}
|
|
}
|
|
|
|
impl std::fmt::Display for SpawnCommand {
|
|
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
write!(fmt, "SpawnCommand")?;
|
|
if let Some(label) = &self.label {
|
|
write!(fmt, " label='{}'", label)?;
|
|
}
|
|
write!(fmt, " domain={:?}", self.domain)?;
|
|
if let Some(args) = &self.args {
|
|
write!(fmt, " args={:?}", args)?;
|
|
}
|
|
if let Some(cwd) = &self.cwd {
|
|
write!(fmt, " cwd={}", cwd.display())?;
|
|
}
|
|
for (k, v) in &self.set_environment_variables {
|
|
write!(fmt, " {}={}", k, v)?;
|
|
}
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromDynamic, ToDynamic)]
|
|
pub enum PaneDirection {
|
|
Up,
|
|
Down,
|
|
Left,
|
|
Right,
|
|
Next,
|
|
Prev,
|
|
}
|
|
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, FromDynamic, ToDynamic)]
|
|
pub enum ScrollbackEraseMode {
|
|
ScrollbackOnly,
|
|
ScrollbackAndViewport,
|
|
}
|
|
|
|
impl Default for ScrollbackEraseMode {
|
|
fn default() -> Self {
|
|
Self::ScrollbackOnly
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromDynamic, ToDynamic)]
|
|
pub enum ClipboardCopyDestination {
|
|
Clipboard,
|
|
PrimarySelection,
|
|
ClipboardAndPrimarySelection,
|
|
}
|
|
|
|
impl Default for ClipboardCopyDestination {
|
|
fn default() -> Self {
|
|
Self::ClipboardAndPrimarySelection
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromDynamic, ToDynamic)]
|
|
pub enum ClipboardPasteSource {
|
|
Clipboard,
|
|
PrimarySelection,
|
|
}
|
|
|
|
impl Default for ClipboardPasteSource {
|
|
fn default() -> Self {
|
|
Self::Clipboard
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromDynamic, ToDynamic)]
|
|
pub enum PaneSelectMode {
|
|
Activate,
|
|
SwapWithActive,
|
|
}
|
|
|
|
impl Default for PaneSelectMode {
|
|
fn default() -> Self {
|
|
Self::Activate
|
|
}
|
|
}
|
|
|
|
#[derive(Default, Debug, Clone, PartialEq, Eq, FromDynamic, ToDynamic)]
|
|
pub struct PaneSelectArguments {
|
|
/// Overrides the main quick_select_alphabet config
|
|
#[dynamic(default)]
|
|
pub alphabet: String,
|
|
|
|
#[dynamic(default)]
|
|
pub mode: PaneSelectMode,
|
|
}
|
|
|
|
#[derive(Default, Debug, Clone, PartialEq, Eq, FromDynamic, ToDynamic)]
|
|
pub struct QuickSelectArguments {
|
|
/// Overrides the main quick_select_alphabet config
|
|
#[dynamic(default)]
|
|
pub alphabet: String,
|
|
/// Overrides the main quick_select_patterns config
|
|
#[dynamic(default)]
|
|
pub patterns: Vec<String>,
|
|
#[dynamic(default)]
|
|
pub action: Option<Box<KeyAssignment>>,
|
|
/// Label to use in place of "copy" when `action` is set
|
|
#[dynamic(default)]
|
|
pub label: String,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, FromDynamic, ToDynamic)]
|
|
pub enum KeyAssignment {
|
|
SpawnTab(SpawnTabDomain),
|
|
SpawnWindow,
|
|
ToggleFullScreen,
|
|
Copy,
|
|
CopyTo(ClipboardCopyDestination),
|
|
Paste,
|
|
PastePrimarySelection,
|
|
PasteFrom(ClipboardPasteSource),
|
|
ActivateTabRelative(isize),
|
|
ActivateTabRelativeNoWrap(isize),
|
|
IncreaseFontSize,
|
|
DecreaseFontSize,
|
|
ResetFontSize,
|
|
ResetFontAndWindowSize,
|
|
ActivateTab(isize),
|
|
ActivateLastTab,
|
|
SendString(String),
|
|
SendKey(KeyNoAction),
|
|
Nop,
|
|
DisableDefaultAssignment,
|
|
Hide,
|
|
Show,
|
|
CloseCurrentTab {
|
|
confirm: bool,
|
|
},
|
|
ReloadConfiguration,
|
|
MoveTabRelative(isize),
|
|
MoveTab(usize),
|
|
ScrollByPage(NotNan<f64>),
|
|
ScrollByLine(isize),
|
|
ScrollToPrompt(isize),
|
|
ScrollToTop,
|
|
ScrollToBottom,
|
|
ShowTabNavigator,
|
|
ShowDebugOverlay,
|
|
HideApplication,
|
|
QuitApplication,
|
|
SpawnCommandInNewTab(SpawnCommand),
|
|
SpawnCommandInNewWindow(SpawnCommand),
|
|
SplitHorizontal(SpawnCommand),
|
|
SplitVertical(SpawnCommand),
|
|
ShowLauncher,
|
|
ShowLauncherArgs(LauncherActionArgs),
|
|
ClearScrollback(ScrollbackEraseMode),
|
|
Search(Pattern),
|
|
ActivateCopyMode,
|
|
|
|
SelectTextAtMouseCursor(SelectionMode),
|
|
ExtendSelectionToMouseCursor(Option<SelectionMode>),
|
|
OpenLinkAtMouseCursor,
|
|
ClearSelection,
|
|
CompleteSelection(ClipboardCopyDestination),
|
|
CompleteSelectionOrOpenLinkAtMouseCursor(ClipboardCopyDestination),
|
|
StartWindowDrag,
|
|
|
|
AdjustPaneSize(PaneDirection, usize),
|
|
ActivatePaneDirection(PaneDirection),
|
|
ActivatePaneByIndex(usize),
|
|
TogglePaneZoomState,
|
|
CloseCurrentPane {
|
|
confirm: bool,
|
|
},
|
|
EmitEvent(String),
|
|
QuickSelect,
|
|
QuickSelectArgs(QuickSelectArguments),
|
|
|
|
Multiple(Vec<KeyAssignment>),
|
|
|
|
SwitchToWorkspace {
|
|
name: Option<String>,
|
|
spawn: Option<SpawnCommand>,
|
|
},
|
|
SwitchWorkspaceRelative(isize),
|
|
|
|
ActivateKeyTable {
|
|
name: String,
|
|
#[dynamic(default)]
|
|
timeout_milliseconds: Option<u64>,
|
|
#[dynamic(default)]
|
|
replace_current: bool,
|
|
#[dynamic(default = "crate::default_true")]
|
|
one_shot: bool,
|
|
},
|
|
PopKeyTable,
|
|
ClearKeyTableStack,
|
|
DetachDomain(SpawnTabDomain),
|
|
AttachDomain(String),
|
|
|
|
CopyMode(CopyModeAssignment),
|
|
RotatePanes(RotationDirection),
|
|
SplitPane(SplitPane),
|
|
PaneSelect(PaneSelectArguments),
|
|
}
|
|
impl_lua_conversion_dynamic!(KeyAssignment);
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, FromDynamic, ToDynamic)]
|
|
pub struct SplitPane {
|
|
pub direction: PaneDirection,
|
|
#[dynamic(default)]
|
|
pub size: SplitSize,
|
|
#[dynamic(default)]
|
|
pub command: SpawnCommand,
|
|
#[dynamic(default)]
|
|
pub top_level: bool,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, FromDynamic, ToDynamic)]
|
|
pub enum SplitSize {
|
|
Cells(usize),
|
|
Percent(u8),
|
|
}
|
|
|
|
impl Default for SplitSize {
|
|
fn default() -> Self {
|
|
Self::Percent(50)
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, FromDynamic, ToDynamic)]
|
|
pub enum RotationDirection {
|
|
Clockwise,
|
|
CounterClockwise,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, FromDynamic, ToDynamic)]
|
|
pub enum CopyModeAssignment {
|
|
MoveToViewportBottom,
|
|
MoveToViewportTop,
|
|
MoveToViewportMiddle,
|
|
MoveToScrollbackTop,
|
|
MoveToScrollbackBottom,
|
|
ToggleSelectionByCell,
|
|
SetSelectionMode(Option<SelectionMode>),
|
|
MoveToStartOfLineContent,
|
|
MoveToEndOfLineContent,
|
|
MoveToStartOfLine,
|
|
MoveToStartOfNextLine,
|
|
MoveBackwardWord,
|
|
MoveForwardWord,
|
|
MoveRight,
|
|
MoveLeft,
|
|
MoveUp,
|
|
MoveDown,
|
|
PageUp,
|
|
PageDown,
|
|
Close,
|
|
PriorMatch,
|
|
NextMatch,
|
|
PriorMatchPage,
|
|
NextMatchPage,
|
|
CycleMatchType,
|
|
ClearPattern,
|
|
EditPattern,
|
|
AcceptPattern,
|
|
}
|
|
|
|
pub type KeyTable = HashMap<(KeyCode, Modifiers), KeyTableEntry>;
|
|
|
|
#[derive(Debug, Clone, Default)]
|
|
pub struct KeyTables {
|
|
pub default: KeyTable,
|
|
pub by_name: HashMap<String, KeyTable>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub struct KeyTableEntry {
|
|
pub action: KeyAssignment,
|
|
}
|