Commit graph

230 commits

Author SHA1 Message Date
Egor Ignatov
5561bc2900 Fix NULL_COLOR_VALUE on 32-bit platforms
Export NULL_COLOR_VALUE using PyLong_FromUnsignedLong instead of
PyModule_AddIntMacro, which converts it to a signed long. On 32-bit
platforms this turns 0xffffffff into -1 and causes the generated Go
uint32 constant to overflow, preventing kitten from building.

Add a regression check for the exported value.
2026-11-09 13:01:06 +03:00
Kovid Goyal
bc9d0b87e3
Custom shaders: Add command and alternate screen events and uniforms
Add the command-start, command-finish, alternate-screen-enter and
alternate-screen-exit events, which fire for changes in the active window,
and the active_window_command_running, active_window_alternate_screen,
active_window_command_state_age and active_window_alternate_screen_age
fields to KittyCustomShaderData, so shaders can show effects while
commands run and hide them in full screen programs.
2026-11-05 08:43:37 +05:30
Kovid Goyal
7670f895a6
IME: Show the cursor at the position reported by the input method in the pre-edit text
Previously the cursor was always drawn after the pre-edit text, as the
cursor position sent by the input method was ignored, so one could not see
which character was being edited when moving inside the pre-edit text, as
with Chewing. Pass the pre-edit cursor from IBus, Wayland text-input and
macOS to kitty, in code points, and place the cursor there. On Wayland, do
not drop pre-edit updates that only move the cursor.

Also use the pre-edit cells rather than the original line under them to
size and color the cursor, so that it covers wide pre-edit characters.

The IME candidate window remains anchored at the start of the pre-edit text.

Fixes #10807
2026-11-05 08:26:34 +05:30
Kovid Goyal
731e0856ec
Fix #10794 2026-11-02 20:05:14 +05:30
Kovid Goyal
6655b2d05d
Cleanup previous PR
Preserve the grapheme segmentation state when the drawing line is
re-initialized after the current char has already been segmented, so that
emoji sequences are not split into multiple cells when wrapped or moved
past scaled text.
2026-10-29 14:42:27 +05:30
Hassan Raza
7703844024
Cover scaled-text collisions at scrolling margins and on the alternate screen 2026-10-29 12:28:40 +05:00
Hassan Raza
8e654b4e4d
Cover wide text crossing scaled glyphs and scrolling 2026-10-29 12:28:40 +05:00
Kovid Goyal
bc46f1bafc
Make mark colors respect color layers
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
Mark colors are now stored per color layer and for the colors set by the
program, like the other colors, instead of in a single array that every
change overwrote. So set-colors without --configured no longer changes the
configured mark colors, window and session layer mark colors survive
changes to the global colors, resetting a layer, the color stack and full
reset restore the correct mark colors, --copy-colors copies them and
get-colors reports the mark colors of the window.
2026-10-29 08:57:18 +05:30
Kovid Goyal
862c8657be
Cleanup previous PR
Make ColorProfile.test_mark_colors() return MARK_MASK pairs instead of a
hard-coded three, simplify the test by using MARK_MASK and mutable expected
values, and correct the changelog entry: config reload was not affected,
set-colors, launch --color, sessions and automatic theme switching were.
2026-10-29 08:52:08 +05:30
Vitor Araujo Boufleur
3459adc4fc Fix live text-marker colour slot indexing 2026-10-28 16:23:18 -03:00
Kovid Goyal
1fee9e89f6
ssh kitten: Allow per-host color schemes for dark and light mode
New color_scheme_dark, color_scheme_light and color_scheme_no_preference
options. When any of them is set, the ssh kitten sends the color schemes
for all three system color schemes to kitty, which applies the one
matching the current system color scheme and switches between them when
the system color scheme changes. color_scheme is used for modes without
a specific color scheme.

The colors are applied in a new session color layer, above the colors of
the window and below colors set by programs. They are associated with the
color stack entry pushed by the ssh kitten and are removed when it is
popped, so nested sessions work and the colors are restored on exit.

Configs that only use color_scheme continue to use escape codes exactly
as before, as does the kitten when running inside tmux.

