Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for graphics in the terminal #4763

Open
wants to merge 55 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
08ceb31
Add Sixel support
ayosec Mar 10, 2021
b4adf34
Merge remote-tracking branch 'vendor/master' into tmp1
ayosec Apr 1, 2021
50d717f
Implementation of the XTSMGRAPHICS sequence.
ayosec Apr 1, 2021
c6359f9
Don't clear cells after the right side of the graphic.
ayosec Apr 2, 2021
bfd0f81
Merge remote-tracking branch 'vendor/master' into graphics
ayosec Apr 3, 2021
fd0218f
Merge remote-tracking branch 'vendor/master' into graphics
ayosec Apr 7, 2021
e5e9c82
Merge remote-tracking branch 'vendor/master' into graphics
ayosec Apr 18, 2021
b6b7840
Merge remote-tracking branch 'vendor/master' into graphics
ayosec May 29, 2021
9723e3f
Don’t erase text behind a sixel image; the image might be transparent
db48x May 31, 2021
5972714
remove an unncessary variable from insert_graphic
db48x May 31, 2021
89a9fc6
Merge commit '5972714b642efb3f257b77fdf526ebe8492cafd8' into graphics
ayosec May 31, 2021
f4bdc6f
Avoid unnecessary clone when set graphic data.
ayosec May 31, 2021
3caa09e
Define MAX_GRAPHIC_DIMENSIONS as a 2-elements array.
ayosec May 31, 2021
ae7aa4b
support DECSET/DECRST (CSI ? Pm h) to change where the cursor ends up
db48x Jun 11, 2021
699a7a9
Merge remote-tracking branch 'vendor/master' into graphics
ayosec Jun 20, 2021
573dedd
put the TermMode back to just u32; I had miscounted the bits
db48x Jun 21, 2021
9d360e4
move_forward takes a relative column count, not an absolute column nu…
db48x Jun 21, 2021
91b8566
Merge remote-tracking branch 'vendor/master' into graphics
ayosec Sep 23, 2021
18653cf
Terminal mode to control cursor position after a new graphic.
ayosec Sep 24, 2021
ebf41d5
Interprets mode 80 as Sixel Display Mode.
ayosec Sep 24, 2021
a919ac7
Merge with alacritty/master
ayosec Jul 11, 2022
48b2610
Fill all cells under a graphic with the template.
ayosec Jul 12, 2022
4469599
Allow hue values up to 360 in the Sixel parser.
ayosec Jul 12, 2022
b737176
Allow replacing part of a graphic with text.
ayosec Jul 12, 2022
f796ba2
Highlight graphics to show hints.
ayosec Jul 12, 2022
dae81e0
Allow overlapping graphics.
ayosec Jul 13, 2022
111986f
Optimize graphics replacement.
ayosec Jul 13, 2022
06b4c3c
Merge branch 'master' into graphics-private
ayosec Jul 13, 2022
1c6a770
Fix clippy warnings.
ayosec Jul 14, 2022
e521d6e
Use hls_to_rgb implementation from libsixel.
ayosec Jul 15, 2022
bf743df
Changes in sixel module to be compatible with oldstable.
ayosec Jul 15, 2022
8d2016b
Initialize cell dimensions when create a Graphics instance.
ayosec Jul 15, 2022
2301bf1
Merge remote-tracking branch 'vendor/master' into graphics
ayosec Aug 4, 2022
03cf630
Support GLES2 Renderer in sixel
kumattau Oct 4, 2022
83aceed
Merge pull request #7 from kumattau/graphics-gles2
ayosec Oct 16, 2022
2eb9812
Merge remote-tracking branch 'vendor/master' into graphics
ayosec Oct 16, 2022
396002c
Set graphics limit per cell.
ayosec Oct 16, 2022
a9335fc
Add Eq derive to ClearSubregion.
ayosec Oct 16, 2022
615e72e
CSI XTSMGRAPHICS Pi=2, Pa=1 should return dimensions that fit in text…
kumattau Oct 20, 2022
410b36e
Merge pull request #8 from kumattau/graphics-xtsmgraphics
ayosec Oct 20, 2022
850fd41
Merge remote-tracking branch 'vendor/master' into graphics
ayosec Oct 20, 2022
2f3a8cf
Remove entry about Sixel support in the changelog.
ayosec Oct 20, 2022
ed6e3fa
Update damage when a graphics is inserted.
ayosec Oct 20, 2022
48a388a
Apply rustfmt to term/mod.rs.
ayosec Oct 20, 2022
2772e72
Merge remote-tracking branch 'vendor/master' into graphics
ayosec Dec 2, 2022
fc97c07
Apply rustfmt and clippy to the current branch.
ayosec Dec 2, 2022
713c541
Merge remote-tracking branch 'vendor/master' into graphics
ayosec Mar 1, 2023
5e75fc9
Merge remote-tracking branch 'vendor/master' into graphics
ayosec Feb 11, 2024
e1b78c1
Serialize/Deserialize only if the `serde` feature is set.
ayosec Feb 11, 2024
6bd9c71
Apply clippy suggestions.
ayosec Feb 12, 2024
84c0f29
Include Sixel support in Device Attributes response.
ayosec Mar 4, 2024
21c9138
Merge remote-tracking branch 'vendor/master' into graphics
ayosec Mar 4, 2024
ff0f64f
Merge remote-tracking branch 'vendor/master' into graphics
ayosec Mar 11, 2024
484e357
Merge remote-tracking branch 'vendor/master' into graphics
ayosec May 15, 2024
39c7b40
Upgrade vte fork.
ayosec May 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- IME composition preview not appearing on Windows
- Synchronized terminal updates using `DCS = 1 s ST`/`DCS = 2 s ST`
- Regex terminal hints ([see features.md](./docs/features.md#hints))
- Support for Sixel protocol
- macOS keybinding (cmd+alt+H) hiding all windows other than Alacritty

### Changed
Expand Down
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions alacritty/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ libc = "0.2"
unicode-width = "0.1"
bitflags = "1"
dirs = "3.0.1"
memoffset = "0.6.1"

[build-dependencies]
gl_generator = "0.14.0"
Expand Down
40 changes: 40 additions & 0 deletions alacritty/res/graphics.f.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#version 330 core

// Index in the textures[] uniform.
flat in int texId;

// Texture coordinates.
in vec2 texCoords;

// Array with graphics data.
uniform sampler2D textures[16];

// Computed color.
out vec4 color;

void main() {
// The expression `textures[texId]` can't be used in OpenGL 3.3.
// If we try to use it, the compiler throws this error:
//
// sampler arrays indexed with non-constant expressions
// are forbidden in GLSL 1.30 and later
//
// To overcome this limitation we use a switch for every valid
// value of `texId`.
//
// The first expression (`textures[texId]`) works with OpenGL 4.0
// or later (using `#version 400 core`). If Alacritty drops support
// for OpenGL 3.3, this switch block can be replaced with it.


#define TEX(N) case N: color = texture(textures[N], texCoords); break;

switch(texId) {
TEX( 0) TEX( 1) TEX( 2) TEX( 3)
TEX( 4) TEX( 5) TEX( 6) TEX( 7)
TEX( 8) TEX( 9) TEX(10) TEX(11)
TEX(12) TEX(13) TEX(14) TEX(15)
default:
discard;
}
}
79 changes: 79 additions & 0 deletions alacritty/res/graphics.v.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#version 330 core

// ------
// INPUTS

// Texture associated to the graphic.
layout(location = 0) in int textureId;

// Sides where the vertex is located.
//
// Bit 0 (LSB) is 0 for top and 1 for bottom.
// Bit 1 is 0 for left and 1 for right.
layout(location = 1) in int sides;

// Column number in the grid where the left vertex is set.
layout(location = 2) in float column;

// Line number in the grid where the left vertex is set.
layout(location = 3) in float line;

// Height in pixels of the texture.
layout(location = 4) in float height;

// Width in pixels of the texture.
layout(location = 5) in float width;

// Offset in the X direction.
layout(location = 6) in float offsetX;

// Offset in the Y direction.
layout(location = 7) in float offsetY;

// Height in pixels of a single cell when the graphic was added.
layout(location = 8) in float baseCellHeight;

// -------
// OUTPUTS

// Texture sent to the fragment shader.
flat out int texId;

// Coordinates sent to the fragment shader.
out vec2 texCoords;

// --------
// UNIFORMS

// Width and height of a single cell.
uniform vec2 cellDimensions;

// Width and height of the view.
uniform vec2 viewDimensions;


#define IS_RIGHT_SIDE ((sides & 1) == 1)
#define IS_BOTTOM_SIDE ((sides & 2) == 2)

void main() {
float scale = cellDimensions.y / baseCellHeight;
float x = (column * cellDimensions.x - offsetX * scale) / (viewDimensions.x / 2) - 1;
float y = -(line * cellDimensions.y - offsetY * scale) / (viewDimensions.y / 2) + 1;

vec4 position = vec4(x, y, 0, 1);
vec2 coords = vec2(0, 0);

if(IS_RIGHT_SIDE) {
position.x += scale * width / (viewDimensions.x / 2);
coords.x = 1;
}

if(IS_BOTTOM_SIDE) {
position.y += -scale * height / (viewDimensions.y / 2);
coords.y = 1;
}

gl_Position = position;
texCoords = coords;
texId = textureId;
}
3 changes: 3 additions & 0 deletions alacritty/src/display/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::ops::{Deref, DerefMut, RangeInclusive};
use alacritty_terminal::ansi::{Color, CursorShape, NamedColor};
use alacritty_terminal::config::Config;
use alacritty_terminal::event::EventListener;
use alacritty_terminal::graphics::GraphicCell;
use alacritty_terminal::grid::{Dimensions, Indexed};
use alacritty_terminal::index::{Column, Direction, Line, Point};
use alacritty_terminal::term::cell::{Cell, Flags};
Expand Down Expand Up @@ -191,6 +192,7 @@ impl<'a> Iterator for RenderableContent<'a> {
pub struct RenderableCell {
pub character: char,
pub zerowidth: Option<Vec<char>>,
pub graphic: Option<GraphicCell>,
pub point: Point<usize>,
pub fg: Rgb,
pub bg: Rgb,
Expand Down Expand Up @@ -261,6 +263,7 @@ impl RenderableCell {

RenderableCell {
zerowidth: cell.zerowidth().map(|zerowidth| zerowidth.to_vec()),
graphic: cell.graphic().cloned(),
flags: cell.flags,
character,
bg_alpha,
Expand Down
14 changes: 13 additions & 1 deletion alacritty/src/display/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ impl Display {
/// This call may block if vsync is enabled.
pub fn draw<T: EventListener>(
&mut self,
terminal: MutexGuard<'_, Term<T>>,
mut terminal: MutexGuard<'_, Term<T>>,
message_buffer: &MessageBuffer,
config: &Config,
search_state: &SearchState,
Expand All @@ -502,14 +502,21 @@ impl Display {
let vi_mode = terminal.mode().contains(TermMode::VI);
let vi_mode_cursor = if vi_mode { Some(terminal.vi_mode_cursor) } else { None };

let graphics_queues = terminal.graphics_take_queues();

// Drop terminal as early as possible to free lock.
drop(terminal);

self.renderer.with_api(&config.ui_config, &size_info, |api| {
api.clear(background_color);
});

if let Some(graphics_queues) = graphics_queues {
self.renderer.graphics_run_updates(graphics_queues, &size_info);
}

let mut lines = RenderLines::new();
let mut graphics_list = renderer::graphics::RenderList::default();

// Draw grid.
{
Expand All @@ -532,12 +539,17 @@ impl Display {
// Update underline/strikeout.
lines.update(&cell);

// Track any graphic present in the cell.
graphics_list.update(&cell);

// Draw the cell.
api.render_cell(cell, glyph_cache);
}
});
}

self.renderer.graphics_draw(graphics_list, &size_info);

let mut rects = lines.rects(&metrics, &size_info);

if let Some(vi_mode_cursor) = vi_mode_cursor {
Expand Down