Commit Graph

12540 Commits

Author SHA1 Message Date
Mitchell Hashimoto
44496df899 input: use std.Io.Writer for key encoder, new API, expose via libghostty
This modernizes `KeyEncoder` to a new `std.Io.Writer`-based API.
Additionally, instead of a single struct, it is now an `encode` function
that takes a series of more focused options. This is more idiomatic Zig
while also making it easier to expose via libghostty-vt.

libghostty-vt also gains access to key encoding APIs.
2025-10-04 20:19:39 -07:00
Mitchell Hashimoto
503a25653f build: framegen can use self-hosted (#9021)
This was a red herring when I was doing the 0.15 port. It works with
self-hosted just fine.
2025-10-04 14:08:42 -07:00
Mitchell Hashimoto
e1568118ee Move paste encoding to the input package, test, optimize away one alloc (#9028)
This moves our paste logic to `src/input` in preparation for exposing
this as part of libghostty-vt. This yields an immediate benefit of unit
tests for paste encoding.

Additionally, we were able to remove one allocation on every unbracketed
paste path unless the input specifically contains a newline. Unlikely to
be noticable, but nice.

NOTE: This also includes one change in behavior: we no longer encode
`\r\n` and a single `\r`, but as a duplicate `\r\r`. This matches xterm
behavior and I don't think will result in any issues since duplicate
carriage returns should do nothing in well-behaved terminals.
2025-10-04 14:08:26 -07:00
Mitchell Hashimoto
d4dcecb071 Move paste encoding to the input package, test, optimize away one alloc
This moves our paste logic to `src/input` in preparation for exposing
this as part of libghostty-vt. This yields an immediate benefit of
unit tests for paste encoding. 

Additionally, we were able to remove one allocation on every unbracketed
paste path unless the input specifically contains a newline. Unlikely to
be noticable, but nice.

NOTE: This also includes one change in behavior: we no longer encode
`\r\n` and a single `\r`, but as a duplicate `\r\r`. This matches xterm
behavior and I don't think will result in any issues since duplicate
carriage returns should do nothing in well-behaved terminals.
2025-10-04 14:05:32 -07:00
Mitchell Hashimoto
18eee610bc Expand ~ in macos-custom-icon (#9024)
Since #8999, `macos-custom-icon` works when its a fully expanded
absolute path like `/Users/username/dir/icon.icns`, but not when it's
abbreviated as `~/dir/icon.icns`. Users were understandably surprised
and confused by this. This PR adds tilde expansion using `NSString`s
built-in property for this.

Also removed a line from the config docs that seemed erroneous. Given
that the option has a functional default, it seems incorrect to say that
it's required.
2025-10-04 07:18:50 -07:00
Mitchell Hashimoto
271024c982 font: Add comprehensive constraint tests (#9023)
As promised in #8990.

I opted for hardcoded metrics and bounding boxes rather than actually
loading fonts and glyphs, both to avoid backend dependence and limit the
focus to the constraint calculations themselves, and because I wanted to
test a case that isn't exhibited by any of the fonts available in the
repo.

This also fixes an error from #8990, probably due to a botched
cherry-pick or rebase.
2025-10-04 06:17:28 -07:00
Daniel Wennberg
3620132dfc Remove incorrect note from config docs 2025-10-04 00:13:23 -07:00
Daniel Wennberg
0b14026696 Expand ~ in macos-custom-icon 2025-10-04 00:13:23 -07:00
Daniel Wennberg
6bc60b6c64 Add comprehensive constraint tests 2025-10-03 22:30:52 -07:00
Daniel Wennberg
5360aeb8aa Fix botched cherry-pick from #8990 2025-10-03 22:20:45 -07:00
Mitchell Hashimoto
e07415a2e2 build: framegen can use self-hosted
This was a red herring when I was doing the 0.15 port. It works with
self-hosted just fine.
2025-10-03 14:41:05 -07:00
Mitchell Hashimoto
42a38ff672 snap: fix Zig 0.15 install 2025-10-03 14:12:04 -07:00
Mitchell Hashimoto
f052eb435e fix(font): Final font patcher fixes (#8847)
This is my final set of fixes to the font patcher/icon scaling code. It
builds on #8563 and there's not much reason to pay attention here until
that one has been reviewed (the unique changes in this PR only touch the
two `nerd_font_*` files; the other 8 files in the diff are just #8563).
However, I wanted to make sure the full set of changes/fixes I propose
are out in the open, such that any substantial edits by maintainers
(like in #7953) can take into account the full context.

I think this and the related patches should be considered fixes, not
features, so I hope they can be considered for a 1.2.x release.

This PR fixes some bugs in the extraction of scale and alignment rules
from the `font_patcher` script. Roughly in order of importance:

* Nerd fonts apply an offset to some codepoint ranges when extracting
glyphs from their original font (e.g., Font Awesome) and placing them in
a Nerd Font. Rules are specified in terms of the former codepoints, but
must be applied to the latter. This offset was previously not taken into
account, so rules were applied to the wrong glyphs, and some glyphs that
should have rules didn't get any.
* Previously, the rules from every single patch set was included, but
the embedded Symbols Only font doesn't contain all of them. Most
importantly, there's a legacy patch set that only exists for historical
reasons and is never used anymore, which was overwriting some other
rules because of overlapping codepoint ranges. Also, the Symbols Only
font contains no box drawing characters, so those rules should not be
included. With this PR, irrelevant patch sets are filtered out.
* Some patch sets specify overlapping codepoint ranges, though in
reality the original fonts don't actually cover the full ranges and the
overlaps just imply that they're filling each other's gaps. During font
patching, the presence/absence of a glyph at each codepoint in the
original font takes care of the ambiguity. Since we don't have that
information, we need to hardcode which patch set "wins" for each case
(it's not always the latest set in the list). Luckily, there are only
two cases.
* Many glyphs belong to scale groups that should be scaled and aligned
as a unit. However, in `font_patcher`, the scale group is _not_ used for
_horizontal_ alignment, _unless_ the entire scale group has a single
advance width (remember, the original symbol fonts are not monospace).
This PR implements this rule by only setting `relative_width` and
`relative_x` if the group is monospace.

There are some additional tweaks to ensure that each codepoint actually
gets the rule it's supposed to when it belongs to multiple scale groups
or patch sets, and to avoid setting rules for codepoints that don't
exist in the embedded font.
2025-10-03 13:53:04 -07:00
Mitchell Hashimoto
afa3d5e087 macos: avoid any zero-sized content size increments (#9020)
Fixes #9016
2025-10-03 13:52:42 -07:00
Daniel Wennberg
78f1bf1807 Handle font_patcher codepoint range overlaps 2025-10-03 13:50:11 -07:00
Daniel Wennberg
44951d9b1c Handle font_patcher codepoint offsets 2025-10-03 13:50:11 -07:00
Daniel Wennberg
d07237fff5 Skip patchsets and codepoints not in SymbolsNF 2025-10-03 13:50:11 -07:00
Daniel Wennberg
a1b7ea2e71 Add font_patcher's grouped vs individual alignment 2025-10-03 13:50:11 -07:00
Mitchell Hashimoto
21aa70dc8b fix(font): Fix positioning of scaled glyphs that don’t specify alignment (#8990)
Follow-up to #8563, which broke scaling without alignment. This change
recovers the behavior from before #8563, such that a scaled group is
clamped to the constraint width and height if necessary, and otherwise,
scaling does not shift the center of the group bounding box.

As a part of this change, horizontal alignment was rewritten to assume
the face is flush with the left edge of the cell. The cell-to-face
offset in the rendering code is then applied regardless of the value of
`align_horizontal`. This both simplifies the code and improves
consistency, as it ensures that the offset is the same for all
non-bitmap glyphs (rounded in FreeType, not rounded in CoreText). It's
the right thing to do following the align-to-face changes in #8563.
2025-10-03 13:49:48 -07:00
Daniel Wennberg
50bdd3bac6 Align stretched glyphs to cell, not face 2025-10-03 13:46:36 -07:00
Daniel Wennberg
32f8c71be3 Always clamp scaled glyph to cell
Also take padding into account for centered alignment, necessary since
our constraint type allows asymmetric padding.
2025-10-03 13:44:22 -07:00
Daniel Wennberg
7acf617763 fix(font): Anchor scaling at bounding box center 2025-10-03 13:44:22 -07:00
Mitchell Hashimoto
77114d7927 macos: avoid any zero-sized content size increments
Fixes #9016
2025-10-03 13:35:40 -07:00
Mitchell Hashimoto
b99ca6ad97 flush output for our builddata executable (#9019)
Fixes #9018

We were truncated our terminfo causing tmux to not respect some
features.
2025-10-03 13:33:59 -07:00
Mitchell Hashimoto
93c634c866 flush output for our builddata executable
Fixes #9018

We were truncated our terminfo causing tmux to not respect some
features.
2025-10-03 13:32:15 -07:00
Mitchell Hashimoto
fd64b833a4 fix(font): Apply glyph constraints before thickening and centering before quantizing (#8580)
In CoreText, when thickening (font smoothing) is enabled or Ghostty is
synthesizing a bold face, the glyph bounding box is padded to make sure
the thicker glyph can fit. Currently, this happens before applying
constraints (scaling and alignment), which makes the size and position
of constrained glyphs dependent on font size, font thickening strength,
and display DPI.

With this PR, constraints are applied before any other adjustments, and
padding is applied directly to the rasterization canvas without
modifying any metrics.

For consistency, I also moved constraint application above emboldening
in the FreeType code, although under that API, the two operations are
orthogonal as far as I can tell.

Secondly, this PR moves glyph centering above bitmap quantization, as
centering is generally fractional and will therefore undo the quantizing
if done after.

Supersedes #8552.
2025-10-03 12:55:23 -07:00
Daniel Wennberg
f245574087 Fix comment 2025-10-03 12:53:46 -07:00
Daniel Wennberg
5c129205a5 Use correct and consistent pre-constraint glyph rect
In Freetype, measure rect after emboldening, so constraints apply to the
true glyph size like in CoreText.

In CoreText, don't let font smoothing affect the rect (only the canvas).
2025-10-03 12:53:46 -07:00
Daniel Wennberg
96fbff681b Center before quantizing bitmap glyphs 2025-10-03 12:53:46 -07:00
Mitchell Hashimoto
071621a8c2 Fix typos (#9013)
This PR fixes typos I spotted in the project.
2025-10-03 10:04:35 -07:00
Andreas Deininger
a667b740ee Fix typos 2025-10-03 18:52:26 +02:00
Mitchell Hashimoto
f99a6846bc Add update-mirror Nu script to ease mirror updating for deps (#9010)
This adds a new script we can manually run that downloads all the files
that need to be uploaded to the mirror and updates our build.zig.zon.
The upload still happens manually [by me] but this simplifies the task
greatly.
2025-10-03 08:13:45 -07:00
Mitchell Hashimoto
f0eb46ea26 Add update-mirror Nu script to ease mirror updating for deps
This adds a new script we can manually run that downloads all the files
that need to be uploaded to the mirror and updates our build.zig.zon.
The upload still happens manually [by me] but this simplifies the task
greatly.
2025-10-03 07:39:41 -07:00
Mitchell Hashimoto
1c1a56394d apprt/gtk: Zig 0.15 whack a mole 2025-10-03 07:33:58 -07:00
Mitchell Hashimoto
4d97186643 apprt/gtk: fix Zig 0.15 2025-10-03 07:17:35 -07:00
Mitchell Hashimoto
e0cf528576 Zig 0.15 (#9004)
Replaces #8372 

Before merge I'm going to squash this and give @pluiedev coauthor, since
I took a lot of her work. I just have to go through this myself to make
sure I learn all the changes in Zig 0.15, but as I got things, I copy
and pasted her work in. My work is probably less thorough and there are
places we can convert deprecated things, probably, but this results in
green CI.

## Benchmarks

It looks like there are some speed regressions in isolated places. I'm
not sure if this is noise or not, I'm going to keep running some tests.
If someone can check macOS that'd be helpful (my vtebench is down on
macOS atm), cc @qwerasd205 if interested.

On an x86_64 system:


![output](https://github.com/user-attachments/assets/25395c18-2560-45c8-9fd3-d524bc5cbfb8)
2025-10-03 07:12:12 -07:00
Mitchell Hashimoto
569fe92389 fix up merge conflicts 2025-10-03 07:11:48 -07:00
Mitchell Hashimoto
bb98bc744d ci: disable freebsd for now 2025-10-03 07:10:44 -07:00
Mitchell Hashimoto
22caf60263 update a bunch of required Zig versions to 0.15 2025-10-03 07:10:44 -07:00
Mitchell Hashimoto
a41f59837e nix: update to unstable for Zig 0.15 in package 2025-10-03 07:10:44 -07:00
Mitchell Hashimoto
ba100dddff update deps 2025-10-03 07:10:44 -07:00
Mitchell Hashimoto
87b77e1980 ci: cleanup 2025-10-03 07:10:43 -07:00
Mitchell Hashimoto
4e3e0ed056 Zig 0.15: Flatpak 2025-10-03 07:10:43 -07:00
Mitchell Hashimoto
e1b5464bab Zig 0.15: build snap 2025-10-03 07:10:43 -07:00
Mitchell Hashimoto
2af424268a Zig 0.15: emit bench 2025-10-03 07:10:43 -07:00
Mitchell Hashimoto
9ec3b1b152 Zig 0.15: webdata 2025-10-03 07:10:43 -07:00
Mitchell Hashimoto
f0cfaa9580 zig 0.15: build on macOS 2025-10-03 07:10:43 -07:00
Mitchell Hashimoto
0112607532 Zig 0.15: zig build test macOS 2025-10-03 07:10:43 -07:00
Mitchell Hashimoto
d59d754e29 Zig 0.15: zig build GTK exe 2025-10-03 07:10:43 -07:00
Mitchell Hashimoto
cb295b84a0 Zig 0.15: zig build test 2025-10-03 07:10:43 -07:00