Fixes #10724
2026-10-23 09:37:50 +05:30
Kovid Goyal
4a343a1801
Keep per-window and program colors when the system color theme changes
Colors in a window are now tracked in layers: the global configured colors
(kitty.conf and the automatic color theme), the colors of the individual
window (launch --color, --copy-colors) and the colors set by the program
running in the window (escape codes, set-colors without --configured).
Switching between light and dark themes changes only the global layer, so
colors set by the ssh kitten, by programs or by launch --color are no
longer overwritten.

Only the colors set by the program are saved on the color stack, so
popping the stack, for example when exiting the ssh kitten, uses the
current theme colors for everything else rather than those from before
the theme change. launch --color colors now also survive config reloads.

set-colors --configured still replaces colors set in the matched windows.

Fixes #10724
2026-10-23 09:22:17 +05:30
Kovid Goyal
aef2bc2306
Fix continuous re-rendering when a selection exists and window is scrolled
The selection dirty check computed iteration data in a different
coordinate system than apply_selection() used to store last_rendered,
so the two never compared equal when scrolled back, causing the
selection buffer to be re-uploaded and the window redrawn every frame.
Use a common helper for both.

Fixes #10714
2026-10-21 21:07:39 +05:30
Kovid Goyal
c0b384f310
Cleanup previous PR 2026-10-18 07:58:49 +05:30
Kovid Goyal
42eb2a1c3b
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
- Anchor the IME cursor rectangle at the column the pre-edit text is
  actually drawn at, which is shifted left of the cursor when the text
  would not otherwise fit on the line, instead of at the cursor column.
- Store the IBus cursor geometry cache per input context rather than in
  a function static, only update it after a successful send and reset it
  whenever a new input context is created.
- Add a test and a changelog entry.
2026-10-10 12:45:19 +05:30
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
74fd8e792f Ignore fractional scroll amounts that are not finite 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
rudolf-blue
96f728cc82 Avoid copying the scrollback on height only resizes 2026-10-09 00:01:01 -04:00
rudolf-blue
37bfa25d0e Fix fractional scroll losing sub-line pixel remainders 2026-10-08 23:59:57 -04:00
rudolf-blue
fc63c2590f Fix off by one continued flag in dump_lines_with_attrs 2026-10-08 23:59:57 -04:00
rudolf-blue
f16d09603e Allow 16 entries on the pointer shape stack 2026-10-08 23:59:57 -04:00
rudolf-blue
d2a272bb98 Fix dotted and dashed underline SGR in as_ansi output 2026-10-08 23:59:57 -04:00
rudolf-blue
4e7dade0ab Skip the activity callback when tab_activity_symbol is not set 2026-10-08 23:50:06 -04:00
Kovid Goyal
237a598cae
Fix heap buffer overflow in unicode_in_range()
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
When growing the buffer, realloc was passed the element count instead of
the byte count, shrinking the buffer while capacity was set to the larger
value. Lines with more than 4096 codepoints (e.g. many combining chars)
would then write past the end of the allocation.
2026-10-08 23:51:48 +05:30
Kovid Goyal
007e61a59e
Fix #10609 2026-10-05 20:34:59 +05:30
Hassan Raza
2ef024bbab
Collect stale hyperlinks before adding new links 2026-09-28 11:34:37 +05:00
Kovid Goyal
14e5d94efe
Allow specifying regexes for URL matching on hover
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
Fixes #10518
2026-09-26 11:08:43 +05:30
Kovid Goyal
2795eac486
add test for IME around cursor 2026-09-19 15:51:09 +05:30
Kovid Goyal
1fb52b8443
Cleanup previous PR and make VS15 on explicit width cell behavior consistent with VS16 2026-09-18 22:59:19 +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
03fbdad855
Color control protocol: Respond to unknown field names safely using base64 encoding 2026-09-01 21:20:04 +05:30
Kovid Goyal
9475a58f0b
autoformat 2026-08-22 13:01:01 +05:30
bjohas
dbabd12ba6 Style IME pre-edit text with italics and a dashed underline
Pre-edit text was drawn in reverse video, which is a solid inverted block
moving through the line as you compose. Draw it as italic with a dashed
underline in the highlight color instead.

