Add support for iTerm2's SetUserVar escape
This doesn't propagate across wezterm's mux protocol at this time. refs: https://github.com/wez/wezterm/issues/647 https://iterm2.com/documentation-scripting-fundamentals.html#setting-user-defined-variables
This commit is contained in:
1 parent
1cb2856223
commit
87677a73bf
7 files changed
+48
-1
No files matched your search
@@ -18,3 +18,5 @@ The `PaneInformation` struct contains the following fields:
|
||||
* `pixel_width` - the width of the pane in pixels
|
||||
* `pixel_height` - the height of the pane in pixels
|
||||
* `title` - the title of the pane, per [pane:get_title()](pane/get_title.md) at the time the pane information was captured
|
||||
* `user_vars` - the user variables defined for the pane, per [pane:get_user_vars()](pane/get_user_vars.md) at the time the pane information was captured.
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# `pane:get_user_vars()`
|
||||
|
||||
*Since: nightly builds only*
|
||||
|
||||
Returns a table holding the user variables that have been assigned
|
||||
to this pane.
|
||||
|
||||
User variables are set using an escape sequence defined by iterm2, but
|
||||
also recognized by wezterm; this example sets the `foo` user variable
|
||||
to the value `bar`:
|
||||
|
||||
```bash
|
||||
printf "\033]1337;SetUserVar=%s=%s\007" foo `echo -n bar | base64`
|
||||
```
|
||||
|
||||
you're then able to access this in your wezterm config:
|
||||
|
||||
```lua
|
||||
wezterm.log_info("foo var is " .. pane:get_user_vars().foo)
|
||||
```
|
||||
|
||||
@@ -10,7 +10,7 @@ use config::{configuration, ExitBehavior};
|
||||
use portable_pty::{Child, MasterPty, PtySize};
|
||||
use rangeset::RangeSet;
|
||||
use std::cell::{RefCell, RefMut};
|
||||
use std::collections::HashSet;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::ops::Range;
|
||||
use std::sync::Arc;
|
||||
use termwiz::escape::DeviceControlMode;
|
||||
@@ -86,6 +86,10 @@ impl Pane for LocalPane {
|
||||
terminal_get_dimensions(&mut self.terminal.borrow_mut())
|
||||
}
|
||||
|
||||
fn copy_user_vars(&self) -> HashMap<String, String> {
|
||||
self.terminal.borrow().user_vars().clone()
|
||||
}
|
||||
|
||||
fn kill(&self) {
|
||||
let mut proc = self.process.borrow_mut();
|
||||
log::debug!(
|
||||
|
||||
@@ -8,6 +8,7 @@ use portable_pty::PtySize;
|
||||
use rangeset::RangeSet;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::cell::RefMut;
|
||||
use std::collections::HashMap;
|
||||
use std::ops::Range;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use termwiz::hyperlink::Rule;
|
||||
@@ -299,6 +300,10 @@ pub trait Pane: Downcast {
|
||||
fn palette(&self) -> ColorPalette;
|
||||
fn domain_id(&self) -> DomainId;
|
||||
|
||||
fn copy_user_vars(&self) -> HashMap<String, String> {
|
||||
HashMap::new()
|
||||
}
|
||||
|
||||
fn erase_scrollback(&self, _erase_mode: ScrollbackEraseMode) {}
|
||||
|
||||
/// Called to advise on whether this tab has focus
|
||||
|
||||
@@ -301,6 +301,8 @@ pub struct TerminalState {
|
||||
writer: Box<dyn std::io::Write>,
|
||||
|
||||
image_cache: lru::LruCache<[u8; 32], Arc<ImageData>>,
|
||||
|
||||
user_vars: HashMap<String, String>,
|
||||
}
|
||||
|
||||
fn encode_modifiers(mods: KeyModifiers) -> u8 {
|
||||
@@ -489,6 +491,7 @@ impl TerminalState {
|
||||
term_version: term_version.to_string(),
|
||||
writer: Box::new(std::io::BufWriter::new(writer)),
|
||||
image_cache: lru::LruCache::new(16),
|
||||
user_vars: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1212,6 +1215,10 @@ impl TerminalState {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn user_vars(&self) -> &HashMap<String, String> {
|
||||
&self.user_vars
|
||||
}
|
||||
|
||||
/// Sets the cursor position to precisely the x and values provided
|
||||
fn set_cursor_position_absolute(&mut self, x: usize, y: VisibleRowIndex) {
|
||||
let old_y = self.cursor.y;
|
||||
@@ -3300,6 +3307,9 @@ impl<'a> Performer<'a> {
|
||||
}
|
||||
OperatingSystemCommand::ITermProprietary(iterm) => match iterm {
|
||||
ITermProprietary::File(image) => self.set_image(*image),
|
||||
ITermProprietary::SetUserVar { name, value } => {
|
||||
self.user_vars.insert(name, value);
|
||||
}
|
||||
_ => log::warn!("unhandled iterm2: {:?}", iterm),
|
||||
},
|
||||
|
||||
|
||||
@@ -48,6 +48,9 @@ impl UserData for PaneObject {
|
||||
methods.add_method("get_dimensions", |_, this, _: ()| {
|
||||
Ok(this.pane()?.get_dimensions())
|
||||
});
|
||||
methods.add_method("get_user_vars", |_, this, _: ()| {
|
||||
Ok(this.pane()?.copy_user_vars())
|
||||
});
|
||||
|
||||
// When called with no arguments, returns the lines from the
|
||||
// viewport as plain text (no escape sequences).
|
||||
|
||||
@@ -109,6 +109,7 @@ pub struct PaneInformation {
|
||||
pub pixel_width: usize,
|
||||
pub pixel_height: usize,
|
||||
pub title: String,
|
||||
pub user_vars: HashMap<String, String>,
|
||||
}
|
||||
impl_lua_conversion!(PaneInformation);
|
||||
|
||||
@@ -1857,6 +1858,7 @@ impl TermWindow {
|
||||
pixel_width: pos.pixel_width,
|
||||
pixel_height: pos.pixel_height,
|
||||
title: pos.pane.get_title(),
|
||||
user_vars: pos.pane.copy_user_vars(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user