1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-23 21:32:13 +03:00

add spawn rpc

This commit is contained in:
Wez Furlong 2019-06-09 08:15:37 -07:00
parent 0a1dd49409
commit e98d8acb96
6 changed files with 43 additions and 2 deletions

View File

@ -2,13 +2,14 @@
use failure::{ensure, Error};
#[cfg(windows)]
use log::error;
use serde_derive::*;
use std::ffi::{OsStr, OsString};
#[cfg(windows)]
use std::os::windows::ffi::OsStrExt;
/// `CommandBuilder` is used to prepare a command to be spawned into a pty.
/// The interface is intentionally similar to that of `std::process::Command`.
#[derive(Debug)]
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct CommandBuilder {
args: Vec<OsString>,
envs: Vec<(OsString, OsString)>,

View File

@ -50,7 +50,7 @@ pub mod unix;
pub mod win;
/// Represents the size of the visible display area in the pty
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)]
pub struct PtySize {
/// The number of lines of text
pub rows: u16,

View File

@ -185,6 +185,14 @@ fn main() -> Result<(), Error> {
})?;
// info!("coarse: {:?}", data);
}
error!(
"spawn: {:?}",
client.spawn(Spawn {
domain_id: 0,
size: PtySize::default(),
command: None
})
);
Ok(())
}
}

View File

@ -70,4 +70,5 @@ impl Client {
GetCoarseTabRenderableData,
GetCoarseTabRenderableDataResponse
);
rpc!(spawn, Spawn, SpawnResponse);
}

View File

@ -10,10 +10,12 @@
//! manage unknown enum variants.
#![allow(dead_code)]
use crate::mux::domain::DomainId;
use crate::mux::tab::TabId;
use failure::{bail, Error};
use leb128;
use log::debug;
use portable_pty::{CommandBuilder, PtySize};
use serde_derive::*;
use std::collections::HashMap;
use std::sync::Arc;
@ -211,6 +213,8 @@ pdu! {
ListTabsResponse: 4,
GetCoarseTabRenderableData: 5,
GetCoarseTabRenderableDataResponse: 6,
Spawn: 7,
SpawnResponse: 8,
}
#[derive(Deserialize, Serialize, PartialEq, Debug)]
@ -252,6 +256,18 @@ pub struct GetCoarseTabRenderableDataResponse {
pub dirty_lines: Vec<DirtyLine>,
}
#[derive(Deserialize, Serialize, PartialEq, Debug)]
pub struct Spawn {
pub domain_id: DomainId,
pub command: Option<CommandBuilder>,
pub size: PtySize,
}
#[derive(Deserialize, Serialize, PartialEq, Debug)]
pub struct SpawnResponse {
pub tab_id: TabId,
}
#[cfg(test)]
mod test {
use super::*;

View File

@ -105,9 +105,24 @@ impl ClientSession {
.encode(&mut self.stream, decoded.serial)?;
}
Pdu::Spawn(spawn) => {
let result = Future::with_executor(self.executor.clone_executor(), move || {
let mux = Mux::get().unwrap();
let domain = mux.get_domain(spawn.domain_id).ok_or_else(|| {
format_err!("domain {} not found on this server", spawn.domain_id)
})?;
Ok(SpawnResponse {
tab_id: domain.spawn(spawn.size, spawn.command)?.tab_id(),
})
})
.wait()?;
Pdu::SpawnResponse(result).encode(&mut self.stream, decoded.serial)?;
}
Pdu::Pong { .. }
| Pdu::ListTabsResponse { .. }
| Pdu::GetCoarseTabRenderableDataResponse { .. }
| Pdu::SpawnResponse { .. }
| Pdu::Invalid { .. } => {}
}
}