From 3ea030794b158e3d02b6cca1e3cc3eb9bd544b1d Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 13 Jun 2021 08:04:16 -0700 Subject: [PATCH] memoize the renderer used for termwiztermtab and custom tab bars Create only one, then just clone as needed. refs: #817 --- config/src/lua.rs | 17 ++++++++++------- mux/src/ssh.rs | 2 +- mux/src/termwiztermtab.rs | 24 ++---------------------- 3 files changed, 13 insertions(+), 30 deletions(-) diff --git a/config/src/lua.rs b/config/src/lua.rs index 56eb0e0bc..66e76748c 100644 --- a/config/src/lua.rs +++ b/config/src/lua.rs @@ -259,11 +259,10 @@ pub fn make_lua_context(config_file: &Path) -> anyhow::Result { use termwiz::caps::{Capabilities, ColorLevel, ProbeHints}; use termwiz::render::terminfo::TerminfoRenderer; -fn new_wezterm_terminfo_renderer() -> TerminfoRenderer { - let data = include_bytes!("../../termwiz/data/xterm-256color"); - let db = terminfo::Database::from_buffer(&data[..]).unwrap(); - - TerminfoRenderer::new( +lazy_static::lazy_static! { + static ref CAPS: Capabilities = { + let data = include_bytes!("../../termwiz/data/xterm-256color"); + let db = terminfo::Database::from_buffer(&data[..]).unwrap(); Capabilities::new_with_hints( ProbeHints::new_from_env() .term(Some("xterm-256color".into())) @@ -274,8 +273,12 @@ fn new_wezterm_terminfo_renderer() -> TerminfoRenderer { .term_program(Some("WezTerm".into())) .term_program_version(Some(crate::wezterm_version().into())), ) - .expect("cannot fail to make internal Capabilities"), - ) + .expect("cannot fail to make internal Capabilities") + }; +} + +pub fn new_wezterm_terminfo_renderer() -> TerminfoRenderer { + TerminfoRenderer::new(CAPS.clone()) } #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)] diff --git a/mux/src/ssh.rs b/mux/src/ssh.rs index d01243a1f..fd44f1d62 100644 --- a/mux/src/ssh.rs +++ b/mux/src/ssh.rs @@ -300,7 +300,7 @@ fn connect_ssh_session( } } - let renderer = crate::termwiztermtab::new_wezterm_terminfo_renderer(); + let renderer = config::lua::new_wezterm_terminfo_renderer(); let mut shim = TerminalShim { stdout: &mut StdoutShim { stdout: stdout_write, diff --git a/mux/src/termwiztermtab.rs b/mux/src/termwiztermtab.rs index d6a5371b9..2b3a2f98c 100644 --- a/mux/src/termwiztermtab.rs +++ b/mux/src/termwiztermtab.rs @@ -24,7 +24,6 @@ use std::ops::Range; use std::rc::Rc; use std::sync::Arc; use std::time::Duration; -use termwiz::caps::{Capabilities, ColorLevel, ProbeHints}; use termwiz::input::{InputEvent, KeyEvent, Modifiers, MouseEvent as TermWizMouseEvent}; use termwiz::render::terminfo::TerminfoRenderer; use termwiz::surface::Change; @@ -408,7 +407,7 @@ pub fn allocate(size: PtySize) -> (TermWizTerminal, Rc) { let (input_tx, input_rx) = channel(); - let renderer = new_wezterm_terminfo_renderer(); + let renderer = config::lua::new_wezterm_terminfo_renderer(); let tw_term = TermWizTerminal { render_tx: TermWizTerminalRenderTty { @@ -437,25 +436,6 @@ pub fn allocate(size: PtySize) -> (TermWizTerminal, Rc) { (tw_term, pane) } -pub(crate) fn new_wezterm_terminfo_renderer() -> TerminfoRenderer { - let data = include_bytes!("../../termwiz/data/xterm-256color"); - let db = terminfo::Database::from_buffer(&data[..]).unwrap(); - - TerminfoRenderer::new( - Capabilities::new_with_hints( - ProbeHints::new_from_env() - .term(Some("xterm-256color".into())) - .terminfo_db(Some(db)) - .color_level(Some(ColorLevel::TrueColor)) - .colorterm(None) - .colorterm_bce(None) - .term_program(Some("WezTerm".into())) - .term_program_version(Some(config::wezterm_version().into())), - ) - .expect("cannot fail to make internal Capabilities"), - ) -} - /// This function spawns a thread and constructs a GUI window with an /// associated termwiz Terminal object to execute the provided function. /// The function is expected to run in a loop to manage input and output @@ -473,7 +453,7 @@ pub async fn run< let render_rx = render_pipe.read; let (input_tx, input_rx) = channel(); - let renderer = new_wezterm_terminfo_renderer(); + let renderer = config::lua::new_wezterm_terminfo_renderer(); let tw_term = TermWizTerminal { render_tx: TermWizTerminalRenderTty {