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

memoize the renderer used for termwiztermtab and custom tab bars

Create only one, then just clone as needed.

refs: #817
This commit is contained in:
Wez Furlong 2021-06-13 08:04:16 -07:00
parent d1d7def1a1
commit 3ea030794b
3 changed files with 13 additions and 30 deletions

View File

@ -259,11 +259,10 @@ pub fn make_lua_context(config_file: &Path) -> anyhow::Result<Lua> {
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)]

View File

@ -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,

View File

@ -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<dyn Pane>) {
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<dyn Pane>) {
(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 {