1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-29 16:42:13 +03:00

add ListTabs rpc

This commit is contained in:
Wez Furlong 2019-03-13 22:24:37 -07:00
parent 4269f6ff5e
commit 4bdbb072f9
5 changed files with 44 additions and 8 deletions

View File

@ -157,6 +157,7 @@ fn main() -> Result<(), Error> {
use crate::server::client::Client;
let mut client = Client::new(&config)?;
eprintln!("ping: {:?}", client.ping()?);
eprintln!("tabs: {:?}", client.list_tabs()?);
Ok(())
}
}

View File

@ -179,6 +179,14 @@ impl Mux {
pub fn is_empty(&self) -> bool {
self.tabs.borrow().is_empty()
}
pub fn iter_tabs(&self) -> Vec<Rc<Tab>> {
self.tabs
.borrow()
.iter()
.map(|(_, v)| Rc::clone(v))
.collect()
}
}
#[derive(Debug, Fail)]

View File

@ -63,4 +63,5 @@ impl Client {
}
rpc!(ping, Ping = (), Pong);
rpc!(list_tabs, ListTabs = (), ListTabsResponse);
}

View File

@ -10,8 +10,10 @@
//! manage unknown enum variants.
#![allow(dead_code)]
use crate::mux::tab::TabId;
use bincode;
use failure::Error;
use std::collections::HashMap;
use varu64;
fn encode_raw<W: std::io::Write>(
@ -77,11 +79,6 @@ pub struct DecodedPdu {
pub pdu: Pdu,
}
#[derive(Deserialize, Serialize, PartialEq, Debug)]
pub struct Ping {}
#[derive(Deserialize, Serialize, PartialEq, Debug)]
pub struct Pong {}
macro_rules! pdu {
($( $name:ident:$vers:expr),* $(,)?) => {
#[derive(PartialEq, Debug)]
@ -133,7 +130,22 @@ macro_rules! pdu {
/// and defining newer structs as the protocol evolves.
pdu! {
Ping: 1,
Pong: 2
Pong: 2,
ListTabs: 3,
ListTabsResponse: 4,
}
#[derive(Deserialize, Serialize, PartialEq, Debug)]
pub struct Ping {}
#[derive(Deserialize, Serialize, PartialEq, Debug)]
pub struct Pong {}
#[derive(Deserialize, Serialize, PartialEq, Debug)]
pub struct ListTabs {}
#[derive(Deserialize, Serialize, PartialEq, Debug)]
pub struct ListTabsResponse {
pub tabs: HashMap<TabId, String>,
}
#[cfg(test)]

View File

@ -1,10 +1,12 @@
use crate::config::Config;
use crate::mux::Mux;
use crate::server::codec::*;
use crate::server::{UnixListener, UnixStream};
use failure::{err_msg, Error};
#[cfg(unix)]
use libc::{mode_t, umask};
use promise::Executor;
use promise::{Executor, Future};
use std::collections::HashMap;
use std::fs::{remove_file, DirBuilder};
#[cfg(unix)]
use std::os::unix::fs::{DirBuilderExt, PermissionsExt};
@ -57,8 +59,20 @@ impl ClientSession {
Pdu::Ping(Ping {}) => {
Pdu::Pong(Pong {}).encode(&mut self.stream, decoded.serial)?;
}
Pdu::ListTabs(ListTabs {}) => {
let result = Future::with_executor(self.executor.clone_executor(), move || {
let mut tabs = HashMap::new();
let mux = Mux::get().unwrap();
for tab in mux.iter_tabs() {
tabs.insert(tab.tab_id(), tab.get_title());
}
Ok(ListTabsResponse { tabs })
})
.wait()?;
Pdu::ListTabsResponse(result).encode(&mut self.stream, decoded.serial)?;
}
Pdu::Pong { .. } | Pdu::Invalid { .. } => {}
Pdu::Pong { .. } | Pdu::ListTabsResponse { .. } | Pdu::Invalid { .. } => {}
}
}
}