Underline rather than reverse video is what other terminals do: VTE renders the
pre-edit run with the input method's own attributes and marks only the cursored
cell distinctly, and foot underlines the run explicitly, excluding the part
under the cursor. Dashed avoids the underline styles applications already use:
curly for spell checking and straight for hyperlinks, which is the collision
that made reverse video look like the safer choice.

The styling is applied to the overlay's own cursor and restored afterwards,
alongside the wrap, cursor-visibility and insert-replace modes already saved
there. The previous code toggled reverse with XOR, which restored itself; the
three new attributes are saved and put back explicitly.

Closes #10382
2026-08-22 07:22:55 +01:00
Kovid Goyal
e62ec6d540
Throughput improvements when processing large blocks of text
Mostly comes from detecting the case of runs of ASCII printable
characters and using a special fast path for them. Improves benchmarks
as per benchmark.py by 15-30% for text heavy workloads
2026-08-16 17:47:56 +05:30
Ayush Bhat
54cf9988d5 Fix hang on Scroll Up with a huge count
screen_scroll() looped `count` times with no upper bound, so CSI 2147483647 S
spun for ~2.1 billion iterations at 100% CPU and never returned, hanging the
whole terminal.

Scrolling up by more than the number of lines on screen blanks the entire
region, so clamp count to self->lines. Scroll Down (_reverse_scroll) already
caps its count the same way.

Fixes #10333
2026-08-08 22:03:03 +02:00
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
Tim Culverhouse
365f1a6b37
terminal: add visibility reports
Allow terminal applications to detect when their view is not observable so they can avoid unnecessary rendering work.

Implement mode 2033 and the visibility status query, and report changes from tab, pane, window, and platform occlusion state.
2026-07-28 14:25:12 -05:00
Kovid Goyal
0816716c72
Add support for DECSTR soft screen reset escape code
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
This escape code is largely undefined. There is no specification for how
it affects alternate screen mode, overriden colors, kitty keyboard
state, paused rendering, etc. Do what I feel is sensible in these cases.

Fixes #10263
2026-07-15 09:28:51 +05:30
Sinity
b2d5a36283
Garbage collect the text cache periodically so unique cell texts do not grow memory without bound
The TextCache interns every unique multi-codepoint cell text for the
lifetime of the window with no eviction, so a stream of unique texts
(for example random combining mark sequences) grows memory without
bound, several hundred MB/hour at moderate throughput.

Mirror the existing hyperlink pool garbage collection: every 8192
newly interned entries, steal the cache contents and have the Screen
remap the index in every live cell (history buffer, main and alt line
buffers, paused rendering snapshot and overlay line), re-interning
only entries still referenced by some cell. Entries whose last
reference scrolled out of the history buffer are freed.

