-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Support for graphics in the terminal #4763
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
base: master
Are you sure you want to change the base?
Conversation
d5a1c08 to
f11ce16
Compare
This sounds like it might have a significant performance impact. Have you actually tested the performance of this PR?
That sounds extremely hacky, which I am not a fan of. This will likely just cause an endless heap of issues with things like selection, so it's not something we can just throw in and forget about.
This seems to just pile on a heap of code to support a bunch of image protocols. I don't like the idea of adding thousands of lines to Alacritty for something with so little use. If we support any protocol it should be the simplest one without any performance impact. I see no benefit in supporting multiple formats.
What about support for devices below OpenGL 3.3? This is something we would like to look into for the future so adding more code that requires at least OpenGL 3.3+ does not seem ideal.
I see little reason for adding memoffset/lazy_static usually, but I haven't looked at the code yet. |
Same |
I launched vtebench three times, in the current Running $ base64 ./target/release/alacritty > /tmp/data
$ wc -l /tmp/data
635257 /tmp/data
# graphics branch
$ perf stat -e cycles,instructions,branches,branch-misses ./target/release/alacritty -e cat /tmp/data
Performance counter stats for './target/release/alacritty -e cat /tmp/data':
4,590,935,968 cycles
10,125,002,121 instructions # 2.21 insn per cycle
2,038,270,623 branches
4,651,069 branch-misses # 0.23% of all branches
0.854657772 seconds time elapsed
0.774462000 seconds user
0.466697000 seconds sys
# master branch
$ perf stat -e cycles,instructions,branches,branch-misses ./target/release/alacritty -e cat /tmp/data
Performance counter stats for './target/release/alacritty -e cat /tmp/data':
4,692,460,970 cycles
10,053,624,431 instructions # 2.14 insn per cycle
2,035,973,894 branches
4,795,961 branch-misses # 0.24% of all branches
0.855561156 seconds time elapsed
0.762745000 seconds user
0.493408000 seconds sys
I changed the NBSP character with a
Without comments and tests, the support for the iTerm2 protocol is less than 100 lines of code.
The only performance impact of this protocol is an extra branch in the
The fallback uses |
This issue is now fixed. |
That doesn't justify adding it. If Alacritty supports any graphics protocol, there should be one and it should be the simplest one available. |
|
I'm also getting the following error:
|
What is the output of |
|
96 or something like that iirc. |
|
I uploaded a fix in 387a224 to check if this fixes the problem. If this works, we may need to generate the code of the fragment shader dynamically, in order to use the 32 units if they are available in the hardware. |
|
@ayosec did you test the iTerm2 protocol with ranger? previewed images are kept on screen and not cleared, so new images are overlayed on top of the old ones, and images are kept in the background when text is rendered in the preview pane. Another issue is that the iterm2 graphics is working with tmux as long as the image file is small, but with large files, it looks like I'm hitting this, which is not an Alacritty issue but Alaciritty is spamming with warning messages like this:
You should be able replicate with:
Note that this issue doesn't happen when running ranger directly without going through a tmux session, and not when running in an ssh session. |
Ranger relies on overwriting images with spaces. The discussion in #910 rejected my first approach to be able to have this functionality. However, if we can change the implementation in this patch to use As a work-around, images can be replaced with the █ character (reversed with
This error happens because the base64 stream is incomplete. Did you use iTerm2 imgcat? It seems that tmux requires specific sequences to send images. Anyways, since iTerm2 will not be accepted, maybe it's not worth it to spend time debugging the issue. |
I can replicate the issue with the linked imgcat script and an image. I won't attach the image here because I'm not sure about its license but I can send it via email.
That's unfortunate, it would have been nice to have it. |
|
I guess it's better to wait for sixel to support 24-bit colors? |
|
Sixel isn't likely to change. |
|
I have updated the patch with the following changes:
|
|
Can your implementation of sixel convert 24bit colors into 256 colors and display a video efficiently? |
18fd66e to
0a41635
Compare
This comment was marked as spam.
This comment was marked as spam.
I feel like this is a perfect solution. As opposed to @ayosec having to maintain a separate fork, pulling from Alacritty when there is an update, just have him maintain the code you aren't willing to, as he is obviously willing to do so. (❤ you ayosec) I would love to see this added into the main Alacritty repo, even if it is just an option that you have to enable manually. I love the speed, flexibility, and customization of Alacritty, but it seems like, at this moment, a great PR is being held back by a locked door. @ayosec has already unlocked it with the key, but the maintainer keeps the door closed with a deadbolt, insisting that the door just "won't open", even if he wanted it too. @ayosec keep up the great work, hope this request (eventually) gets merged, or I might have to move away from Alacritty in search of a project with more understanding maintainers. |
This comment was marked as off-topic.
This comment was marked as off-topic.
As a quick hack, you can adjust the cell dimensions (to increase how many cells are under the image), and the size in the vertex data. For example, to increase the size by a 50%, something like this should work: diff --git a/alacritty/src/renderer/graphics/draw.rs b/alacritty/src/renderer/graphics/draw.rs
index eb1cbad3..433db23d 100644
--- a/alacritty/src/renderer/graphics/draw.rs
+++ b/alacritty/src/renderer/graphics/draw.rs
@@ -98,8 +98,8 @@ impl RenderList {
sides: TopLeft,
column: render_item.column.0 as GLuint,
line: render_item.line as GLuint,
- height: graphic_texture.height,
- width: graphic_texture.width,
+ height: graphic_texture.height * 3 / 2,
+ width: graphic_texture.width * 3 / 2,
offset_x: render_item.offset_x,
offset_y: render_item.offset_y,
base_cell_height: graphic_texture.cell_height,
@@ -112,7 +112,7 @@ impl RenderList {
}
if render_item.show_hint {
- let scale = size_info.cell_height() / graphic_texture.cell_height;
+ let scale = size_info.cell_height() / graphic_texture.cell_height * 1.5;
let x = render_item.column.0 as f32 * size_info.cell_width()
- render_item.offset_x as f32 * scale;
diff --git a/alacritty_terminal/src/graphics/mod.rs b/alacritty_terminal/src/graphics/mod.rs
index 5ecdf29c..4cc63dc4 100644
--- a/alacritty_terminal/src/graphics/mod.rs
+++ b/alacritty_terminal/src/graphics/mod.rs
@@ -473,8 +473,8 @@ pub fn insert_graphic<L: EventListener>(
graphic: GraphicData,
palette: Option<Vec<Rgb>>,
) {
- let cell_width = term.graphics.cell_width as usize;
- let cell_height = term.graphics.cell_height as usize;
+ let cell_width = (term.graphics.cell_width / 1.5) as usize;
+ let cell_height = (term.graphics.cell_height / 1.5) as usize;
// Store last palette if we receive a new one, and it is shared.
if let Some(palette) = palette {@bytesnake Can you share your use-case? If this is something that other people may use, we can add a configuration option. |
This comment was marked as off-topic.
This comment was marked as off-topic.
i need this but for typst |
If Sixel images are sent through tmux I'm not sure if we can scale it after receiving it. tmux needs to know how many cells are written before inserting the image, and it may adjust the image when needed. For example, Do you know if this feature is available in other terminals? Maybe there is a way to solve the problem that I'm missing. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as abuse.
This comment was marked as abuse.
|
Any updates? |
Since Rust 1.77, `offset_of` is available in the std.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
happy to see unnecessary dependencies being removed
thank you for the contribution
|
What are we missing for this PR to be merged? |
maintainer outlined a few things here. more or less the size of the code seems to be the biggest problem, then also qualms about the sixel API itself. Honestly, with the nature of their concerns, I think they're leading us and ayosec on. They should probably just close this PR. Anyone who likes this PR enough is just using ayosec's fork anyway. |
I think I've made it pretty clear that this has little chance of ever getting upstreamed. Considering the great work ayosec has done writing and maintaining it, I just don't think it would be fair to close the PR and banish it into the void. There's nothing wrong with alternative Alacritty distributions for people with differing preferences. |
Clippy suggests using the function provided in std.
This patch adds support for graphics in the terminal. Graphics can be sent as Sixel images.
New features
Sixel parser
The Sixel parser is based on the SIXEL GRAPHICS EXTENSION chapter in a DEC manual.
The support is complete except for the pixel aspect ratio parameters. According to the manual, a Sixel image can specify that it expects a specific shape for the pixels in the device, but in none of terminals that I checked these parameters had any effect: they always assume a 1:1 ratio. Also, I didn't find any Sixel generator that emits a different ratio. To avoid extra complexity in the parser, it always assume 1:1 when the image is built.
There are two new terminal modes:
SixelScrolling(80)If enabled, new graphics are inserted at the cursor position, and they can scroll the grid.
If disabled, new graphics are inserted at top-left, and they are limited by the height of the window.
SixelPrivateColorRegisters(1070)If enabled, every Sixel parser has its own color palette.
If disabled, Sixel images can share a color palette.
Initially I didn't plan to support this mode, since it seems to be specific to xterm, but when I was testing applications using Sixel I found that mpv uses it to reuse a palette between video frames. Since mpv is based on libsixel, I guess that this feature could be used by more applications.
Both modes are enabled by default.
The function to convert HLS colors to RGB is a direct port of the implementation of the same function in xterm. I verified that the function emits the same results in all combinations of values 0, 30, 60, 90, and 100 in every color component. Only a few of these combinations were left in the tests to reduce the noise in the code.
To test the parser there are Sixel images generated with 3 different applications. For each one, there is a
.rgbafile in the same directory with the expected RGBA values. The commands to produce these files are inalacritty_terminal/tests/sixel/README.md.Byte
90as DCSSixel images using byte
90as DCS are not supported. DCS can be eitherESC Por90, but thevtecrate only recognizesESC P. I guess that this is because90can be a continuation byte in a UTF-8 sequence (two most significant bits are10), so it can be a valid input from users.Xterm has the same limitation. I don't expect that many applications depends on it.
ppmtosixelis an exception. It uses90to start the Sixel data, and it has to be replaced if we want to see an image generated by it.It is still interesting to test
ppmtosixelbecause it was written in 1991, long before Sixel was added to most (if not all) terminal emulators.