Skip to content

Commit

Permalink
Toggle the zoom state of the current pane from CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
quantonganh committed Aug 19, 2023
1 parent 87a0099 commit 403a711
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 1 deletion.
6 changes: 6 additions & 0 deletions codec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ pdu! {
GetPaneDirection: 60,
GetPaneDirectionResponse: 61,
AdjustPaneSize: 62,
TogglePaneZoomState: 63,
}

impl Pdu {
Expand Down Expand Up @@ -852,6 +853,11 @@ pub struct SetPaneZoomed {
pub zoomed: bool,
}

#[derive(Deserialize, Serialize, PartialEq, Debug)]
pub struct TogglePaneZoomState {
pub pane_id: PaneId,
}

#[derive(Deserialize, Serialize, PartialEq, Debug)]
pub struct GetPaneDirection {
pub pane_id: PaneId,
Expand Down
1 change: 1 addition & 0 deletions wezterm-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1328,4 +1328,5 @@ impl Client {
GetPaneDirectionResponse
);
rpc!(adjust_pane_size, AdjustPaneSize, UnitResponse);
rpc!(toggle_pane_zoom_state, TogglePaneZoomState, UnitResponse);
}
22 changes: 21 additions & 1 deletion wezterm-mux-server-impl/src/sessionhandler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,26 @@ impl SessionHandler {
.detach();
}

Pdu::TogglePaneZoomState(TogglePaneZoomState { pane_id }) => {
spawn_into_main_thread(async move {
catch(
move || {
let mux = Mux::get();
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.toggle_zoom();
Ok(Pdu::UnitResponse(UnitResponse {}))
},
send_response,
)
})
.detach();
}

Pdu::Invalid { .. } => send_response(Err(anyhow!("invalid PDU {:?}", decoded.pdu))),
Pdu::Pong { .. }
| Pdu::ListPanesResponse { .. }
Expand Down Expand Up @@ -1021,7 +1041,7 @@ async fn split_pane(split: SplitPane, client_id: Option<Arc<ClientId>>) -> anyho

Ok::<Pdu, anyhow::Error>(Pdu::SpawnResponse(SpawnResponse {
pane_id: pane.pane_id(),
tab_id: tab_id,
tab_id,
window_id,
size,
}))
Expand Down
6 changes: 6 additions & 0 deletions wezterm/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ mod set_window_title;
mod spawn_command;
mod split_pane;
mod tls_creds;
mod toggle_pane_zoom_state;

#[derive(Debug, Parser, Clone, Copy)]
enum CliOutputFormatKind {
Expand Down Expand Up @@ -159,6 +160,10 @@ Outputs the pane-id for the newly created pane on success"
/// Rename a workspace
#[command(name = "rename-workspace", rename_all = "kebab")]
RenameWorkspace(rename_workspace::RenameWorkspace),

/// Toggle the zoom state of the current pane
#[command(name = "toggle-pane-zoom-state", rename_all = "kebab")]
TogglePaneZoomState(toggle_pane_zoom_state::TogglePaneZoomState),
}

async fn run_cli_async(opts: &crate::Opt, cli: CliCommand) -> anyhow::Result<()> {
Expand Down Expand Up @@ -194,6 +199,7 @@ async fn run_cli_async(opts: &crate::Opt, cli: CliCommand) -> anyhow::Result<()>
CliSubCommand::SetTabTitle(cmd) => cmd.run(client).await,
CliSubCommand::SetWindowTitle(cmd) => cmd.run(client).await,
CliSubCommand::RenameWorkspace(cmd) => cmd.run(client).await,
CliSubCommand::TogglePaneZoomState(cmd) => cmd.run(client).await,
}
}

Expand Down
18 changes: 18 additions & 0 deletions wezterm/src/cli/toggle_pane_zoom_state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use crate::cli::resolve_pane_id;
use clap::Parser;
use mux::pane::PaneId;
use wezterm_client::client::Client;

#[derive(Debug, Parser, Clone)]
pub struct TogglePaneZoomState {}

impl TogglePaneZoomState {
pub async fn run(&self, client: Client) -> anyhow::Result<()> {
let none: Option<PaneId> = None;
let pane_id = resolve_pane_id(&client, none).await?;
client
.toggle_pane_zoom_state(codec::TogglePaneZoomState { pane_id })
.await?;
Ok(())
}
}

0 comments on commit 403a711

Please sign in to comment.