1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-22 13:16:39 +03:00

add Pane::get_metadata

The idea here is that different kinds of panes may want to expose
additional metadata to lua scripts. It would be a bit weird to add
a Pane method for each of those and plumb it all the way through
the various APIs, so just allowing a pane impl to return a dynamic
value (likely an Object) allows a bunch of flexibility.

This commit exposes the clientpane is_tardy boolean and the time
since the last data was recevied (since_last_response_ms) from
the mux client pane implementation: these are used to show the
tardiness indicator in the client pane.

Exposing this data enables the user to add that info to their
status bar if they wish.
This commit is contained in:
Wez Furlong 2022-09-01 21:27:49 -07:00
parent 8adc78b587
commit 14c613a064
6 changed files with 33 additions and 2 deletions

1
Cargo.lock generated
View File

@ -5420,6 +5420,7 @@ dependencies = [
"uds_windows",
"umask",
"url",
"wezterm-dynamic",
"wezterm-ssh",
"wezterm-term",
"winapi",

View File

@ -14,6 +14,7 @@ use termwiz::hyperlink::Rule;
use termwiz::input::KeyboardEncoding;
use termwiz::surface::{Line, SequenceNo};
use url::Url;
use wezterm_dynamic::Value;
use wezterm_term::color::ColorPalette;
use wezterm_term::{
Clipboard, DownloadHandler, KeyCode, KeyModifiers, MouseEvent, SemanticZone, StableRowIndex,
@ -204,6 +205,11 @@ pub trait Pane: Downcast {
fn get_current_seqno(&self) -> SequenceNo;
/// Returns misc metadata that is pane-specific
fn get_metadata(&self) -> Value {
Value::Null
}
/// Given a range of lines, return the subset of those lines that
/// have changed since the supplied sequence no.
fn get_changed_since(

View File

@ -37,6 +37,7 @@ textwrap = "0.15"
thiserror = "1.0"
umask = { path = "../umask" }
url = "2"
wezterm-dynamic = { path = "../wezterm-dynamic" }
wezterm-ssh = { path = "../wezterm-ssh" }
wezterm-term = { path = "../term", features=["use_serde"] }

View File

@ -16,13 +16,14 @@ use mux::{Mux, MuxNotification};
use rangeset::RangeSet;
use ratelim::RateLimiter;
use std::cell::{RefCell, RefMut};
use std::collections::HashMap;
use std::collections::{BTreeMap, HashMap};
use std::ops::Range;
use std::rc::Rc;
use std::sync::Arc;
use termwiz::input::KeyEvent;
use termwiz::surface::SequenceNo;
use url::Url;
use wezterm_dynamic::Value;
use wezterm_term::color::ColorPalette;
use wezterm_term::{
Alert, Clipboard, KeyCode, KeyModifiers, Line, MouseEvent, StableRowIndex, TerminalSize,
@ -195,6 +196,23 @@ impl Pane for ClientPane {
self.local_pane_id
}
fn get_metadata(&self) -> Value {
let renderable = self.renderable.borrow();
let inner = renderable.inner.borrow();
let mut map: BTreeMap<Value, Value> = BTreeMap::new();
map.insert(
Value::String("is_tardy".to_string()),
Value::Bool(inner.is_tardy()),
);
map.insert(
Value::String("since_last_response_ms".to_string()),
Value::U64(inner.last_recv_time.elapsed().as_millis() as u64),
);
Value::Object(map.into())
}
fn get_cursor_position(&self) -> StableCursorPosition {
self.renderable.borrow().get_cursor_position()
}

View File

@ -72,7 +72,7 @@ pub struct RenderableInner {
fetch_limiter: RateLimiter,
last_send_time: Instant,
last_recv_time: Instant,
pub last_recv_time: Instant,
last_late_dirty: Instant,
last_input_rtt: u64,

View File

@ -1,6 +1,7 @@
//! PaneObject represents a Mux Pane instance in lua code
use super::luaerr;
use anyhow::anyhow;
use luahelper::dynamic_to_lua_value;
use mlua::{UserData, UserDataMethods};
use mux::pane::{Pane, PaneId};
use mux::Mux;
@ -48,6 +49,10 @@ impl UserData for PaneObject {
.get_current_working_dir()
.map(|u| u.to_string()))
});
methods.add_method("get_metadata", |lua, this, _: ()| {
let value = this.pane()?.get_metadata();
dynamic_to_lua_value(lua, value)
});
methods.add_method("get_foreground_process_name", |_, this, _: ()| {
Ok(this.pane()?.get_foreground_process_name())
});