Allow reloading hyperlink rules from the config at runtime
This commit is contained in:
1 parent
7c7825c070
commit
fd78a0b3ce
7 files changed
+49
-11
No files matched your search
@@ -1,12 +1,22 @@
|
||||
//! Bridge our gui config into the terminal crate configuration
|
||||
|
||||
use crate::config::configuration;
|
||||
use termwiz::hyperlink::Rule as HyperlinkRule;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct TermConfig;
|
||||
|
||||
impl term::TerminalConfiguration for TermConfig {
|
||||
fn generation(&self) -> usize {
|
||||
configuration().generation()
|
||||
}
|
||||
|
||||
fn scrollback_size(&self) -> usize {
|
||||
configuration().scrollback_lines
|
||||
}
|
||||
|
||||
fn hyperlink_rules(&self) -> (usize, Vec<HyperlinkRule>) {
|
||||
let config = configuration();
|
||||
(config.generation(), config.hyperlink_rules.clone())
|
||||
}
|
||||
}
|
||||
@@ -100,7 +100,6 @@ impl Domain for LocalDomain {
|
||||
size.cols as usize,
|
||||
size.pixel_width as usize,
|
||||
size.pixel_height as usize,
|
||||
config.hyperlink_rules.clone(),
|
||||
std::sync::Arc::new(crate::config::TermConfig {}),
|
||||
);
|
||||
|
||||
|
||||
@@ -345,14 +345,11 @@ impl Domain for RemoteSshDomain {
|
||||
let child = pair.slave.spawn_command(cmd)?;
|
||||
log::info!("spawned: {:?}", child);
|
||||
|
||||
let config = configuration();
|
||||
|
||||
let mut terminal = term::Terminal::new(
|
||||
size.rows as usize,
|
||||
size.cols as usize,
|
||||
size.pixel_width as usize,
|
||||
size.pixel_height as usize,
|
||||
config.hyperlink_rules.clone(),
|
||||
std::sync::Arc::new(crate::config::TermConfig {}),
|
||||
);
|
||||
|
||||
|
||||
+15
-1
@@ -1,4 +1,15 @@
|
||||
use termwiz::hyperlink::Rule as HyperlinkRule;
|
||||
|
||||
pub trait TerminalConfiguration: std::fmt::Debug {
|
||||
/// Returns a generation counter for the active
|
||||
/// configuration. If the implementation may be
|
||||
/// changed at runtime, it must increment the generation
|
||||
/// number with each change so that any caches maintained
|
||||
/// by the terminal can be flushed.
|
||||
fn generation(&self) -> usize {
|
||||
0
|
||||
}
|
||||
|
||||
fn scrollback_size(&self) -> usize {
|
||||
3500
|
||||
}
|
||||
@@ -22,5 +33,8 @@ pub trait TerminalConfiguration: std::fmt::Debug {
|
||||
true
|
||||
}
|
||||
|
||||
// fn hyperlink_rules(&self) -> &Vec<HyperlinkRule>;
|
||||
/// Returns the current generation and its associated hyperlink rules.
|
||||
fn hyperlink_rules(&self) -> (usize, Vec<HyperlinkRule>) {
|
||||
(self.generation(), vec![])
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ use super::*;
|
||||
use failure::Fallible;
|
||||
use std::sync::Arc;
|
||||
use termwiz::escape::parser::Parser;
|
||||
use termwiz::hyperlink::Rule as HyperlinkRule;
|
||||
|
||||
pub trait Clipboard {
|
||||
fn get_contents(&self) -> Fallible<String>;
|
||||
@@ -72,7 +71,6 @@ impl Terminal {
|
||||
physical_cols: usize,
|
||||
pixel_width: usize,
|
||||
pixel_height: usize,
|
||||
hyperlink_rules: Vec<HyperlinkRule>,
|
||||
config: Arc<dyn TerminalConfiguration>,
|
||||
) -> Terminal {
|
||||
Terminal {
|
||||
@@ -81,7 +79,6 @@ impl Terminal {
|
||||
physical_cols,
|
||||
pixel_height,
|
||||
pixel_width,
|
||||
hyperlink_rules,
|
||||
config,
|
||||
),
|
||||
parser: Parser::new(),
|
||||
|
||||
@@ -209,8 +209,8 @@ pub struct TerminalState {
|
||||
|
||||
tabs: TabStop,
|
||||
|
||||
/// FIXME: replace hyperlink_rules with config access
|
||||
hyperlink_rules: Vec<HyperlinkRule>,
|
||||
hyperlink_rules_generation: usize,
|
||||
|
||||
/// The terminal title string
|
||||
title: String,
|
||||
@@ -260,11 +260,12 @@ impl TerminalState {
|
||||
physical_cols: usize,
|
||||
pixel_width: usize,
|
||||
pixel_height: usize,
|
||||
hyperlink_rules: Vec<HyperlinkRule>,
|
||||
config: Arc<dyn TerminalConfiguration>,
|
||||
) -> TerminalState {
|
||||
let screen = ScreenOrAlt::new(physical_rows, physical_cols, &config);
|
||||
|
||||
let (hyperlink_rules_generation, hyperlink_rules) = config.hyperlink_rules();
|
||||
|
||||
TerminalState {
|
||||
config,
|
||||
screen,
|
||||
@@ -289,6 +290,7 @@ impl TerminalState {
|
||||
selection_start: None,
|
||||
tabs: TabStop::new(physical_cols, 8),
|
||||
hyperlink_rules,
|
||||
hyperlink_rules_generation,
|
||||
title: "wezterm".to_string(),
|
||||
palette: ColorPalette::default(),
|
||||
pixel_height,
|
||||
@@ -440,9 +442,29 @@ impl TerminalState {
|
||||
}
|
||||
}
|
||||
|
||||
/// If the configuration changed, obtain the new hyperlink rules
|
||||
/// from it and invalidate any implicit hyperlinks so that we
|
||||
/// re-apply the rules to the display
|
||||
fn refresh_hyperlink_rules(&mut self) {
|
||||
if self.config.generation() != self.hyperlink_rules_generation {
|
||||
let (generation, rules) = self.config.hyperlink_rules();
|
||||
self.hyperlink_rules = rules;
|
||||
self.hyperlink_rules_generation = generation;
|
||||
|
||||
// dirty all lines as any of them may have changed
|
||||
// their hyperlinkyness
|
||||
let screen = self.screen_mut();
|
||||
for line in &mut screen.lines {
|
||||
line.invalidate_implicit_hyperlinks();
|
||||
line.set_dirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Called after a mouse move or viewport scroll to recompute the
|
||||
/// current highlight
|
||||
fn recompute_highlight(&mut self) {
|
||||
self.refresh_hyperlink_rules();
|
||||
let line_idx = self.mouse_position.y as ScrollbackOrVisibleRowIndex
|
||||
- self.viewport_offset as ScrollbackOrVisibleRowIndex;
|
||||
let x = self.mouse_position.x;
|
||||
|
||||
@@ -104,7 +104,6 @@ impl TestTerm {
|
||||
width,
|
||||
height * 16,
|
||||
width * 8,
|
||||
Vec::new(),
|
||||
Arc::new(TestTermConfig { scrollback }),
|
||||
),
|
||||
host: TestHost::new(),
|
||||
|
||||
Reference in new issue
Block a user