diff --git a/Cargo.lock b/Cargo.lock index 7a400f06f..35ecb0dac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3518,7 +3518,7 @@ dependencies = [ [[package]] name = "termwiz" -version = "0.10.0" +version = "0.11.0" dependencies = [ "anyhow", "base64 0.10.1", diff --git a/codec/src/lib.rs b/codec/src/lib.rs index d24530e58..1ba38dc95 100644 --- a/codec/src/lib.rs +++ b/codec/src/lib.rs @@ -743,7 +743,8 @@ impl From> for SerializedLines { { // Unset the hyperlink on the cell, if any, and record that // in the hyperlinks data for later restoration. - if let Some(link) = cell.attrs_mut().hyperlink.take() { + if let Some(link) = cell.attrs_mut().hyperlink().map(Arc::clone) { + cell.attrs_mut().set_hyperlink(None); match current_link.as_ref() { Some(current) if Arc::ptr_eq(¤t, &link) => { // Continue the current streak diff --git a/tabout/Cargo.toml b/tabout/Cargo.toml index 7fa820906..771c4feb6 100644 --- a/tabout/Cargo.toml +++ b/tabout/Cargo.toml @@ -9,4 +9,4 @@ license = "MIT" documentation = "https://docs.rs/tabout" [dependencies] -termwiz = { path = "../termwiz", version="0.10"} +termwiz = { path = "../termwiz", version="0.11"} diff --git a/term/Cargo.toml b/term/Cargo.toml index 02e3cc430..6764e1b5f 100644 --- a/term/Cargo.toml +++ b/term/Cargo.toml @@ -31,5 +31,5 @@ pretty_assertions = "0.6" pretty_env_logger = "0.4" [dependencies.termwiz] -version = "0.10" +version = "0.11" path = "../termwiz" diff --git a/term/src/terminalstate.rs b/term/src/terminalstate.rs index 5e45c3962..837b7d94b 100644 --- a/term/src/terminalstate.rs +++ b/term/src/terminalstate.rs @@ -1213,10 +1213,10 @@ impl TerminalState { } fn set_hyperlink(&mut self, link: Option) { - self.pen.hyperlink = match link { + self.pen.set_hyperlink(match link { Some(hyperlink) => Some(Arc::new(hyperlink)), None => None, - } + }); } fn sixel(&mut self, sixel: Box) { @@ -2424,9 +2424,9 @@ impl TerminalState { debug!("{:?}", sgr); match sgr { Sgr::Reset => { - let link = self.pen.hyperlink.take(); + let link = self.pen.hyperlink().map(Arc::clone); self.pen = CellAttributes::default(); - self.pen.hyperlink = link; + self.pen.set_hyperlink(link); } Sgr::Intensity(intensity) => { self.pen.set_intensity(intensity); diff --git a/termwiz/Cargo.toml b/termwiz/Cargo.toml index a1e344302..d27e374c0 100644 --- a/termwiz/Cargo.toml +++ b/termwiz/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["Wez Furlong"] name = "termwiz" -version = "0.10.0" +version = "0.11.0" edition = "2018" repository = "https://github.com/wez/wezterm" description = "Terminal Wizardry for Unix and Windows" diff --git a/termwiz/src/cell.rs b/termwiz/src/cell.rs index ee02093ff..63beebefd 100644 --- a/termwiz/src/cell.rs +++ b/termwiz/src/cell.rs @@ -23,9 +23,9 @@ pub struct CellAttributes { /// The background color pub background: ColorAttribute, /// The hyperlink content, if any - pub hyperlink: Option>, + hyperlink: Option>, /// The image data, if any - pub image: Option>, + image: Option>, } /// Define getter and setter for the attributes bitfield. @@ -198,6 +198,14 @@ impl CellAttributes { image: None, } } + + pub fn hyperlink(&self) -> Option<&Arc> { + self.hyperlink.as_ref() + } + + pub fn image(&self) -> Option<&ImageCell> { + self.image.as_ref().map(|im| im.as_ref()) + } } #[cfg(feature = "use_serde")] diff --git a/termwiz/src/render/terminfo.rs b/termwiz/src/render/terminfo.rs index c3fb9d672..3b49d5f75 100644 --- a/termwiz/src/render/terminfo.rs +++ b/termwiz/src/render/terminfo.rs @@ -188,10 +188,10 @@ impl TerminfoRenderer { } if self.caps.hyperlinks() { - if let Some(link) = attr.hyperlink.as_ref() { + if let Some(link) = attr.hyperlink() { let osc = OperatingSystemCommand::SetHyperlink(Some((**link).clone())); write!(out, "{}", osc)?; - } else if self.current_attr.hyperlink.is_some() { + } else if self.current_attr.hyperlink().is_some() { // Close out the old hyperlink let osc = OperatingSystemCommand::SetHyperlink(None); write!(out, "{}", osc)?; @@ -436,7 +436,9 @@ impl TerminfoRenderer { self.attr_apply(|attr| attr.background = *col); } Change::Attribute(AttributeChange::Hyperlink(link)) => { - self.attr_apply(|attr| attr.hyperlink = link.clone()); + self.attr_apply(|attr| { + attr.set_hyperlink(link.clone()); + }); } Change::AllAttributes(all) => { self.pending_attr = Some(all.clone()); diff --git a/termwiz/src/surface/line.rs b/termwiz/src/surface/line.rs index 9f4a90db6..71597fc34 100644 --- a/termwiz/src/surface/line.rs +++ b/termwiz/src/surface/line.rs @@ -151,7 +151,7 @@ impl Line { } for cell in &mut self.cells { - let replace = match cell.attrs().hyperlink { + let replace = match cell.attrs().hyperlink() { Some(ref link) if link.is_implicit() => Some(Cell::new_grapheme( cell.str(), cell.attrs().clone().set_hyperlink(None).clone(), @@ -208,7 +208,7 @@ impl Line { if m.range.contains(&byte_idx) { let attrs = cell.attrs_mut(); // Don't replace existing links - if !attrs.hyperlink.is_some() { + if !attrs.hyperlink().is_some() { attrs.set_hyperlink(Some(Arc::clone(&m.link))); self.bits |= LineBits::HAS_IMPLICIT_HYPERLINKS; } @@ -298,7 +298,7 @@ impl Line { self.invalidate_implicit_hyperlinks(); self.bits |= LineBits::DIRTY; - if cell.attrs().hyperlink.is_some() { + if cell.attrs().hyperlink().is_some() { self.bits |= LineBits::HAS_HYPERLINK; } self.invalidate_grapheme_at_or_before(idx); diff --git a/termwiz/src/surface/mod.rs b/termwiz/src/surface/mod.rs index a640c1175..46753b0ff 100644 --- a/termwiz/src/surface/mod.rs +++ b/termwiz/src/surface/mod.rs @@ -482,7 +482,9 @@ impl Surface { } Foreground(value) => self.attributes.foreground = *value, Background(value) => self.attributes.background = *value, - Hyperlink(value) => self.attributes.hyperlink = value.clone(), + Hyperlink(value) => { + self.attributes.set_hyperlink(value.clone()); + } } } diff --git a/wezterm/src/gui/termwindow.rs b/wezterm/src/gui/termwindow.rs index 49d2deb3f..bebb5ebf4 100644 --- a/wezterm/src/gui/termwindow.rs +++ b/wezterm/src/gui/termwindow.rs @@ -2751,8 +2751,8 @@ impl TermWindow { let mut last_cell_idx = 0; for cluster in cell_clusters { let attrs = &cluster.attrs; - let is_highlited_hyperlink = match (&attrs.hyperlink, &self.current_highlight) { - (&Some(ref this), &Some(ref highlight)) => Arc::ptr_eq(this, highlight), + let is_highlited_hyperlink = match (attrs.hyperlink(), &self.current_highlight) { + (Some(ref this), &Some(ref highlight)) => Arc::ptr_eq(this, highlight), _ => false, }; let style = self.fonts.match_style(params.config, attrs); @@ -2875,7 +2875,7 @@ impl TermWindow { params.pos.is_active, ); - if let Some(image) = attrs.image.as_ref() { + if let Some(image) = attrs.image() { // Render iTerm2 style image attributes if let Ok(sprite) = gl_state @@ -3046,8 +3046,8 @@ impl TermWindow { let mut last_cell_idx = 0; for cluster in cell_clusters { let attrs = &cluster.attrs; - let is_highlited_hyperlink = match (&attrs.hyperlink, &self.current_highlight) { - (&Some(ref this), &Some(ref highlight)) => this == highlight, + let is_highlited_hyperlink = match (attrs.hyperlink(), &self.current_highlight) { + (Some(ref this), &Some(ref highlight)) => *this == highlight, _ => false, }; let style = self.fonts.match_style(&config, attrs); @@ -3194,7 +3194,7 @@ impl TermWindow { Operator::MultiplyThenOver(glyph_color) }, ); - } else if let Some(image) = attrs.image.as_ref() { + } else if let Some(image) = attrs.image() { // Render iTerm2 style image attributes let software = self.render_state.software(); if let Ok(sprite) = software @@ -3726,7 +3726,7 @@ impl TermWindow { let new_highlight = if top == stable_row { if let Some(line) = lines.get_mut(0) { if let Some(cell) = line.cells().get(x) { - cell.attrs().hyperlink.as_ref().cloned() + cell.attrs().hyperlink().cloned() } else { None }