Commit graph

149 commits

Author SHA1 Message Date
Kovid Goyal
4bafcb9a7c
Graphics protocol: Add sub-feature querying
Fixes #10732
2026-10-25 09:59:12 +05:30
Kovid Goyal
2efa09dd07
Fix #10684 2026-10-18 08:28:21 +05:30
Kovid Goyal
10b3792dfb
misc improvements for indexed color images 2026-10-16 11:13:14 +05:30
Kovid Goyal
535c7502e8
Graphics protocol: Add indexed color image formats
Some checks are pending
CI / Linux (python=3.14 cc=clang sanitize=1) (push) Waiting to run
CI / Linux (python=3.12 cc=gcc sanitize=0) (push) Waiting to run
CI / Linux (python=3.13 cc=gcc sanitize=1) (push) Waiting to run
CI / Linux package (push) Waiting to run
CI / Bundle test (macos-latest) (push) Waiting to run
CI / Bundle test (ubuntu-latest) (push) Waiting to run
CI / macOS Brew (push) Waiting to run
CI / Test ./dev.sh and benchmark (push) Waiting to run
CodeQL / CodeQL-Build (actions, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, macos-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (go, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (python, ubuntu-latest) (push) Waiting to run
Depscan / Scan dependencies for vulnerabilities (push) Waiting to run
Add two new image formats, f=8 with one byte per pixel that is an index
into the terminal color palette and f=16 with a palette index followed by
an alpha byte. Indices 0-247 are the SGR 256 color table entries and
248-255 are special colors: default background, default foreground,
selection background and foreground, cursor, cursor text, URL color and
one reserved slot. Such images change color automatically when the
terminal colors change.

The images are uploaded as integer textures and drawn by a separate
shader program that looks up colors in the existing per window color
table uniform block, so a color scheme change costs nothing extra and
rendering of normal images is unaffected. Programs are switched only at
boundaries between runs of indexed and normal images in draw order. The
shader does bilinear filtering after the palette lookup since integer
textures cannot be filtered. Animation and frame composition are not
supported for these formats.

Closes #10666
2026-10-15 22:05:23 +05:30
rudolf-blue
ee56934397 Forget the disk position of a replaced zero length cache entry 2026-10-09 07:40:55 -04:00
rudolf-blue
2dc9687573 Fix deleting displayed and base animation frames 2026-10-08 23:59:57 -04:00
rudolf-blue
5f75c46ae5 Encrypt disk cache entries outside the lock 2026-10-08 23:59:56 -04:00
rudolf-blue
f3b74cdeac Fix key leak and stale entry accounting in disk cache defrag 2026-10-08 23:59:56 -04:00
Kovid Goyal
fa9f8dac18
Cleanup previous PR
Some checks are pending
CI / Linux (python=3.14 cc=clang sanitize=1) (push) Waiting to run
CI / Linux (python=3.12 cc=gcc sanitize=0) (push) Waiting to run
CI / Linux (python=3.13 cc=gcc sanitize=1) (push) Waiting to run
CI / Linux package (push) Waiting to run
CI / Bundle test (macos-latest) (push) Waiting to run
CI / Bundle test (ubuntu-latest) (push) Waiting to run
CI / macOS Brew (push) Waiting to run
CI / Test ./dev.sh and benchmark (push) Waiting to run
CodeQL / CodeQL-Build (actions, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, macos-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (go, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (python, ubuntu-latest) (push) Waiting to run
Depscan / Scan dependencies for vulnerabilities (push) Waiting to run
2026-10-08 08:31:32 +05:30
fairyhunter13
1bf03eabaa Graphics: move Unicode placeholder cell images with lines scrolled into history from a region
A line scrolled out of a region whose top is row 0 (tmux with a bottom status line) enters the history, but scroll_filter_margins_func left the refs of history lines in place, so they drew over other lines on the next scroll back. A reverse scroll also moved history refs although the history does not move.
2026-10-08 09:20:16 +07:00
Kovid Goyal
24f7369bb6
Drop Unicode placeholder cell images scrolled off the bottom of the screen
A full screen reverse scroll (ESC M at the top, CSI T) moves every image
ref down a row. scroll_filter_func() only removed refs that left through
the top, so a cell image on the bottom line ended up at row `lines`, off
screen, while its line was discarded. The next forward scroll brought it
back onto the bottom row, where the line has no placeholders.
screen_render_line_graphics() returns early for such lines, so nothing
removed the ref and a slice of the old image was drawn over the new text.
tmux and pagers send ESC M when scrolling down, so this shows up in
practice. Fix it by dropping cell image refs that move below the bottom
margin, the same way the margins scroll path drops refs that leave the
region.

This replaces PR #10623, which was not merged for these reasons:

- It does not find the cause. It removes cell image refs at render time
  for every line without placeholders, so the stale ref still exists and
  is still seen by anything that reads refs before the next render, such
  as graphics query and delete commands and the paused rendering path,
  which returns before the new code.
- It costs time on every frame. Whenever any image is loaded, even with
  no placeholders at all, each clean visible line and each visible
  history line triggers a walk over all images and refs. Before, such
  lines cost nothing. This fix adds one comparison to a loop that only
  runs when the screen scrolls.

Close #10623
2026-10-07 20:19:23 +05:30
Kovid Goyal
b493a637b0
Graphics protocol: Fix no response for animation chunks when a=f specified in continuations
Fixes #10599
Fixes #10600
2026-10-05 03:23:27 +05:30
Kovid Goyal
73f5102392
Graphics protocol: Fix memory leak when loading corrupt PNG with ICC profile
Some checks are pending
CI / Linux (python=3.14 cc=clang sanitize=1) (push) Waiting to run
CI / Linux (python=3.12 cc=gcc sanitize=0) (push) Waiting to run
CI / Linux (python=3.13 cc=gcc sanitize=1) (push) Waiting to run
CI / Linux package (push) Waiting to run
CI / Bundle test (macos-latest) (push) Waiting to run
CI / Bundle test (ubuntu-latest) (push) Waiting to run
CI / macOS Brew (push) Waiting to run
CI / Test ./dev.sh and benchmark (push) Waiting to run
CodeQL / CodeQL-Build (actions, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, macos-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (go, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (python, ubuntu-latest) (push) Waiting to run
Depscan / Scan dependencies for vulnerabilities (push) Waiting to run
2026-09-24 19:00:13 +05:30
Kovid Goyal
87ab3e98f4
Graphics protocol: Fix file descriptor leak that can be triggered by malicious clients
Also make failure responses generic to avoid leaking any filesystem
information to failed opens
2026-09-14 21:03:15 +05:30
Hassan Raza
4a19654bc2
Fix composed frame metadata 2026-08-27 15:09:14 +05:00
Kovid Goyal
0200d1c22b
Add bounds checking to a couple of functions
This is not strictly necessary as their callers already validate bounds,
however, I have now got two separate false security reports for this so
rather than waste my time responding to these, just add the bounds
checking.
2026-08-26 12:25:05 +05:30
Kovid Goyal
6b5bdca90d
Avoid extra copy of image data into disk cache
Also fix a rare race and reduce memory consumption for transient images
2026-08-23 19:41:15 +05:30
Kovid Goyal
7616cfe854
Graphics: Make reading images robust against clients that truncate files that are being read by kitty 2026-08-23 17:05:06 +05:30
Kovid Goyal
fb862c019b
... 2026-08-23 09:30:28 +05:30
Kovid Goyal
d894ac8c1d
Follow libpng's documented contract 2026-08-23 09:24:02 +05:30
zaveshaa
15ceaac34b Fix doubled words in docs and a test comment 2026-08-22 23:10:54 +03:00
Kovid Goyal
d805e28aad
Fix handling of a=f chunked loading 2026-08-21 10:46:43 +05:30
Kovid Goyal
f5b4722c68
Fix incorrect key being used for animation compose
Regression in 0.45.0
Fixes #10379
2026-08-21 10:31:17 +05:30
Kovid Goyal
5bdbf2676b
Graphics: clipping against page margins on scroll
Fixes #10377
2026-08-21 09:16:22 +05:30
Kovid Goyal
0ecb10d158
Add AVX 512 implementations for remaining SIMD functions 2026-08-18 09:03:29 +05:30
Kovid Goyal
7f0b072f0d
autoformat 2026-08-05 05:32:56 +05:30
copilot-swe-agent[bot]
a31f9e52f2
Refactor kitty_tests: move __init__.py code to base.py, update all imports 2026-08-05 05:32:54 +05:30
Jeff Quast
efeb4aead0 Fix erroneous scroll when using X/Y offsets in images
Problem
-------

In update_dest_rect() when both num_cols and num_rows are 0
(auto-computed, ``a=T``), the first block computes num_cols with
cell_x_offset, but, then the second block mismatches num_cols, causing
it to compute width_px from num_cols and adds cell_x_offset a second
time. The returned value is large enough that it often causes scrolling,
depending on size and location of the screen.

A sample visual program:

```python
import zlib, base64, time
from functools import partial
echo = partial(print, end='', flush=True)

echo('\033[H\033[J')

base = bytes([0, 128, 0, 255]) * 640 * 576
k = zlib.compress(keyframe, 3)
echo(f'\033[8;60H\033_Ga=T,i=1,q=1,f=32,s=640,v=576,o=z,N=1;{base64.b64encode(k).decode()}\033\\')
time.sleep(1)

delta = bytes([200, 0, 0, 255]) * 32 * 512
d = zlib.compress(delta, 3)
echo(f'\033[9;67H\033_Ga=T,i=100,q=1,f=32,s=32,v=512,o=z,N=1,X=9,Y=25;{base64.b64encode(d).decode()}\033\\')

time.sleep(1)
print()
```

Solution
--------

Add 'auto_cols' and 'auto_rows' to remember the original read-only
values before exercising their auto-calculated size. 'auto_rows' isn't
technically necessary given the logic branching but it describes in code
better.

Before and After video
----------------------

A video will be attached shortly, here.
2026-07-12 18:22:40 -04:00
copilot-swe-agent[bot]
051a5b72e0
Preferentially evict transient images before non-transient ones under storage pressure 2026-06-19 06:48:39 +00:00
Matsumoto Kotaro
89946ebc07 graphics: make N a transient usage-hints bitmask
Change the graphics protocol N key from a boolean into a usage-hints
bitmask. Define the first bit as a transient hint, allowing the terminal
to treat the image data as short-lived and apply optimizations such as
skipping disk cache writes.

Propagate the transient hint through frame coalescing and composition, so
a composed frame is transient if any contributing frame is transient.
2026-06-19 13:22:01 +09:00
Matsumoto Kotaro
cc2d7a1789 graphics: add memory-only storage for graphics data
Add a new graphics protocol key, N=1, to request that transmitted
image/frame data is kept only in memory and not written to the graphics
disk cache file.

This is useful for transient high-frequency updates such as video-like
streams, where the latest frame is the only useful data and persisting
each frame to the disk cache causes unnecessary write traffic.

The implementation keeps the existing graphics cache abstraction intact:
memory-only entries can still be read back by animation, composition, and
frame coalescing paths. Only persistence to the disk cache file is skipped.

The default behavior is unchanged when N is omitted or set to zero.
2026-05-30 18:46:24 +09:00
Kovid Goyal
4fe29f2630
dd basic drag thumbnail support to dnd kitten 2026-05-03 22:18:18 +05:30
copilot-swe-agent[bot]
b252524def Add tests for graphics protocol crash fixes (commits e9661f0 and 48ab623)
Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/52901924-cb01-416f-8d4c-56bc2872a3c6
2026-03-23 03:39:38 +00:00
Kovid Goyal
e6d7e91000
Avoid using lseek() to track disk cache file write offset
It's slow and not thread safe.
We use pwrite() so it's not reliable anyway.
2025-11-17 11:16:30 +05:30
Kovid Goyal
45b2678db1
Allow backspace to wrap cursor to previous line
Fixes #8841
2025-07-23 08:56:54 +05:30
Kovid Goyal
24a195c7c7
Graphics: Fix deletion of images by id not working for images with no placements 2024-12-24 09:39:01 +05:30
Kovid Goyal
8facaf4fa0
Graphics: Fix deleted but not freed images without any references being incorrectly freed on a subsequent delete command 2024-12-18 09:25:06 +05:30
Kovid Goyal
cb2e1fcd04
Graphics protocol: Fix delete by number not deleting newest image with the specified number
Fixes #8071
2024-11-24 10:11:34 +05:30
Kovid Goyal
70d72b22d8
Graphics protocol: Clear any partially uploaded data for a chunked load when any delete command is received
Fixes #7968
2024-10-13 09:49:44 +05:30
Kovid Goyal
a0dc062032
Fix render cache not being used 2024-07-23 15:07:41 +05:30
Kovid Goyal
8201f0dd0e
Move caching implementation to Python
Less code, more performant since the cache is used from Python.
And we can make the Go code a pure image format conversion filter.
2024-07-23 13:37:53 +05:30
Kovid Goyal
d08dcd92c7
Python wrapper to use image to RGBA Go code 2024-07-22 22:39:12 +05:30
Kovid Goyal
2ba28171ab
DRYer 2024-07-16 10:45:46 +05:30
Kovid Goyal
c056df223e
Nicer way to prevent defrag 2024-07-16 07:43:50 +05:30
Kovid Goyal
9a50e453b2
Ensure defrag doesnt run when testing hole coalescing 2024-07-15 22:41:22 +05:30
Kovid Goyal
24e6dda0bc
disk-cache: Improve hole management
Make coalescing of neighboring holes robust. Speed up hole finding.
Cost is we replace a single array tracking holes with three hashmaps
tracking size->[pos] pos->size and endpos->size.
2024-07-15 21:13:59 +05:30
Kovid Goyal
2058cac203
Now the test should be fully robust 2024-07-15 09:29:30 +05:30
Kovid Goyal
a49bb8c5f9
DRYer 2024-07-15 09:24:19 +05:30
Kovid Goyal
638a4b19ee
... 2024-07-15 09:19:13 +05:30
Kovid Goyal
aaf7808328
Add explicit check for holes in test 2024-07-15 09:05:44 +05:30