Skip to content

Add Terminal.text_sized() kitty text sizing#368

Merged
jquast merged 25 commits into
masterfrom
jq/text-sizing
May 4, 2026
Merged

Add Terminal.text_sized() kitty text sizing#368
jquast merged 25 commits into
masterfrom
jq/text-sizing

Conversation

@jquast
Copy link
Copy Markdown
Owner

@jquast jquast commented Apr 12, 2026

From bin/text_sizing_protocol.py:

Screenshot_20260410_185914

From bin/scroller.py:

kitty-text-sizing-.2.mp4

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 12, 2026

Merging this PR will degrade performance by 20.7%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 2 improved benchmarks
❌ 3 (👁 3) regressed benchmarks
✅ 23 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
test_truncate_cjk 7,034.3 µs 485.9 µs ×14
test_truncate_emoji_zwj 1,609.3 µs 937.9 µs +71.59%
👁 test_rjust_ansi 363.2 µs 458 µs -20.7%
👁 test_ljust_ansi 363.4 µs 458 µs -20.65%
👁 test_center_ansi 366.2 µs 460.8 µs -20.54%

Comparing jq/text-sizing (58821f2) with master (ab1b0be)

Open in CodSpeed

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.46%. Comparing base (ab1b0be) to head (58821f2).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #368      +/-   ##
==========================================
+ Coverage   97.44%   97.46%   +0.02%     
==========================================
  Files          13       13              
  Lines        3642     3673      +31     
  Branches      631      640       +9     
==========================================
+ Hits         3549     3580      +31     
  Misses         71       71              
  Partials       22       22              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jquast jquast changed the title kitty text sizing protocol (DRAFT) new: Kitty text sizing protocol May 2, 2026
@jquast jquast changed the title new: Kitty text sizing protocol Add Terminal.text_sized() kitty text sizing May 2, 2026
@jquast jquast marked this pull request as ready for review May 2, 2026 17:01
@jquast
Copy link
Copy Markdown
Owner Author

jquast commented May 3, 2026

The 3 regressions in ljust, center, and, rjust is that we now use wcwidth.width() with argumentcontrol_codes=parse, instead of control_codes=ignore as before.

"ignoring" control codes worked pretty well, but the more complex ones like OSC 66 kitty text sizing, and basic backspacing and cursor left "overtyping" all new in wcwidth 0.7.0 release require 'parse' to parse them.

So this regression is acceptable, we get better results by using 'parse' by default,

>>> wcwidth.ljust('hello\b\b\b\bworld', 10, control_codes='ignore', fillchar='.')
'hello\x08\x08\x08\x08world'
>>> wcwidth.ljust('hello\b\b\b\bworld', 10, control_codes='parse', fillchar='.')
'hello\x08\x08\x08\x08world....'

test_ljust_ansi 363.4 µs 461.7 µs -21.29%
test_center_ansi 366.2 µs 464.2 µs -21.11%
test_rjust_ansi 363.2 µs 461.2 µs -21.24%

I have included new documentation in docs/measuring.txt about the new ability to parse cursor movement sequences.

jquast added 5 commits May 2, 2026 22:06
- allow vertical/horizontal_align='top' (str) in addition to protocol code
- better "cleanup" our sequences on return, and verify with tests, the
  first use of 'text_sized()' call would cause some erroneous output,
  though partially fixed, it is now also well-documented in the
  documentation
@jquast jquast merged commit 22ea7ef into master May 4, 2026
16 checks passed
@jquast jquast deleted the jq/text-sizing branch May 4, 2026 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant