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

mux: propagate User Vars across to the client

user vars were stubbed out.  This commit adds storage for them
in the mux client and adds a new notification that publishes each
var as it is changed.  That differential stream is applied to the
storage in the mux client when it is received.

```lua
local wezterm = require 'wezterm'

wezterm.on("update-right-status", function(window, pane)
  local woot = pane:get_user_vars().woot
  window:set_right_status(tostring(woot))
end);

return {
  unix_domains = {
    {name="unix"},
  },
}
```

then running:

* `wezterm connect unix`
* in that session: `printf "\033]1337;SetUserVar=%s=%s\007" woot `echo -n nice | base64``

causes `nice` to show in the status area.

refs: #1528
This commit is contained in:
Wez Furlong 2022-01-10 18:33:32 -07:00
parent 3ae38eb5bf
commit 1fd53d4a5d
8 changed files with 27 additions and 10 deletions

View File

@ -406,7 +406,7 @@ macro_rules! pdu {
/// The overall version of the codec. /// The overall version of the codec.
/// This must be bumped when backwards incompatible changes /// This must be bumped when backwards incompatible changes
/// are made to the types and protocol. /// are made to the types and protocol.
pub const CODEC_VERSION: usize = 12; pub const CODEC_VERSION: usize = 13;
// Defines the Pdu enum. // Defines the Pdu enum.
// Each struct has an explicit identifying number. // Each struct has an explicit identifying number.

View File

@ -42,6 +42,7 @@ As features stabilize some brief notes about them will accumulate here.
* Kitty Image Protocol: didn't respect `c` and `r` parameters to scale images * Kitty Image Protocol: didn't respect `c` and `r` parameters to scale images
* Cursor location on the primary screen wasn't updated correctly if the window was resized while the alternate screen was active [#1512](https://github.com/wez/wezterm/issues/1512) * Cursor location on the primary screen wasn't updated correctly if the window was resized while the alternate screen was active [#1512](https://github.com/wez/wezterm/issues/1512)
* Windows: latency issue with AltSnap and other window-managery things [#1013](https://github.com/wez/wezterm/issues/1013) [#1398](https://github.com/wez/wezterm/issues/1398) [#1075](https://github.com/wez/wezterm/issues/1075) [#1099](https://github.com/wez/wezterm/issues/1099) * Windows: latency issue with AltSnap and other window-managery things [#1013](https://github.com/wez/wezterm/issues/1013) [#1398](https://github.com/wez/wezterm/issues/1398) [#1075](https://github.com/wez/wezterm/issues/1075) [#1099](https://github.com/wez/wezterm/issues/1099)
* Multiplexer sessions now propagate user vars [#1528](https://github.com/wez/wezterm/issues/1528)
### 20220101-133340-7edc5b5a ### 20220101-133340-7edc5b5a

View File

@ -50,6 +50,11 @@ pub enum Alert {
TitleMaybeChanged, TitleMaybeChanged,
/// When the color palette has been updated /// When the color palette has been updated
PaletteChanged, PaletteChanged,
/// A UserVar has changed value
SetUserVar {
name: String,
value: String,
},
} }
pub trait AlertHandler { pub trait AlertHandler {

View File

@ -603,9 +603,9 @@ impl<'a> Performer<'a> {
OperatingSystemCommand::ITermProprietary(iterm) => match iterm { OperatingSystemCommand::ITermProprietary(iterm) => match iterm {
ITermProprietary::File(image) => self.set_image(*image), ITermProprietary::File(image) => self.set_image(*image),
ITermProprietary::SetUserVar { name, value } => { ITermProprietary::SetUserVar { name, value } => {
self.user_vars.insert(name, value); self.user_vars.insert(name.clone(), value.clone());
if let Some(handler) = self.alert_handler.as_mut() { if let Some(handler) = self.alert_handler.as_mut() {
handler.alert(Alert::TitleMaybeChanged); handler.alert(Alert::SetUserVar { name, value });
} }
} }
ITermProprietary::UnicodeVersion(ITermUnicodeVersionOp::Set(n)) => { ITermProprietary::UnicodeVersion(ITermUnicodeVersionOp::Set(n)) => {

View File

@ -15,6 +15,7 @@ use rangeset::RangeSet;
use ratelim::RateLimiter; use ratelim::RateLimiter;
use std::cell::RefCell; use std::cell::RefCell;
use std::cell::RefMut; use std::cell::RefMut;
use std::collections::HashMap;
use std::ops::Range; use std::ops::Range;
use std::rc::Rc; use std::rc::Rc;
use std::sync::Arc; use std::sync::Arc;
@ -36,6 +37,7 @@ pub struct ClientPane {
clipboard: RefCell<Option<Arc<dyn Clipboard>>>, clipboard: RefCell<Option<Arc<dyn Clipboard>>>,
mouse_grabbed: RefCell<bool>, mouse_grabbed: RefCell<bool>,
ignore_next_kill: RefCell<bool>, ignore_next_kill: RefCell<bool>,
user_vars: RefCell<HashMap<String, String>>,
} }
impl ClientPane { impl ClientPane {
@ -92,6 +94,7 @@ impl ClientPane {
clipboard: RefCell::new(None), clipboard: RefCell::new(None),
mouse_grabbed: RefCell::new(false), mouse_grabbed: RefCell::new(false),
ignore_next_kill: RefCell::new(false), ignore_next_kill: RefCell::new(false),
user_vars: RefCell::new(HashMap::new()),
} }
} }
@ -134,6 +137,14 @@ impl ClientPane {
} }
Pdu::NotifyAlert(NotifyAlert { alert, .. }) => { Pdu::NotifyAlert(NotifyAlert { alert, .. }) => {
let mux = Mux::get().unwrap(); let mux = Mux::get().unwrap();
match &alert {
Alert::SetUserVar { name, value } => {
self.user_vars
.borrow_mut()
.insert(name.clone(), value.clone());
}
_ => {}
}
mux.notify(MuxNotification::Alert { mux.notify(MuxNotification::Alert {
pane_id: self.local_pane_id, pane_id: self.local_pane_id,
alert, alert,
@ -418,6 +429,10 @@ impl Pane for ClientPane {
CloseReason::Pane => false, CloseReason::Pane => false,
} }
} }
fn copy_user_vars(&self) -> HashMap<String, String> {
self.user_vars.borrow().clone()
}
} }
struct PaneWriter { struct PaneWriter {

View File

@ -65,13 +65,9 @@ impl GuiFrontEnd {
} => { } => {
// Handled via TermWindowNotif; NOP it here. // Handled via TermWindowNotif; NOP it here.
} }
MuxNotification::Alert {
pane_id: _,
alert: Alert::PaletteChanged,
}
| MuxNotification::Alert { | MuxNotification::Alert {
pane_id: _, pane_id: _,
alert: Alert::TitleMaybeChanged, alert: Alert::PaletteChanged | Alert::TitleMaybeChanged | Alert::SetUserVar{..},
} => {} } => {}
MuxNotification::Empty => { MuxNotification::Empty => {
if mux::activity::Activity::count() == 0 { if mux::activity::Activity::count() == 0 {

View File

@ -921,7 +921,7 @@ impl TermWindow {
} }
TermWindowNotif::MuxNotification(n) => match n { TermWindowNotif::MuxNotification(n) => match n {
MuxNotification::Alert { MuxNotification::Alert {
alert: Alert::TitleMaybeChanged, alert: Alert::TitleMaybeChanged | Alert::SetUserVar { .. },
.. ..
} => { } => {
self.update_title(); self.update_title();

View File

@ -92,7 +92,7 @@ where
{ {
let per_pane = handler.per_pane(pane_id); let per_pane = handler.per_pane(pane_id);
let mut per_pane = per_pane.lock().unwrap(); let mut per_pane = per_pane.lock().unwrap();
per_pane.notifications.push(alert); per_pane.notifications.push(dbg!(alert));
} }
handler.schedule_pane_push(pane_id); handler.schedule_pane_push(pane_id);
} }