Commit graph

185 commits

Author SHA1 Message Date
Egor Ignatov
51b159f990 Fix PNG dimension validation test on 32-bit platforms
Expect OverflowError for dimensions that exceed sys.maxsize, since
PyArg_ParseTuple rejects them before the PNG buffer validation runs.
Continue to expect ValueError for invalid dimensions and buffer lengths
that reach the validation code.
2026-11-09 13:01:06 +03:00
Kovid Goyal
e55d14085a
Cleanup previous PR
- Parse in-band resize reports robustly: require the 48; prefix, accept
  extra parameters and reject negative values instead of panicking
- Handle bracketed paste in parse_input_from_terminal with a dedicated
  scan for the end of paste marker so pasted escape bytes are never lost
- Guard against NaN in scroll_by_pixels and scroll_to_absolute, clamp
  negative absolute scroll targets, let infinite fractional scrolls clamp
  and propagate overflow errors from PyLong_AsDouble
- Empty disk cache entries no longer claim offset 0 in the cache file and
  defrag only moves entries actually written to disk
- Reject zero and too large block sizes in rsync signature headers
- Only replace the encryptor tag once it has been read successfully
2026-10-09 18:37:48 +05:30
rudolf-blue
72da47342f Reject out of range width and height in png_from_32bit_rgba_data 2026-10-09 07:40:55 -04:00
rudolf-blue
307561bb3e End bracketed paste in kittens even inside an unterminated sequence 2026-10-09 07:40:55 -04:00
Kovid Goyal
f78106e296
Cleanup previous PR
- Back off on all accept() errors that leave the connection pending, not
  just resource exhaustion, so the talk thread cannot spin on a readable
  listener
- Use an atomic for the test only accept failure injection instead of
  taking the talk mutex on every accept
- Encrypt disk cache entries in chunks of up to 1MB to reduce the number
  of write syscalls for large images
- Have GlobalWatchers.set_extra() invalidate the cached watchers
2026-10-09 11:14:45 +05:30
Kovid Goyal
26de0a5d11 Merge branch 'more-fixes' of https://github.com/rudolf-blue/kitty
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 11:09:49 +05:30
Kovid Goyal
0607401967
Make history consumption on resize an explicit parameter
resize_screen_buffers() moves the storage of the source history buffer into
the result, both when reusing unchanged lines and in the same size fast path.
Replace the global used to opt out of this with an explicit HistoryResizeMode
argument so callers that must keep their history (HistoryBuf.rewrap) state it,
and make the same size fast path copy rather than steal in that mode. Document
that nothing may fail after the history has been consumed.
2026-10-09 10:49:57 +05:30
rudolf-blue
68bc11d2ce Fix continued line detection once scrollback has wrapped around 2026-10-09 00:01:01 -04:00
rudolf-blue
8637b48ad2 Fix escape handling in parse_input_from_terminal 2026-10-08 23:59:57 -04:00
rudolf-blue
f7441cc323 Fix parsing of rgbi colors 2026-10-08 23:59:57 -04:00
rudolf-blue
9cfd91e812 Fix crash in png_from_32bit_rgba_data on invalid input 2026-10-08 23:59:56 -04:00
Hassan Raza
c15b077b6b
Set cursor text blinking without inverting it 2026-10-05 15:24:21 +05:00
Kovid Goyal
6ad2a3aee7
Fix heap buffer underflow in shlex parser 2026-09-28 07:35:08 +05:30
Kovid Goyal
a908167e98
Fix the IPC lock used by custom shader compilation 2026-09-22 15:21:40 +05:30
Siriwat Uamganmsup
0b29c33e89 Widen the cell for Thai/Lao vowel sign AM (U+0E33, U+0EB3)
These two code points have Grapheme_Cluster_Break=SpacingMark but a
width of one, the only such code points in Unicode. Grapheme
segmentation (GB9a) adds them to the previous cell, so "จำ" occupied a
single cell in kitty while wcwidth() based programs count two. As a
result the SARA AA glyph was clipped, only the nikhahit was visible and
the cursor drifted right by one cell per AM.

