we can now send input to a client tab
This commit is contained in:
1 parent
c1e605aedf
commit
86cd39eb4e
6 files changed
+105
-16
No files matched your search
@@ -72,4 +72,6 @@ impl Client {
|
||||
);
|
||||
rpc!(spawn, Spawn, SpawnResponse);
|
||||
rpc!(write_to_tab, WriteToTab, UnitResponse);
|
||||
rpc!(key_down, SendKeyDown, UnitResponse);
|
||||
rpc!(mouse_event, SendMouseEvent, UnitResponse);
|
||||
}
|
||||
@@ -216,6 +216,8 @@ pdu! {
|
||||
SpawnResponse: 8,
|
||||
WriteToTab: 9,
|
||||
UnitResponse: 10,
|
||||
SendKeyDown: 11,
|
||||
SendMouseEvent: 12,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, PartialEq, Debug)]
|
||||
@@ -278,6 +280,18 @@ pub struct WriteToTab {
|
||||
pub data: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, PartialEq, Debug)]
|
||||
pub struct SendKeyDown {
|
||||
pub tab_id: TabId,
|
||||
pub event: termwiz::input::KeyEvent,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, PartialEq, Debug)]
|
||||
pub struct SendMouseEvent {
|
||||
pub tab_id: TabId,
|
||||
pub event: term::input::MouseEvent,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
+61
-1
@@ -5,7 +5,7 @@ use crate::server::{UnixListener, UnixStream};
|
||||
use failure::{err_msg, format_err, Error};
|
||||
#[cfg(unix)]
|
||||
use libc::{mode_t, umask};
|
||||
use log::{debug, error};
|
||||
use log::{debug, error, warn};
|
||||
use promise::{Executor, Future};
|
||||
use std::collections::HashMap;
|
||||
use std::fs::{remove_file, DirBuilder};
|
||||
@@ -47,6 +47,36 @@ pub struct ClientSession {
|
||||
executor: Box<dyn Executor>,
|
||||
}
|
||||
|
||||
struct BufferedTerminalHost<'a> {
|
||||
write: std::cell::RefMut<'a, dyn std::io::Write>,
|
||||
clipboard: Option<Option<String>>,
|
||||
title: Option<String>,
|
||||
}
|
||||
|
||||
impl<'a> term::TerminalHost for BufferedTerminalHost<'a> {
|
||||
fn writer(&mut self) -> &mut dyn std::io::Write {
|
||||
&mut *self.write
|
||||
}
|
||||
|
||||
fn click_link(&mut self, link: &Arc<term::cell::Hyperlink>) {
|
||||
error!("ignoring url open of {:?}", link.uri());
|
||||
}
|
||||
|
||||
fn get_clipboard(&mut self) -> Result<String, Error> {
|
||||
warn!("peer requested clipboard; ignoring");
|
||||
Ok("".into())
|
||||
}
|
||||
|
||||
fn set_clipboard(&mut self, clip: Option<String>) -> Result<(), Error> {
|
||||
self.clipboard.replace(clip);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_title(&mut self, title: &str) {
|
||||
self.title.replace(title.to_owned());
|
||||
}
|
||||
}
|
||||
|
||||
impl ClientSession {
|
||||
fn new(stream: UnixStream, executor: Box<dyn Executor>) -> Self {
|
||||
Self { stream, executor }
|
||||
@@ -118,6 +148,36 @@ impl ClientSession {
|
||||
Pdu::UnitResponse(UnitResponse {}).encode(&mut self.stream, decoded.serial)?;
|
||||
}
|
||||
|
||||
Pdu::SendKeyDown(SendKeyDown { tab_id, event }) => {
|
||||
Future::with_executor(self.executor.clone_executor(), move || {
|
||||
let mux = Mux::get().unwrap();
|
||||
let tab = mux
|
||||
.get_tab(tab_id)
|
||||
.ok_or_else(|| format_err!("no such tab {}", tab_id))?;
|
||||
tab.key_down(event.key, event.modifiers)?;
|
||||
Ok(())
|
||||
})
|
||||
.wait()?;
|
||||
Pdu::UnitResponse(UnitResponse {}).encode(&mut self.stream, decoded.serial)?;
|
||||
}
|
||||
Pdu::SendMouseEvent(SendMouseEvent { tab_id, event }) => {
|
||||
Future::with_executor(self.executor.clone_executor(), move || {
|
||||
let mux = Mux::get().unwrap();
|
||||
let tab = mux
|
||||
.get_tab(tab_id)
|
||||
.ok_or_else(|| format_err!("no such tab {}", tab_id))?;
|
||||
let mut host = BufferedTerminalHost {
|
||||
write: tab.writer(),
|
||||
clipboard: None,
|
||||
title: None,
|
||||
};
|
||||
tab.mouse_event(event, &mut host)?;
|
||||
Ok(())
|
||||
})
|
||||
.wait()?;
|
||||
Pdu::UnitResponse(UnitResponse {}).encode(&mut self.stream, decoded.serial)?;
|
||||
}
|
||||
|
||||
Pdu::Spawn(spawn) => {
|
||||
let result = Future::with_executor(self.executor.clone_executor(), move || {
|
||||
let mux = Mux::get().unwrap();
|
||||
|
||||
+17
-5
@@ -1,9 +1,7 @@
|
||||
use crate::mux::domain::DomainId;
|
||||
use crate::mux::renderable::Renderable;
|
||||
use crate::mux::tab::{alloc_tab_id, Tab, TabId};
|
||||
use crate::server::codec::{
|
||||
GetCoarseTabRenderableData, GetCoarseTabRenderableDataResponse, WriteToTab,
|
||||
};
|
||||
use crate::server::codec::*;
|
||||
use crate::server::domain::ClientInner;
|
||||
use failure::{bail, Fallible};
|
||||
use filedescriptor::Pipe;
|
||||
@@ -17,6 +15,7 @@ use term::color::ColorPalette;
|
||||
use term::{CursorPosition, Line};
|
||||
use term::{KeyCode, KeyModifiers, MouseEvent, TerminalHost};
|
||||
use termwiz::hyperlink::Hyperlink;
|
||||
use termwiz::input::KeyEvent;
|
||||
|
||||
pub struct ClientTab {
|
||||
client: Arc<ClientInner>,
|
||||
@@ -83,11 +82,24 @@ impl Tab for ClientTab {
|
||||
}
|
||||
|
||||
fn key_down(&self, key: KeyCode, mods: KeyModifiers) -> Fallible<()> {
|
||||
bail!("ClientTab::key_down not impl");
|
||||
let mut client = self.client.client.lock().unwrap();
|
||||
client.key_down(SendKeyDown {
|
||||
tab_id: self.remote_tab_id,
|
||||
event: KeyEvent {
|
||||
key: key,
|
||||
modifiers: mods,
|
||||
},
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn mouse_event(&self, event: MouseEvent, host: &mut dyn TerminalHost) -> Fallible<()> {
|
||||
bail!("ClientTab::mouse_event not impl");
|
||||
let mut client = self.client.client.lock().unwrap();
|
||||
client.mouse_event(SendMouseEvent {
|
||||
tab_id: self.remote_tab_id,
|
||||
event,
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn advance_bytes(&self, buf: &[u8], host: &mut dyn TerminalHost) {
|
||||
|
||||
+5
-5
@@ -1,14 +1,14 @@
|
||||
// clippy hates bitflags
|
||||
#![cfg_attr(feature = "cargo-clippy", allow(clippy::suspicious_arithmetic_impl, clippy::redundant_field_names))]
|
||||
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use super::VisibleRowIndex;
|
||||
use serde_derive::*;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
pub use termwiz::input::KeyCode;
|
||||
pub use termwiz::input::Modifiers as KeyModifiers;
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize)]
|
||||
pub enum MouseButton {
|
||||
Left,
|
||||
Middle,
|
||||
@@ -18,14 +18,14 @@ pub enum MouseButton {
|
||||
None,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize)]
|
||||
pub enum MouseEventKind {
|
||||
Press,
|
||||
Release,
|
||||
Move,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize)]
|
||||
pub struct MouseEvent {
|
||||
pub kind: MouseEventKind,
|
||||
pub x: usize,
|
||||
|
||||
@@ -6,6 +6,7 @@ use crate::escape::{Action, CSI};
|
||||
use crate::keymap::{Found, KeyMap};
|
||||
use crate::readbuf::ReadBuffer;
|
||||
use bitflags::bitflags;
|
||||
use serde_derive::*;
|
||||
use std;
|
||||
|
||||
#[cfg(windows)]
|
||||
@@ -15,7 +16,7 @@ use winapi::um::wincon::{
|
||||
};
|
||||
|
||||
bitflags! {
|
||||
#[derive(Default)]
|
||||
#[derive(Default, Serialize, Deserialize)]
|
||||
pub struct Modifiers: u8 {
|
||||
const NONE = 0;
|
||||
const SHIFT = 1<<1;
|
||||
@@ -25,7 +26,7 @@ bitflags! {
|
||||
}
|
||||
}
|
||||
bitflags! {
|
||||
#[derive(Default)]
|
||||
#[derive(Default, Serialize, Deserialize)]
|
||||
pub struct MouseButtons: u8 {
|
||||
const NONE = 0;
|
||||
const LEFT = 1<<1;
|
||||
@@ -55,7 +56,7 @@ pub enum InputEvent {
|
||||
Wake,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct MouseEvent {
|
||||
pub x: u16,
|
||||
pub y: u16,
|
||||
@@ -63,7 +64,7 @@ pub struct MouseEvent {
|
||||
pub modifiers: Modifiers,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct KeyEvent {
|
||||
/// Which key was pressed
|
||||
pub key: KeyCode,
|
||||
@@ -75,7 +76,7 @@ pub struct KeyEvent {
|
||||
/// Which key is pressed. Not all of these are probable to appear
|
||||
/// on most systems. A lot of this list is @wez trawling docs and
|
||||
/// making an entry for things that might be possible in this first pass.
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub enum KeyCode {
|
||||
/// The decoded unicode character
|
||||
Char(char),
|
||||
|
||||
Reference in new issue
Block a user