From cc0ac6c8337e3dfea740feb0385d4a14e737d77c Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 22 Nov 2019 15:16:14 -0500 Subject: resize the browser terminal if the streamer terminal is resized --- teleterm-web/src/lib.rs | 3 ++ teleterm-web/src/model.rs | 6 ++++ teleterm-web/src/protocol.rs | 3 +- teleterm/src/cmd/watch.rs | 3 ++ teleterm/src/server.rs | 23 ++++++++---- teleterm/src/web.rs | 9 ++--- teleterm/static/teleterm_web.js | 66 +++++++++++++++++------------------ teleterm/static/teleterm_web_bg.wasm | Bin 713218 -> 716255 bytes 8 files changed, 66 insertions(+), 47 deletions(-) diff --git a/teleterm-web/src/lib.rs b/teleterm-web/src/lib.rs index b2ad524..5d59f24 100644 --- a/teleterm-web/src/lib.rs +++ b/teleterm-web/src/lib.rs @@ -67,6 +67,9 @@ fn update( model.disconnect_watch(); orders.perform_cmd(model.list()); } + crate::protocol::Message::Resize { size } => { + model.set_size(size.rows, size.cols); + } } } ws::WebSocketEvent::Error(e) => { diff --git a/teleterm-web/src/model.rs b/teleterm-web/src/model.rs index 72ac8c3..ba707eb 100644 --- a/teleterm-web/src/model.rs +++ b/teleterm-web/src/model.rs @@ -67,6 +67,12 @@ impl Model { } } + pub fn set_size(&mut self, rows: u16, cols: u16) { + if let Some(conn) = &mut self.watch_conn { + conn.term.set_size(rows, cols); + } + } + pub fn screen(&self) -> Option<&vt100::Screen> { self.watch_conn.as_ref().map(|conn| conn.term.screen()) } diff --git a/teleterm-web/src/protocol.rs b/teleterm-web/src/protocol.rs index 60047e0..9c0c144 100644 --- a/teleterm-web/src/protocol.rs +++ b/teleterm-web/src/protocol.rs @@ -1,10 +1,11 @@ // it's possible we should just consider pulling the real protocol out into a // crate or something? but ideally in a way that doesn't require pulling in // tokio -#[derive(Debug, Clone, PartialEq, Eq, serde::Deserialize)] +#[derive(Clone, Debug, serde::Deserialize)] pub enum Message { TerminalOutput { data: Vec }, Disconnected, + Resize { size: Size }, } #[derive(Clone, Debug, serde::Deserialize)] diff --git a/teleterm/src/cmd/watch.rs b/teleterm/src/cmd/watch.rs index f156112..f205002 100644 --- a/teleterm/src/cmd/watch.rs +++ b/teleterm/src/cmd/watch.rs @@ -360,6 +360,9 @@ impl crate::protocol::Message::Error { msg } => { return Err(Error::Server { message: msg }); } + crate::protocol::Message::Resize { .. } => { + // do nothing + } msg => { return Err(crate::error::Error::UnexpectedMessage { message: msg, diff --git a/teleterm/src/server.rs b/teleterm/src/server.rs index 1f8f442..1f565a2 100644 --- a/teleterm/src/server.rs +++ b/teleterm/src/server.rs @@ -489,16 +489,17 @@ impl let username = conn.state.username().unwrap(); if let Some(stream_conn) = self.connections.get(&id) { - let data = stream_conn - .state - .term() - .map(|parser| parser.screen().contents_formatted()) - .ok_or_else(|| Error::InvalidWatchId { - id: id.to_string(), - })?; + let term = stream_conn.state.term().ok_or_else(|| { + Error::InvalidWatchId { id: id.to_string() } + })?; + let (rows, cols) = term.screen().size(); + let data = term.screen().contents_formatted(); log::info!("{}: watch({}, {})", conn.id, username, id); conn.state.watch(&id); + conn.send_message(crate::protocol::Message::resize( + crate::term::Size { rows, cols }, + )); conn.send_message(crate::protocol::Message::terminal_output( &data, )); @@ -585,6 +586,14 @@ impl parser.set_size(size.rows, size.cols); } + for watch_conn in self.watchers_mut() { + let watch_id = watch_conn.state.watch_id().unwrap(); + if conn.id == watch_id { + watch_conn + .send_message(crate::protocol::Message::resize(size)); + } + } + Ok(()) } diff --git a/teleterm/src/web.rs b/teleterm/src/web.rs index 6cc9568..89291c5 100644 --- a/teleterm/src/web.rs +++ b/teleterm/src/web.rs @@ -377,12 +377,9 @@ impl msg: &crate::protocol::Message, ) -> Result> { match msg { - crate::protocol::Message::TerminalOutput { .. } => { - let json = serde_json::to_string(msg) - .context(crate::error::SerializeMessage)?; - Ok(Some(tungstenite::Message::Text(json))) - } - crate::protocol::Message::Disconnected => { + crate::protocol::Message::TerminalOutput { .. } + | crate::protocol::Message::Disconnected + | crate::protocol::Message::Resize { .. } => { let json = serde_json::to_string(msg) .context(crate::error::SerializeMessage)?; Ok(Some(tungstenite::Message::Text(json))) diff --git a/teleterm/static/teleterm_web.js b/teleterm/static/teleterm_web.js index 2520faa..d886582 100644 --- a/teleterm/static/teleterm_web.js +++ b/teleterm/static/teleterm_web.js @@ -18,31 +18,31 @@ function addHeapObject(obj) { return idx; } function __wbg_elem_binding0(arg0, arg1, arg2) { - wasm.__wbg_function_table.get(74)(arg0, arg1, addHeapObject(arg2)); + wasm.__wbg_function_table.get(75)(arg0, arg1, addHeapObject(arg2)); } function __wbg_elem_binding1(arg0, arg1, arg2) { - wasm.__wbg_function_table.get(74)(arg0, arg1, addHeapObject(arg2)); + wasm.__wbg_function_table.get(296)(arg0, arg1, addHeapObject(arg2)); } -function __wbg_elem_binding2(arg0, arg1) { - wasm.__wbg_function_table.get(225)(arg0, arg1); +function __wbg_elem_binding2(arg0, arg1, arg2) { + wasm.__wbg_function_table.get(75)(arg0, arg1, addHeapObject(arg2)); } -function __wbg_elem_binding3(arg0, arg1, arg2) { - wasm.__wbg_function_table.get(74)(arg0, arg1, addHeapObject(arg2)); +function __wbg_elem_binding3(arg0, arg1) { + wasm.__wbg_function_table.get(227)(arg0, arg1); } function __wbg_elem_binding4(arg0, arg1, arg2) { - wasm.__wbg_function_table.get(74)(arg0, arg1, addHeapObject(arg2)); + wasm.__wbg_function_table.get(75)(arg0, arg1, addHeapObject(arg2)); } function __wbg_elem_binding5(arg0, arg1, arg2) { - wasm.__wbg_function_table.get(78)(arg0, arg1, arg2); + wasm.__wbg_function_table.get(79)(arg0, arg1, arg2); } function __wbg_elem_binding6(arg0, arg1, arg2) { - wasm.__wbg_function_table.get(294)(arg0, arg1, addHeapObject(arg2)); + wasm.__wbg_function_table.get(75)(arg0, arg1, addHeapObject(arg2)); } function __wbg_elem_binding7(arg0, arg1, arg2, arg3, arg4) { - wasm.__wbg_function_table.get(321)(arg0, arg1, addHeapObject(arg2), arg3, addHeapObject(arg4)); + wasm.__wbg_function_table.get(323)(arg0, arg1, addHeapObject(arg2), arg3, addHeapObject(arg4)); } function __wbg_elem_binding8(arg0, arg1, arg2, arg3) { - wasm.__wbg_function_table.get(325)(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3)); + wasm.__wbg_function_table.get(327)(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3)); } /** */ @@ -884,7 +884,7 @@ function init(module) { imports.wbg.__wbindgen_throw = function(arg0, arg1) { throw new Error(getStringFromWasm(arg0, arg1)); }; - imports.wbg.__wbindgen_closure_wrapper315 = function(arg0, arg1, arg2) { + imports.wbg.__wbindgen_closure_wrapper322 = function(arg0, arg1, arg2) { const state = { a: arg0, b: arg1, cnt: 1 }; const real = (arg0) => { state.cnt++; @@ -893,7 +893,7 @@ function init(module) { try { return __wbg_elem_binding4(a, state.b, arg0); } finally { - if (--state.cnt === 0) wasm.__wbg_function_table.get(75)(a, state.b); + if (--state.cnt === 0) wasm.__wbg_function_table.get(76)(a, state.b); else state.a = a; } } @@ -902,16 +902,16 @@ function init(module) { const ret = real; return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper313 = function(arg0, arg1, arg2) { + imports.wbg.__wbindgen_closure_wrapper656 = function(arg0, arg1, arg2) { const state = { a: arg0, b: arg1, cnt: 1 }; - const real = (arg0) => { + const real = () => { state.cnt++; const a = state.a; state.a = 0; try { - return __wbg_elem_binding5(a, state.b, arg0); + return __wbg_elem_binding3(a, state.b, ); } finally { - if (--state.cnt === 0) wasm.__wbg_function_table.get(75)(a, state.b); + if (--state.cnt === 0) wasm.__wbg_function_table.get(228)(a, state.b); else state.a = a; } } @@ -920,16 +920,16 @@ function init(module) { const ret = real; return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper651 = function(arg0, arg1, arg2) { + imports.wbg.__wbindgen_closure_wrapper1076 = function(arg0, arg1, arg2) { const state = { a: arg0, b: arg1, cnt: 1 }; - const real = () => { + const real = (arg0) => { state.cnt++; const a = state.a; state.a = 0; try { - return __wbg_elem_binding2(a, state.b, ); + return __wbg_elem_binding1(a, state.b, arg0); } finally { - if (--state.cnt === 0) wasm.__wbg_function_table.get(226)(a, state.b); + if (--state.cnt === 0) wasm.__wbg_function_table.get(297)(a, state.b); else state.a = a; } } @@ -938,16 +938,16 @@ function init(module) { const ret = real; return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper1071 = function(arg0, arg1, arg2) { + imports.wbg.__wbindgen_closure_wrapper316 = function(arg0, arg1, arg2) { const state = { a: arg0, b: arg1, cnt: 1 }; const real = (arg0) => { state.cnt++; const a = state.a; state.a = 0; try { - return __wbg_elem_binding6(a, state.b, arg0); + return __wbg_elem_binding5(a, state.b, arg0); } finally { - if (--state.cnt === 0) wasm.__wbg_function_table.get(295)(a, state.b); + if (--state.cnt === 0) wasm.__wbg_function_table.get(76)(a, state.b); else state.a = a; } } @@ -956,16 +956,16 @@ function init(module) { const ret = real; return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper319 = function(arg0, arg1, arg2) { + imports.wbg.__wbindgen_closure_wrapper318 = function(arg0, arg1, arg2) { const state = { a: arg0, b: arg1, cnt: 1 }; const real = (arg0) => { state.cnt++; const a = state.a; state.a = 0; try { - return __wbg_elem_binding0(a, state.b, arg0); + return __wbg_elem_binding2(a, state.b, arg0); } finally { - if (--state.cnt === 0) wasm.__wbg_function_table.get(75)(a, state.b); + if (--state.cnt === 0) wasm.__wbg_function_table.get(76)(a, state.b); else state.a = a; } } @@ -974,16 +974,16 @@ function init(module) { const ret = real; return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper311 = function(arg0, arg1, arg2) { + imports.wbg.__wbindgen_closure_wrapper320 = function(arg0, arg1, arg2) { const state = { a: arg0, b: arg1, cnt: 1 }; const real = (arg0) => { state.cnt++; const a = state.a; state.a = 0; try { - return __wbg_elem_binding1(a, state.b, arg0); + return __wbg_elem_binding6(a, state.b, arg0); } finally { - if (--state.cnt === 0) wasm.__wbg_function_table.get(75)(a, state.b); + if (--state.cnt === 0) wasm.__wbg_function_table.get(76)(a, state.b); else state.a = a; } } @@ -992,16 +992,16 @@ function init(module) { const ret = real; return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper317 = function(arg0, arg1, arg2) { + imports.wbg.__wbindgen_closure_wrapper314 = function(arg0, arg1, arg2) { const state = { a: arg0, b: arg1, cnt: 1 }; const real = (arg0) => { state.cnt++; const a = state.a; state.a = 0; try { - return __wbg_elem_binding3(a, state.b, arg0); + return __wbg_elem_binding0(a, state.b, arg0); } finally { - if (--state.cnt === 0) wasm.__wbg_function_table.get(75)(a, state.b); + if (--state.cnt === 0) wasm.__wbg_function_table.get(76)(a, state.b); else state.a = a; } } diff --git a/teleterm/static/teleterm_web_bg.wasm b/teleterm/static/teleterm_web_bg.wasm index df83c13..ace642f 100644 Binary files a/teleterm/static/teleterm_web_bg.wasm and b/teleterm/static/teleterm_web_bg.wasm differ -- cgit v1.2.3-54-g00ecf