Commit graph

162 commits

Author SHA1 Message Date
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
Kovid Goyal
0eaf44d33d
Add tests for strip_csi with multibyte 2024-11-24 09:28:21 +05:30
Kovid Goyal
5e36e0a324
Fix text_at 2024-11-04 09:10:07 +05:30
Kovid Goyal
30f4441fe5
Fix line_as_ansi 2024-11-04 09:10:07 +05:30
Kovid Goyal
913ce58fe3
Make shlex_split always return a token
Matches behavior of split() so is therefore more intuitive
2024-09-02 17:30:18 +05:30
Kovid Goyal
2b3f2258ff
More pyugrade to 3.9 2024-08-05 11:00:51 +05:30
Kovid Goyal
1c9d9e394c
Have close notifications indicate when notification is not found 2024-07-25 07:58:17 +05:30
Kovid Goyal
deff40df8a
New OSC 21 protocol for color control
Needs to be specced up
2024-07-22 10:57:13 +05:30
Kovid Goyal
0cf9a79760
A new option second_transparent_bg
Makes a second background color semi-transparent via background_opacity.
Useful for things like cursor line highlight in editors.

Fixes #7646
2024-07-21 20:22:31 +05:30
Kovid Goyal
098ed41716
Add support for ANSI-C quoted strings to shlex 2024-05-09 11:46:23 +05:30
Kovid Goyal
6205fb32fd
Refactor VT parser for more speed
No longer copy bytes into a separate buffer, instead parse them in place
in the read buffer
2024-02-25 09:57:23 +05:30
Kovid Goyal
23bb2e1b67
Fast function to replace c0 codes 2024-02-25 09:57:23 +05:30
Kovid Goyal
8cc2cad4d9
Use list of legal chars in URL from the WHATWG standard
Notably this excludes some ASCII chars: <>{}[]`|
See https://url.spec.whatwg.org/#url-code-points

Fixes #7095
2024-02-05 13:27:22 +05:30
Kovid Goyal
b0ba4b4a42
Fast and robust implementation of shlex.split
Also returns position of words in src string which we will need for
keymap parsing.
2023-12-02 14:57:02 +05:30
Kovid Goyal
77292a16d6
Make shebangs consistent
Follow PEP 0394 and use /usr/bin/env python so that the python in the
users venv is respected. Not that the kitty python files are meant to be
executed standalone anyway, but, whatever.

Fixes #6810
2023-11-11 08:32:05 +05:30
Kovid Goyal
defa2e29ac
Always ask for confirmation when pasting text with control codes in it 2023-10-20 13:02:28 +05:30
Kovid Goyal
56963c693e
When pasting in bracketed paste mode and the cursor is at a shell prompt, strip out C0 control codes
Some shells incorrectly interpret these allowing escape from bracketed paste mode. Thanks to David Leadbetter for discovering.
2023-10-20 12:17:13 +05:30
Kovid Goyal
750018e5fe
... 2023-05-25 12:25:46 +05:30
Kovid Goyal
cb936c1b5b
Use /dev/null rather than /dev/tty for the test 2023-05-25 12:24:59 +05:30
Kovid Goyal
624007c7aa
Refuse to read image files in /proc /sys and /dev
Also, open the image file with O_NONBLOCK to ensure we dont hang opening
a FIFO
2023-05-25 12:17:03 +05:30
Kovid Goyal
7fe5d7b58f
Replace isort with ruff 2023-01-09 16:47:42 +05:30
Kovid Goyal
306f9e5735
Prettify URLs before displaying them to the user 2022-12-29 17:04:02 +05:30
Kovid Goyal
68cf9f7514
Switch to tracking linewrap on the last cell in a line
This allows us to have newline not affect the wrap status of a line.

Now a lines wrapping status is changed only when the last cell
in the line is changed. This actually matches the behavior of many other
terminal emulators so is probably a good thing from a ecosystem
compatibility perspective.

The fish shell expects this weird behavior of newline not changing
wrapping status, for unknown reasons, which is the actual motivation for
doing all this work.

Fixes #5766
2022-12-26 20:26:21 +05:30
Kovid Goyal
c6360537e5
Try to fix tests failing on Python 3.11 2022-12-16 10:05:05 +05:30