Expose activate-pane-direction cli command (#2526)
* Expose `activate-pane-direction` cli command Add a new subcommand for `wezterm cli` called `activate-pane-direction`. It allows switching the active pane in the current tab in the given direction. * Bump codec version * Replace boolean flags with a single direction arg * Run cargo fmt
This commit is contained in:
1 parent
cd9376d923
commit
36f47ec3f6
5 files changed
+66
-4
No files matched your search
+9
-1
@@ -12,6 +12,7 @@
|
||||
#![cfg_attr(feature = "cargo-clippy", allow(clippy::range_plus_one))]
|
||||
|
||||
use anyhow::{bail, Context as _, Error};
|
||||
use config::keyassignment::PaneDirection;
|
||||
use mux::client::{ClientId, ClientInfo};
|
||||
use mux::pane::PaneId;
|
||||
use mux::renderable::{RenderableDimensions, StableCursorPosition};
|
||||
@@ -416,7 +417,7 @@ macro_rules! pdu {
|
||||
/// The overall version of the codec.
|
||||
/// This must be bumped when backwards incompatible changes
|
||||
/// are made to the types and protocol.
|
||||
pub const CODEC_VERSION: usize = 30;
|
||||
pub const CODEC_VERSION: usize = 31;
|
||||
|
||||
// Defines the Pdu enum.
|
||||
// Each struct has an explicit identifying number.
|
||||
@@ -464,6 +465,7 @@ pdu! {
|
||||
GetImageCellResponse: 47,
|
||||
MovePaneToNewTab: 48,
|
||||
MovePaneToNewTabResponse: 49,
|
||||
ActivatePaneDirection: 50,
|
||||
}
|
||||
|
||||
impl Pdu {
|
||||
@@ -767,6 +769,12 @@ pub struct SetPaneZoomed {
|
||||
pub zoomed: bool,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, PartialEq, Debug)]
|
||||
pub struct ActivatePaneDirection {
|
||||
pub pane_id: PaneId,
|
||||
pub direction: PaneDirection,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, PartialEq, Debug)]
|
||||
pub struct GetPaneRenderChanges {
|
||||
pub pane_id: PaneId,
|
||||
|
||||
@@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryFrom;
|
||||
use std::path::PathBuf;
|
||||
use wezterm_dynamic::{FromDynamic, ToDynamic};
|
||||
use wezterm_dynamic::{FromDynamic, FromDynamicOptions, ToDynamic, Value};
|
||||
use wezterm_input_types::{KeyCode, Modifiers};
|
||||
use wezterm_term::input::MouseButton;
|
||||
use wezterm_term::SemanticType;
|
||||
@@ -249,7 +249,7 @@ impl SpawnCommand {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromDynamic, ToDynamic)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, FromDynamic, ToDynamic)]
|
||||
pub enum PaneDirection {
|
||||
Up,
|
||||
Down,
|
||||
@@ -259,6 +259,25 @@ pub enum PaneDirection {
|
||||
Prev,
|
||||
}
|
||||
|
||||
impl PaneDirection {
|
||||
pub fn direction_from_str(arg: &str) -> Result<PaneDirection, String> {
|
||||
for candidate in PaneDirection::variants() {
|
||||
if candidate.to_lowercase() == arg.to_lowercase() {
|
||||
if let Ok(direction) = PaneDirection::from_dynamic(
|
||||
&Value::String(candidate.to_string()),
|
||||
FromDynamicOptions::default(),
|
||||
) {
|
||||
return Ok(direction);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(format!(
|
||||
"invalid direction {arg}, possible values are {:?}",
|
||||
PaneDirection::variants()
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, FromDynamic, ToDynamic)]
|
||||
pub enum ScrollbackEraseMode {
|
||||
ScrollbackOnly,
|
||||
|
||||
@@ -1197,6 +1197,7 @@ impl Client {
|
||||
rpc!(mouse_event, SendMouseEvent, UnitResponse);
|
||||
rpc!(resize, Resize, UnitResponse);
|
||||
rpc!(set_zoomed, SetPaneZoomed, UnitResponse);
|
||||
rpc!(activate_pane_direction, ActivatePaneDirection, UnitResponse);
|
||||
rpc!(
|
||||
get_pane_render_changes,
|
||||
GetPaneRenderChanges,
|
||||
|
||||
@@ -460,6 +460,26 @@ impl SessionHandler {
|
||||
.detach();
|
||||
}
|
||||
|
||||
Pdu::ActivatePaneDirection(ActivatePaneDirection { pane_id, direction }) => {
|
||||
spawn_into_main_thread(async move {
|
||||
catch(
|
||||
move || {
|
||||
let mux = Mux::get().unwrap();
|
||||
let (_domain_id, _window_id, tab_id) = mux
|
||||
.resolve_pane_id(pane_id)
|
||||
.ok_or_else(|| anyhow!("no such pane {}", pane_id))?;
|
||||
let tab = mux
|
||||
.get_tab(tab_id)
|
||||
.ok_or_else(|| anyhow!("no such tab {}", tab_id))?;
|
||||
tab.activate_pane_direction(direction);
|
||||
Ok(Pdu::UnitResponse(UnitResponse {}))
|
||||
},
|
||||
send_response,
|
||||
)
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
||||
Pdu::Resize(Resize {
|
||||
containing_tab_id,
|
||||
pane_id,
|
||||
|
||||
+15
-1
@@ -2,7 +2,7 @@ use anyhow::{anyhow, Context};
|
||||
use chrono::{DateTime, Utc};
|
||||
use clap::{Parser, ValueEnum, ValueHint};
|
||||
use clap_complete::{generate as generate_completion, shells, Generator as CompletionGenerator};
|
||||
use config::keyassignment::SpawnTabDomain;
|
||||
use config::keyassignment::{PaneDirection, SpawnTabDomain};
|
||||
use config::wezterm_version;
|
||||
use mux::activity::Activity;
|
||||
use mux::pane::PaneId;
|
||||
@@ -367,6 +367,14 @@ Outputs the pane-id for the newly created pane on success"
|
||||
/// The text to send. If omitted, will read the text from stdin.
|
||||
text: Option<String>,
|
||||
},
|
||||
|
||||
/// Activate an adjacent pane in the specified direction.
|
||||
#[clap(name = "activate-pane-direction", rename_all = "kebab")]
|
||||
ActivatePaneDirection {
|
||||
/// The direction to switch to.
|
||||
#[clap(parse(try_from_str = PaneDirection::direction_from_str))]
|
||||
direction: PaneDirection,
|
||||
},
|
||||
}
|
||||
|
||||
use termwiz::escape::osc::{
|
||||
@@ -1144,6 +1152,12 @@ async fn run_cli_async(config: config::ConfigHandle, cli: CliCommand) -> anyhow:
|
||||
let creds = client.get_tls_creds().await?;
|
||||
codec::Pdu::GetTlsCredsResponse(creds).encode(std::io::stdout().lock(), 0)?;
|
||||
}
|
||||
CliSubCommand::ActivatePaneDirection { direction } => {
|
||||
let pane_id = resolve_pane_id(&client, None).await?;
|
||||
client
|
||||
.activate_pane_direction(codec::ActivatePaneDirection { pane_id, direction })
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user