See #10249

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-11 20:40:02 +02:00
Kovid Goyal
9cd2c60064
Clean previous PR
Some checks are pending
CI / Linux (python=3.13 cc=clang sanitize=1) (push) Waiting to run
CI / Linux (python=3.11 cc=gcc sanitize=0) (push) Waiting to run
CI / Linux (python=3.12 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-06-29 06:17:08 +05:30
amoena
207b22aa80
fix(erase_last_command): erase the most recent command even empty output
erase_last_command selected the region to erase via find_cmd_output(..., -1),
which anchors on OUTPUT_START (OSC, 133;C). Commands that produce no output
(an empty Enter, a comment, cd, export, etc. -- never emit 133;C, so they were
skipped and an older command-with-output was erased instead. "Erase the last
command" therefore did not erase the last command whenever the most recent ones
has no output.

Select the region by prompt marks instead: erase the prompt block immediately
above the current (live) prompt, whatever it contains. Every submittd command
is now one unit, removed newest-first, one prompt block per invocation.

This also fixes two latent defects in the previous implementation:

* The on-screen deletion was anchored at `cursor->y - count`, which
  assumes the region ends exactly one row above the cursor.
  Multi-line prompts and skipped rows broke that assumption and left
  residual lines. Anchor at the top of the region instead.

* When part of the erased region was in the scrollback, the lines
  were removed from the history buffer but no redraw was signalled,
  so the deletion of the off-screen lines only became visible after
  the next scroll event recomputed the history viewport. Clamp
  scrolled_by to the new history length and call dirty_scroll()
  after shrinking the buffer.

include_prompt is retained for API compatibility but is now a no-op: the
unit erased is always the whole prompt block.
2026-06-28 11:17:01 -03:00
Kovid Goyal
3fc5bed364
Merge branch 'decst8c' of https://github.com/aymanbagabas/kitty
Some checks failed
CI / Linux (python=3.13 cc=clang sanitize=1) (push) Has been cancelled
CI / Linux (python=3.11 cc=gcc sanitize=0) (push) Has been cancelled
CI / Linux (python=3.12 cc=gcc sanitize=1) (push) Has been cancelled
CI / Linux package (push) Has been cancelled
CI / Bundle test (macos-latest) (push) Has been cancelled
CI / Bundle test (ubuntu-latest) (push) Has been cancelled
CI / macOS Brew (push) Has been cancelled
CI / Test ./dev.sh and benchmark (push) Has been cancelled
CodeQL / CodeQL-Build (actions, ubuntu-latest) (push) Has been cancelled
CodeQL / CodeQL-Build (c, macos-latest) (push) Has been cancelled
CodeQL / CodeQL-Build (c, ubuntu-latest) (push) Has been cancelled
CodeQL / CodeQL-Build (go, ubuntu-latest) (push) Has been cancelled
CodeQL / CodeQL-Build (python, ubuntu-latest) (push) Has been cancelled
Depscan / Scan dependencies for vulnerabilities (push) Has been cancelled
2026-05-27 08:38:45 +05:30
Kovid Goyal
c7622683c8
Cleanup previous PR 2026-05-27 08:31:41 +05:30
Ayman Bagabas
c68a1654d3 feat(vt): add support for DECST8C escape sequence
Recognize CSI ? 5 W as DECST8C, which resets the active screen's tab
stops to the default of every 8 columns. Other CSI W variants continue
to produce a parse error.

Signed-off-by: Ayman Bagabas <aymanbagabas@gmail.com>
2026-05-26 21:12:27 -04:00
Ayman Bagabas
3138ae4aad fix(screen): preserve tab stops across window resizes
Previously, every window resize reinitialised the tab stops to the
default of every 8 columns, discarding any stops set via HTS or cleared
via TBC. ECMA-48 only treats RIS, DECSTR, and DECCOLM as events that
reset tab stops, and other terminal emulators all preserve user-set
stops across an interactive resize.

Copy the surviving prefix of the previous tab stops into the freshly
allocated array on both main and alt screens. Newly added columns when
growing the window keep the default every 8 columns pattern. Also point
the active tabstops pointer at the alt screen's array when a resize
happens while the alt screen is active, instead of unconditionally
resetting it to the main screen's array.

Signed-off-by: Ayman Bagabas <aymanbagabas@gmail.com>
2026-05-26 21:12:27 -04:00
n-WN
708372f249
tests: regression for apply_selection with paused-rendering + scrollback
Add a regression test that exercises the code path which crashed in
v0.46.2 (#10017): when paused_rendering is active and a selection
extends into the scrollback, the inner loop of apply_selection iterates
with a negative y. Without the recently-added paused_y translation and
the paused_y < 0 guard, the call to linebuf_init_line treats the
negative y as a huge unsigned index_type and reads ~4GB out of bounds
in line_attrs[idx], crashing with SIGBUS.

The test reproduces the trigger deterministically via the Screen Python
bindings and asserts that current_selections() returns the expected
buffer instead of crashing.
2026-05-16 17:00:01 +08:00
copilot-swe-agent[bot]
f6f1cae3b7
Fix issue #9834: preserve trailing spaces on soft-wrapped lines during copy
Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/343539f7-deab-4eeb-9829-99bec57c3523

Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
2026-04-08 17:17:20 +00:00