Now, when such a code point combines into a plain one cell wide cell,
the cell is widened to two cells, using the same mechanism as U+FE0F
does for narrow emoji. The C and Go wcswidth() implementations are
updated to match so that kitty's own width calculations agree with the
screen.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 10:43:49 +07:00
Kovid Goyal
bab67650e2
Test suite: Fix small numbers of Python tests being run in incorrect environment
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
Also fix env reporting. Fixes #10478
2026-09-15 16:50:21 +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
Kovid Goyal
e99f6044c5
Remove NUL from paths received via OSC7
NUL is anyway not legal in paths and it causes session files saved with
such paths to fail

We dont remove other control codes since they are actually legal in
paths.

Fixes #10321
2026-08-05 13:36:18 +05:30
Kovid Goyal
7f0b072f0d
autoformat 2026-08-05 05:32:56 +05:30
Kovid Goyal
104acf7d65
add tests for lock_with_file 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
copilot-swe-agent[bot]
c2e7ee19d2
Change set_uint_at_address to use METH_FASTCALL, skip ctypes test on intel macs 2026-06-25 10:49:19 +00:00
copilot-swe-agent[bot]
c35ff2e843
Replace ctypes in marks.py with C-level set_uint_at_address function 2026-06-25 10:35:11 +00:00
Kovid Goyal
58d314be7c
Cleanup previous PR 2026-04-28 16:57:14 +05:30
Idate96
5a74cb126f Guard line buffer copy bounds 2026-04-28 13:10:34 +02:00
copilot-swe-agent[bot]
7d3ff332b9
macOS: fix args passed via open --args being ignored when macos-launch-services-cmdline is present (fixes #9910)
Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/2cdc7e8f-5b64-4c97-bd65-dec508155313

Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
2026-04-24 04:52:37 +00:00
Kovid Goyal
83160c10c4
Cleanup previous PR 2026-03-16 17:38:14 +05:30
Kovid Goyal
573bfb688a
Move parsing of colors fully into C
Uses a perfect hash function for color name lookup
2025-12-31 14:21:45 +05:30
Kovid Goyal
e14e34948e
More cleanups for color parsing
Using rounding when converting float to uint8 for more accuracy.
Fix rgb:3 and rgbi: parsing in Go code. Various other minor cleanups.
2025-12-31 09:35:09 +05:30
Kovid Goyal
7c13c04c84
Move color parsing code to C for performance 2025-12-30 21:43:57 +05:30
Kovid Goyal
62d5fcc074
Merge branch 'wide-gamut-colors' of https://github.com/jokull/kitty 2025-12-30 13:19:44 +05:30
Jökull Sólberg
64abd87a9e Add wide gamut color support with OKLCH and LAB formats
Implements modern wide gamut color formats with CSS Color Module Level 4
gamut mapping, addressing PR feedback with Go implementation, performance
benchmarks, and reorganized documentation.

Features:
- OKLCH (perceptually uniform color space)
- CIE LAB (device-independent color space)
- CSS Color 4 compliant gamut mapping algorithm
- Inline comment support in color config parsing

Addressing PR Feedback:

1. Go Implementation (tools/utils/style/):
   - Complete OKLCH and LAB parsing with gamut mapping
   - Matches Python implementation structure
   - Comprehensive test suite (all tests passing)
   - Performance benchmarks showing acceptable overhead

2. Performance Benchmarks:
   - OKLCH: ~4.6 µs/op
   - LAB: ~1.5 µs/op
   - 10 mixed colors: ~13 µs total
   - Typical config (50 colors): <0.5ms startup impact

3. Documentation Reorganization:
   - Moved detailed color docs to docs/wide-gamut-colors.rst
   - Configuration docs now link to separate documentation
   - Reduces size of main configuration documentation

Gamut Mapping:
- Binary search chroma reduction from CSS Color Module Level 4
- Preserves lightness and hue while reducing chroma for out-of-gamut colors
- Uses deltaE OK (JND threshold: 0.02) for perceptual difference
- Ensures graceful degradation on sRGB displays

Python Implementation:
- parse_oklch(): OKLCH color parsing with gamut mapping
- parse_lab(): CIE LAB parsing with gamut mapping via OKLCH conversion
- lab_to_oklch(): LAB to OKLCH conversion for consistent gamut mapping
- oklch_to_srgb_gamut_map(): CSS Color 4 gamut mapping algorithm
- srgb_to_oklab(): Reverse conversion for deltaE calculations
- deltaE_ok(): Perceptual color difference in OKLab space

Go Implementation:
- colorspaces.go: All color space conversions and gamut mapping
- wrapper.go: ParseColor() updated to support OKLCH and LAB
- Comprehensive test coverage with benchmarks
- Matches Python implementation behavior

Robustness:
- NaN and infinity validation in all color parsing functions
- Defense-in-depth with validation at parsing and gamut mapping levels
- Returns None/error for invalid input (consistent error handling)
- Validates before clamping operations to prevent NaN propagation

Files changed:
- Python: kitty/rgb.py, kitty_tests/datatypes.py (+250 lines)
- Go: tools/utils/style/colorspaces.go, wrapper.go (+350 lines, tests)
- Docs: docs/wide-gamut-colors.rst (moved from inline)
- Config: kitty/options/definition.py (simplified, links to docs)

References:
- CSS Color Module Level 4: https://www.w3.org/TR/css-color-4/
- OKLCH Color Space: https://bottosson.github.io/posts/oklab/

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-27 14:34:34 +00:00
Kovid Goyal
d52f2e7981
Rewrite rendering pipeline
This was needed to fix various corner cases when doing blending of colors
in linear space. The new architecture has the same performance as the
old in the common case of opaque rendering with no UI layers or images.

In the case of only positive z-index images there is a performance
decrease as the OS Window is now rendered to a offscreen texture and
then blitted to screen. However, in the future when we move to Vulkan or
I can figure out how to get Wayland to accept buffers with colors in
linear space, this performance penalty can be removed. The performance
penalty was not significant on my system but this is highly GPU
dependent. Modern GPUs are supposedly optimised for rendering to
offscreen buffers, so we will see. The awrit project might be a good
test case.

Now either we have 1-shot rendering for the case of opaque with only ext
or all the various pieces are rendered in successive draw calls into an
offscreen buffer that is blitted to the output buffer after all drawing
is done.

Fixes #8869
2025-08-11 00:47:02 +05:30
Kovid Goyal
bca017fa4c
Fix #8741 2025-06-20 20:11:23 +05:30
Kovid Goyal
15781435ae
Cleanup reading of argv from files 2025-04-28 09:54:57 +05:30
Kovid Goyal
2093fb1310
Fix handling of empty quoted string in shlex 2025-04-26 08:55:32 +05:30
Kovid Goyal
7bd7709685
Move parsing of macos-launch-services-cmdline into native code
Avoids expensive re-exec and simplifies various things. Much faster
for single instance usage.
2025-04-25 14:39:36 +05:30
Kovid Goyal
639ad3e8a6
Make shlex code re-useable in launcher 2025-04-25 09:35:42 +05:30
Kovid Goyal
76ac66fc8c
Implement various filesystem utility functions in C so they can be used in the launcher 2025-04-24 20:37:51 +05:30
Kovid Goyal
3f919cbc56
Specify the algorithm for splitting text into cells 2025-04-11 09:34:21 +05:30
Kovid Goyal
b32a5492c5
Add test for wrap with combining char 2025-04-11 09:34:21 +05:30
Kovid Goyal
c01a941fe7
Get the unicode grapheme seg tests passing on screen, with minimal modification
We ignore tests including ACII control codes and we modify the results
when there are grapheme breaks before zero width characters.
2025-04-11 09:34:21 +05:30
Kovid Goyal
203e9f6c58
Port wcswidth to use grapheme segmentation 2025-04-11 09:34:21 +05:30
Kovid Goyal
66856e7b52
Use a multi-stage lookup table for grapheme segmentation 2025-03-31 21:51:28 +05:30
Kovid Goyal
2aa2607adc
... 2025-03-25 17:13:54 +05:30
Kovid Goyal
3e50588525
Add a test for PUA recog 2025-03-25 16:52:01 +05:30
Kovid Goyal
0d866b1f13
Add tests for grapheme segmentation
Test data provided by Unicode organisation
2025-03-13 13:48:35 +05:30
Kovid Goyal
561686c9d4
Refactor rewrap code, again
Now we do the rewrap of history and line buffers together. This is
faster and deals with multiline chars split between the two buffers
correctly. Also, considerably simpler code.
2025-02-03 10:56:49 +05:30
Kovid Goyal
cf2fffaf95
Fix continuation char marking when rewrapping historybuf 2025-02-03 10:56:49 +05:30
Kovid Goyal
b5dff921c4
Start work on multicell support 2025-02-03 10:56:43 +05:30