1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-22 12:51:31 +03:00

Change cell api to avoid direct access to hyperlink/image

This allows potentially changing the struct layout
to reduce the struct size.
This commit is contained in:
Wez Furlong 2020-10-11 13:09:24 -07:00
parent 96c4750a30
commit 2a87c1dec7
11 changed files with 38 additions and 25 deletions

2
Cargo.lock generated
View File

@ -3518,7 +3518,7 @@ dependencies = [
[[package]]
name = "termwiz"
version = "0.10.0"
version = "0.11.0"
dependencies = [
"anyhow",
"base64 0.10.1",

View File

@ -743,7 +743,8 @@ impl From<Vec<(StableRowIndex, Line)>> 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(&current, &link) => {
// Continue the current streak

View File

@ -9,4 +9,4 @@ license = "MIT"
documentation = "https://docs.rs/tabout"
[dependencies]
termwiz = { path = "../termwiz", version="0.10"}
termwiz = { path = "../termwiz", version="0.11"}

View File

@ -31,5 +31,5 @@ pretty_assertions = "0.6"
pretty_env_logger = "0.4"
[dependencies.termwiz]
version = "0.10"
version = "0.11"
path = "../termwiz"

View File

@ -1213,10 +1213,10 @@ impl TerminalState {
}
fn set_hyperlink(&mut self, link: Option<Hyperlink>) {
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<Sixel>) {
@ -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);

View File

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

View File

@ -23,9 +23,9 @@ pub struct CellAttributes {
/// The background color
pub background: ColorAttribute,
/// The hyperlink content, if any
pub hyperlink: Option<Arc<Hyperlink>>,
hyperlink: Option<Arc<Hyperlink>>,
/// The image data, if any
pub image: Option<Box<ImageCell>>,
image: Option<Box<ImageCell>>,
}
/// Define getter and setter for the attributes bitfield.
@ -198,6 +198,14 @@ impl CellAttributes {
image: None,
}
}
pub fn hyperlink(&self) -> Option<&Arc<Hyperlink>> {
self.hyperlink.as_ref()
}
pub fn image(&self) -> Option<&ImageCell> {
self.image.as_ref().map(|im| im.as_ref())
}
}
#[cfg(feature = "use_serde")]

View File

@ -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());

View File

@ -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);

View File

@ -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());
}
}
}

View File

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