aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAyose <ayosec@gmail.com>2022-07-12 13:38:05 +0100
committerAyose <ayosec@gmail.com>2022-07-12 13:38:05 +0100
commit48b2610a7ac8c1ea22d6d1fff5208966e5efa574 (patch)
tree276af968b0ffa220b9ea40887215863af0c85732
parenta919ac7d1e6d1ec5729ac08d25351ea0d6446145 (diff)
downloadr-alacritty-48b2610a7ac8c1ea22d6d1fff5208966e5efa574.tar.gz
r-alacritty-48b2610a7ac8c1ea22d6d1fff5208966e5efa574.tar.bz2
r-alacritty-48b2610a7ac8c1ea22d6d1fff5208966e5efa574.zip
Fill all cells under a graphic with the template.
With the template we can create hyperlinks attached to the graphic. To avoid reflow issues when a row is shrank, wrapped rows that only contain graphic cells are discarded. With this approach we loss some info, like the hyperlink, but the image is always properly positioned in the grid.
-rw-r--r--alacritty/src/renderer/graphics/draw.rs29
-rw-r--r--alacritty/src/renderer/rects.rs4
-rw-r--r--alacritty_terminal/src/grid/row.rs4
-rw-r--r--alacritty_terminal/src/term/mod.rs10
4 files changed, 29 insertions, 18 deletions
diff --git a/alacritty/src/renderer/graphics/draw.rs b/alacritty/src/renderer/graphics/draw.rs
index 0bc4b3ec..cb61562f 100644
--- a/alacritty/src/renderer/graphics/draw.rs
+++ b/alacritty/src/renderer/graphics/draw.rs
@@ -39,21 +39,24 @@ impl RenderList {
/// The graphic is added only the first time it is found in a cell.
#[inline]
pub fn update(&mut self, cell: &RenderableCell) {
- if let Some(graphic) = cell.extra.as_ref().and_then(|cell| cell.graphic.as_ref()) {
- let graphic_id = graphic.graphic_id();
- if self.items.contains_key(&graphic_id) {
- return;
- }
+ let graphic = match cell.extra.as_ref().and_then(|cell| cell.graphic.as_ref()) {
+ Some(graphic) => graphic,
+ _ => return,
+ };
+
+ let graphic_id = graphic.graphic_id();
+ if self.items.contains_key(&graphic_id) {
+ return;
+ }
- let render_item = RenderPosition {
- column: cell.point.column,
- line: cell.point.line,
- offset_x: graphic.offset_x,
- offset_y: graphic.offset_y,
- };
+ let render_item = RenderPosition {
+ column: cell.point.column,
+ line: cell.point.line,
+ offset_x: graphic.offset_x,
+ offset_y: graphic.offset_y,
+ };
- self.items.insert(graphic_id, render_item);
- }
+ self.items.insert(graphic_id, render_item);
}
/// Returns `true` if there are no items to render.
diff --git a/alacritty/src/renderer/rects.rs b/alacritty/src/renderer/rects.rs
index 73ca2c94..113eaab5 100644
--- a/alacritty/src/renderer/rects.rs
+++ b/alacritty/src/renderer/rects.rs
@@ -179,6 +179,10 @@ impl RenderLines {
/// Update the stored lines with the next cell info.
#[inline]
pub fn update(&mut self, cell: &RenderableCell) {
+ if cell.flags.contains(Flags::GRAPHICS) {
+ return;
+ }
+
self.update_flag(cell, Flags::UNDERLINE);
self.update_flag(cell, Flags::DOUBLE_UNDERLINE);
self.update_flag(cell, Flags::STRIKEOUT);
diff --git a/alacritty_terminal/src/grid/row.rs b/alacritty_terminal/src/grid/row.rs
index 900d2a76..f1bb6adb 100644
--- a/alacritty_terminal/src/grid/row.rs
+++ b/alacritty_terminal/src/grid/row.rs
@@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
use crate::grid::GridCell;
use crate::index::Column;
-use crate::term::cell::ResetDiscriminant;
+use crate::term::cell::{Flags, ResetDiscriminant};
/// A row in the grid.
#[derive(Serialize, Deserialize, Default, Clone, Debug)]
@@ -81,7 +81,7 @@ impl<T: Clone + Default> Row<T> {
self.occ = min(self.occ, columns);
- if new_row.is_empty() {
+ if new_row.is_empty() || new_row.iter().all(|cell| cell.flags().contains(Flags::GRAPHICS)) {
None
} else {
Some(new_row)
diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs
index 3ef6b2d6..96ed5678 100644
--- a/alacritty_terminal/src/term/mod.rs
+++ b/alacritty_terminal/src/term/mod.rs
@@ -2074,7 +2074,7 @@ impl<T: EventListener> Handler for Term<T> {
// cells are not overwritten, allowing any text behind
// transparent portions of the image to be visible.
- let left = if scrolling { self.grid.cursor.point.column.0 } else { 0 };
+ let leftmost = if scrolling { self.grid.cursor.point.column.0 } else { 0 };
let texture = Arc::new(TextureRef {
id: graphic_id,
@@ -2094,8 +2094,12 @@ impl<T: EventListener> Handler for Term<T> {
};
// Store a reference to the graphic in the first column.
- let graphic_cell = GraphicCell { texture: texture.clone(), offset_x: 0, offset_y };
- self.grid[line][Column(left)].set_graphic(graphic_cell);
+ for (left, offset_x) in (leftmost..).zip((0..width).step_by(cell_width)) {
+ let graphic_cell = GraphicCell { texture: texture.clone(), offset_x, offset_y };
+ let mut cell = self.grid.cursor.template.clone();
+ cell.set_graphic(graphic_cell);
+ self.grid[line][Column(left)] = cell;
+ }
if scrolling && offset_y < height - cell_height as u16 {
self.linefeed();