10952 Commits

Author SHA1 Message Date
Mitchell Hashimoto
390812828a Nuke GLFW, make zig build run on macOS build the Xcode project (#7815)
This PR does two things.

1. Build system improvements to make developing on macOS more enjoyable 
2. Delete the GLFW apprt

## Build System Improvements (macOS)

On macOS, there are a few major improvements:

* `zig build` now produces a full macOS app bundle and copies it into
`zig-out`
* `zig build run` now builds the macOS app and runs it, streaming logs
directly into the terminal
* `-Demit-macos-app` can control whether app bundle is created
* `-Dxcframework-target` can be set to one of `native` or `universal` to
control whether the xcframework uses only your target machines arch or
creates a universal one with macOS and iOS. This defaults to `native`
for the `run` command and `universal` for all others.
* The general flow of the `build.zig` file was improved to be more
declarative

## Nuke GLFW

> This deletes the GLFW apprt from the Ghostty codebase.
> 
> The GLFW apprt was the original apprt used by Ghostty (well, before
> Ghostty even had the concept of an "apprt" -- it was all just a single
> application then). It let me iterate on the core terminal features,
> rendering, etc. without bothering about the UI. It was a good way to
get
> started. But it has long since outlived its usefulness.
> 
> We've had a stable GTK apprt for Linux (and Windows via WSL) and a
> native macOS app via libghostty for awhile now. The GLFW apprt only
> remained within the tree for a few reasons:
> 
>   1. Primarily, it provided a faster feedback loop on macOS because
>      building the macOS app historically required us to hop out of the
>      zig build system and into Xcode, which is slow and cumbersome.
> 
>   2. It was a convenient way to narrow whether a bug was in the
> core Ghostty codebase or in the apprt itself. If a bug was in both
>      the glfw and macOS app then it was likely in the core.
> 
>   3. It provided us a way on macOS to test OpenGL.
> 
> All of these reasons are no longer valid. Respectively:
> 
> 1. Our Zig build scripts now execute the `xcodebuild` CLI directly and
>      can open the resulting app, stream logs, etc. This is the same
> experience we have on Linux. (Xcode has always been a dependency of
>      building on macOS in general, so this is not cumbersome.)
> 
>   2. We have a healthy group of maintainers, many of which have access
>      to both macOS and Linux, so we can quickly narrow down bugs
>      regardless of the apprt.
> 
> 3. Our OpenGL renderer hasn't been compatible with macOS for some time
>      now, so this is no longer a useful feature.
> 
> At this point, the GLFW apprt is just a burden. It adds complexity
> across the board, and some people try to run Ghostty with it in the
real
> world and get confused when it doesn't work (it's always been lacking
in
> features and buggy compared to the other apprts).
> 
> So, it's time to say goodbye. Its bittersweet because it is a big part
> of Ghostty's history, but we've grown up now and it's time to move on.
> Thank you, goodbye.
> 
> (NOTE: If you are a user of the GLFW apprt, then please fork the
project
> prior to this commit or start a new project based on it. We've warned
> against using it for a very, very long time now.)
2025-07-05 13:49:24 -07:00
Mitchell Hashimoto
0929f39e89 build: xcodebuild properly sets up resources 2025-07-05 13:36:31 -07:00
Mitchell Hashimoto
8653229607 ci: don't use the new macOS app emit yet 2025-07-05 07:26:02 -07:00
Mitchell Hashimoto
8b44d0b3bb build: make zig build run on macOS work with an empty zig-out 2025-07-05 07:22:42 -07:00
Mitchell Hashimoto
5fc0bbc58f build: add -Demit-macos-app 2025-07-05 07:05:36 -07:00
Mitchell Hashimoto
f04a388f00 bash: stop using PS0 for the 'cursor' feature (#7808)
Our use of PS0 (which bash runs before command execution) was causing
raw command sequences to be printed between multiple commands in a
sequence.

    $ alias garbage='echo start
    > echo end'

    $ garbage
    start
    �\���dend

I wasn't able to definitely track down all of the reasons for why this
only happens in the command sequence case, but I suspect it's related to
the way that __ghostty_preexec runs from within the bash DEBUG trap (by
way of bash-preexec).

This problem occurs when PS0 is set to _any_ string (even "") inside of
__ghostty_preexec, which also rules out most/any Ghostty-specific code.
PS1 and PS2 appear to be safe to (re)set in this context.

Fortunately, we can avoid using PS0 entirely by instead printing the
cursor reset escape sequence directly from __ghostty_precmd because it
also runs just before command execution.

Fixes #7802
2025-07-04 21:05:41 -07:00
Mitchell Hashimoto
d223cfce1d fix: draw cursor on top of text for most cursor styles (#7810)
This addresses #7739.

## Changes
* Added second cursor list to the renderer as suggested
* Modified `Contents.setCursor` to accept a cursor style argument in
order to conditionally render the cursor
* Not sure if this the optimal workaround so suggestions would be
appreciated

## Screenshots
Block:
![Screenshot 2025-07-04 at 7 10
19 PM](https://github.com/user-attachments/assets/39caf936-863b-42f3-9ca9-a32a2da237b8)

Hollow block:
![Screenshot 2025-07-04 at 7 10
06 PM](https://github.com/user-attachments/assets/5063e1a0-06c7-46d1-9118-5855bff7cc5c)
2025-07-04 21:05:04 -07:00
Daniel
1a4b128af3 replace nested if for readability 2025-07-04 21:36:17 -04:00
Jon Parise
b8931dd1db bash: stop using PS0 for the 'cursor' feature
Our use of PS0 (which bash runs before command execution) was causing
raw command sequences to be printed between multiple commands in a
sequence.

    $ alias garbage='echo start
    > echo end'

    $ garbage
    start
    �\���dend

I wasn't able to definitely track down all of the reasons for why this
only happens in the command sequence case, but I suspect it's related to
the way that __ghostty_preexec runs from within the bash DEBUG trap (by
way of bash-preexec).

This problem occurs when PS0 is set to _any_ string (even "") inside of
__ghostty_preexec, which also rules out most/any Ghostty-specific code.
PS1 and PS2 appear to be safe to (re)set in this context.

Fortunately, we can avoid using PS0 entirely by instead printing the
cursor reset escape sequence directly from __ghostty_precmd because it
also runs just before command execution.
2025-07-04 20:06:06 -04:00
Daniel
0b4a1e2154 added test for other cursor style 2025-07-04 18:54:55 -04:00
Daniel
a9fc3b6fa0 enable drawing cursor on top or bottom based on style 2025-07-04 18:50:23 -04:00
Daniel
de3e77570e add second cursor list 2025-07-04 18:26:27 -04:00
Mitchell Hashimoto
91ee75ae4d build: add -Dxcframework-target to specify the target for builds 2025-07-04 15:01:14 -07:00
Mitchell Hashimoto
3793dac313 build: zig build run only builds xcframework for current arch 2025-07-04 14:56:25 -07:00
Mitchell Hashimoto
fb9c52ecf4 Nuke GLFW from Orbit
This deletes the GLFW apprt from the Ghostty codebase.

The GLFW apprt was the original apprt used by Ghostty (well, before
Ghostty even had the concept of an "apprt" -- it was all just a single
application then). It let me iterate on the core terminal features,
rendering, etc. without bothering about the UI. It was a good way to get
started. But it has long since outlived its usefulness.

We've had a stable GTK apprt for Linux (and Windows via WSL) and a
native macOS app via libghostty for awhile now. The GLFW apprt only
remained within the tree for a few reasons:

  1. Primarily, it provided a faster feedback loop on macOS because
     building the macOS app historically required us to hop out of the
     zig build system and into Xcode, which is slow and cumbersome.

  2. It was a convenient way to narrow whether a bug was in the
     core Ghostty codebase or in the apprt itself. If a bug was in both
     the glfw and macOS app then it was likely in the core.

  3. It provided us a way on macOS to test OpenGL.

All of these reasons are no longer valid. Respectively:

  1. Our Zig build scripts now execute the `xcodebuild` CLI directly and
     can open the resulting app, stream logs, etc. This is the same
     experience we have on Linux. (Xcode has always been a dependency of
     building on macOS in general, so this is not cumbersome.)

  2. We have a healthy group of maintainers, many of which have access
     to both macOS and Linux, so we can quickly narrow down bugs
     regardless of the apprt.

  3. Our OpenGL renderer hasn't been compatible with macOS for some time
     now, so this is no longer a useful feature.

At this point, the GLFW apprt is just a burden. It adds complexity
across the board, and some people try to run Ghostty with it in the real
world and get confused when it doesn't work (it's always been lacking in
features and buggy compared to the other apprts).

So, it's time to say goodbye. Its bittersweet because it is a big part
of Ghostty's history, but we've grown up now and it's time to move on.
Thank you, goodbye.

(NOTE: If you are a user of the GLFW apprt, then please fork the project
prior to this commit or start a new project based on it. We've warned
against using it for a very, very long time now.)
2025-07-04 14:12:18 -07:00
Mitchell Hashimoto
7bd90e6ec4 Build system can build macOS app bundle and open it
`zig build run` on macOS now builds the app bundle via the `xcodebuild`
CLI and runs it. The experience for running the app is now very similar
to Linux or the prior GLFW build, where the app runs, blocks the zig
command, and logs to the terminal.

`xcodebuild` has its own build cache system that we can't really hook
into so it runs on every `zig build run` command, but it does cache and
I find its actually relatively fast so I think this is a good
replacement for the glfw-based system.
2025-07-04 13:32:15 -07:00
Mitchell Hashimoto
908eb6d156 On wait-after-command (or abnormal exit), only close on encoded key (#7800)
Fixes #7794

This commit also resets some terminal state to give us a better chance
of getting an encoded key, such as ensuring keyboard input is enabled
and disabling any Kitty protocols. This shouldn't ever be set but just
in case!
2025-07-04 07:47:57 -07:00
Mitchell Hashimoto
d4743378cf macOS: remove @DeferredProperty usage from TerminalEntity (#7799)
This fixes an Apple Shortcuts crash for macOS 15 and earlier.
Unfortunately it looks like we can't guard these with `@available`. I'm
going to report an Apple Feedback about this but for now this gets
shortcuts working on macOS 15 and earlier.
2025-07-04 07:42:21 -07:00
Mitchell Hashimoto
eea073c97b On wait-after-command (or abnormal exit), only close on encoded key
Fixes #7794

This commit also resets some terminal state to give us a better chance
of getting an encoded key, such as ensuring keyboard input is enabled
and disabling any Kitty protocols. This shouldn't ever be set but just
in case!
2025-07-04 07:41:01 -07:00
Mitchell Hashimoto
d8838cff0b macOS: remove @DeferredProperty usage from TerminalEntity
This fixes an Apple Shortcuts crash for macOS 15 and earlier.
Unfortunately it looks like we can't guard these with `@available`. I'm
going to report an Apple Feedback about this but for now this gets
shortcuts working on macOS 15 and earlier.
2025-07-04 07:30:26 -07:00
Leah Amelia Chen
887a77fbab Request translators to update the CODEOWNERS file (#7798) 2025-07-04 08:38:58 +00:00
Kat
95d9b1e627 Request translators to update the CODEOWNERS file. 2025-07-04 18:08:18 +10:00
Mitchell Hashimoto
1213e919d4 Handle exec failures more gracefully (#7793)
Fixes #7792

Our error handling for `exec` failing within the forked process never
actually worked! It triggered all sorts of issues. We didn't catch this
before because it used to be exceptionally hard to fail an exec because
we used to wrap ALL commands in a `/bin/sh -c`.

However, we now support direction execution, most notably when you do
`ghostty -e <command>` but also via the `direct:` prefix on configured
commands.

This fixes up our exec failure handling by printing a useful error
message and avoiding any errdefers in the child which was causing the
double-close.
2025-07-03 21:39:08 -07:00
Mitchell Hashimoto
e494d94fb3 Handle exec failures more gracefully
Fixes #7792

Our error handling for `exec` failing within the forked process never
actually worked! It triggered all sorts of issues. We didn't catch this
before because it used to be exceptionally hard to fail an exec because
we used to wrap ALL commands in a `/bin/sh -c`.

However, we now support direction execution, most notably when you do
`ghostty -e <command>` but also via the `direct:` prefix on configured
commands.

This fixes up our exec failure handling by printing a useful error
message and avoiding any errdefers in the child which was causing the
double-close.
2025-07-03 21:31:03 -07:00
Mitchell Hashimoto
8e14d26275 config: for now, make goto_tab NOT performable on macOS (#7788)
Fixes #7786
Fixes regression from #7683

This is a band-aid fix. The issue is that performable keybinds don't
show up in the reverse mapping that GUI toolkits use to find their key
equivalents. The full explanation of why is already in Binding.zig.

For macOS, we have a way to validate menu items before they're triggered
so we ideally do want a way to get reverse mappings even with
performable keybinds. But I think this wants to be optional and that's
all a bigger change. For now, this is a simple fix that will work.
2025-07-03 13:51:54 -07:00
Mitchell Hashimoto
e1be836283 config: for now, make goto_tab NOT performable on macOS
Fixes #7786
Fixes regression from #7683

This is a band-aid fix. The issue is that performable keybinds don't
show up in the reverse mapping that GUI toolkits use to find their key
equivalents. The full explanation of why is already in Binding.zig.

For macOS, we have a way to validate menu items before they're triggered
so we ideally do want a way to get reverse mappings even with
performable keybinds. But I think this wants to be optional and that's
all a bigger change. For now, this is a simple fix that will work.
2025-07-03 13:45:41 -07:00
Mitchell Hashimoto
3e9cfacb7d feat: support selection foreground being cell foreground (#5219)
This resolves #2685.

## Changes

* Created `SelectionColor` tagged union that can take a `Color`,
`cell-foreground`, or `cell-background`
* Used the new union to implement the feature for Metal and OpenGL
* Removed the use of `invert_selection_fg_bg` during rendering as
suggested in the issue

## Demo

macOS:


https://github.com/user-attachments/assets/b5b2db83-bb62-4929-8e3c-870a1e1a7a5c

Ubuntu:


https://github.com/user-attachments/assets/259dd707-d9d9-4590-8f3c-a67ccdef34bc


Any feedback would be helpful, I'm sure there's a lot of room for
improvement here.
2025-07-03 09:31:27 -07:00
Mitchell Hashimoto
32764f3a1d fix test syntax 2025-07-03 09:29:36 -07:00
Mitchell Hashimoto
465ac5b1b7 clean up some of the color usage, use exhaustive switches 2025-07-03 09:25:56 -07:00
Qwerasd
ffbba3e460 renderer/opengl: fix issue with cell bg alignment on some systems (#7783)
Discussed in #7714, fix confirmed by user as working.

Okay, so, what the hell? This implies that on this user's system,
something that *should* be an integer multiple of the cell width, when
divided by the cell width, is giving some epsilon less than the proper
result. I can only guess that this is driver or hardware weirdness,
possibly the fragcoord is being converted from a low precision float in
NDC to the fragment-space coordinate so we're not actually getting an
integer multiple, and the epsilon less is actually before the division?

Regardless, switching it back to use halves for pixel coordinates fixes
this and shouldn't break the math at all, since `floor((n * k + 0.5)/k)`
should always yield `n` just like without the `+ 0.5`.
2025-07-03 10:05:52 -06:00
Mitchell Hashimoto
e87e5e7361 backwards compatibility handlers for removed fields 2025-07-03 07:30:55 -07:00
Daniel
95de198761 Squash and rebase, updated refactored version with selection and cursor cell color changes 2025-07-03 07:14:37 -07:00
Daniel
9e341a3d60 Created tagged union for selection colors, enabled parsing
Implemented cell color for Metal

Removed use of selection-invert-fg-bg

Mirrored feature to OpenGL

Added tests for SelectionColor

Fixed selection on inverted cell behavior

Implemented cell colors for cursor-text

Implemented cell colors for cursor-color, removed uses of cursor-invert-fg-bg during rendering

Updated docs for dynamically colored options

Updated docstrings, cleaned up awkward formatting, and moved style computation to avoid unnecssary invocations

Bump version in docstrings
2025-07-03 07:14:37 -07:00
Mitchell Hashimoto
7bb6d3b728 Do not resolve the symbolic link for the initial working directory (#7773)
Fixes #7769
2025-07-03 07:11:01 -07:00
Basil Crow
182f8ddd1a Do not resolve the symbolic link for the initial working directory 2025-07-03 07:09:24 -07:00
Qwerasd
1270e04480 renderer/opengl: maybe fix issue with cell bg alignment
By using integers for the fragcoords I may have stepped on an edge case
which causes cell background positions to be shifted by 1 px under some
circumstances. I couldn't reproduce that issue in a VM, so I'm making
this commit for the user who was having the problem to test it.
2025-07-02 17:43:05 -06:00
Mitchell Hashimoto
f1f9d5eb4b Fix some config help that caused website errors when copied 2025-07-02 16:21:37 -07:00
Qwerasd
4d609a884e (macOS) Memory Leak Fixes (#7770)
This PR contains fixes for 4 different memory leaks that affected
Ghostty on macOS.

1. (whenever a font is loaded) CoreText font features dict list wasn't
properly released. Fixed by releasing.
2. (whenever a font is searched for) CoreText discovery iterator
descriptors weren't properly released. Fixed by releasing.
3. (during resize) Metal texture descriptors were not properly released.
Fixed by releasing.
4. (every frame) Objective-C runtime blocks for buffer completion
handler and IOSurfaceLayer set surface were not properly deallocated due
to issues with the internal implementation in `zig-objc`. Fixed in
`zig-objc`, dependency hash updated with fix.

A handful of small apparent leaks remain but their cause is not clear
and they're all static (not increasing over time, seemingly).

### Xcode memory graph "leaks" comparison
|Before (main)|After (this PR)|
|-|-|
|<img width="445" alt="image"
src="https://github.com/user-attachments/assets/d1c89918-8ab2-4201-bf1e-9b3a519a85a8"
/>|<img width="445" alt="image"
src="https://github.com/user-attachments/assets/88c60807-756e-48d8-9918-2a52d6556035"/>|

<sup>Images taken after launching Ghostty, creating 4 tabs, and rapidly
switching between them to force render many frames.</sup>

---

Hopefully this fixes the occasional OOM issues some users have reported.
2025-07-02 17:08:34 -06:00
Qwerasd
8ed08aaecf deps: update zig-objc
This update also fixes a memory leak that was caused by blocks not being
deallocated and just collecting every single frame, slowly accumulating
memory until OOM.
2025-07-02 16:38:13 -06:00
trag1c
16513e4eb6 Adding a Bulgarian localization. (#7390) 2025-07-02 22:34:55 +02:00
trag1c
5dd1ebb583 add newline to end of file 2025-07-02 22:17:17 +02:00
Qwerasd
1f733c9e7f renderer/metal: properly release texture descriptors
Fixes memory leak. We always need to release these descriptors; the
textures themselves will retain or copy them if necessary.
2025-07-02 11:48:30 -06:00
Qwerasd
a91f9ed0e2 font/coretext: fix small memory leak 2025-07-02 11:38:26 -06:00
Qwerasd
2a836b0ab7 font/coretext: fix small memory leak 2025-07-02 11:02:33 -06:00
Qwerasd
776d25b065 Even More Sprite Glyphs (#7761)
Follow-on to #7755, adds the sixteenth blocks from the Symbols for
Legacy Computing Supplement and a few circle/ellipse glyphs that connect
to existing glyphs.

In order to add the one sixteenth blocks I reworked block element
alignment to not use the `yHalfs`, `yThirds`, etc. functions, but
instead a more versatile `Fraction` type I introduced, and making these
changes slightly affected how the vertical/horizontal eighths glyphs are
sized, and the horizontal center-point alignment of the smooth mosaic
glyphs for odd cell widths (shifted by half a pixel), but I believe both
of these to be improvements.

### Circle/ellipse glyphs
```
Existing sprites:
🯠 🯡 🯢 🯣

Which connect like so:
🯢🯡🯣
🯠

New sprites:
𜸀 𜸁 𜸋 𜸌

Which connect like so:
🯡𜸀𜸀🯣 🯢 𜸋𜸌
    𜸁
    𜸁
    🯠
```
|Main (via font)|This PR (via sprites)|
|-|-|
|![image](https://github.com/user-attachments/assets/b0102f7e-1cb3-4842-a8c6-352df6d5264f)|![image](https://github.com/user-attachments/assets/9a35d444-39ff-41e1-a632-597f195090a8)|

### Diffs
|Range|||||
|-|-|-|-|-|
|U+1CE00...U+1CEFF|![sprite_face_diff-U+1CE00 U+1CEFF-9x17+1](https://github.com/user-attachments/assets/632daca9-9d1e-458b-b645-3841de9f4915)|![sprite_face_diff-U+1CE00 U+1CEFF-11x21+2](https://github.com/user-attachments/assets/47731d99-9e1a-4005-a56c-dc9af3c38160)|![sprite_face_diff-U+1CE00 U+1CEFF-12x24+3](https://github.com/user-attachments/assets/2a4fd0d7-4114-480d-91e8-f8182ef0ff2b)|![sprite_face_diff-U+1CE00 U+1CEFF-18x36+4](https://github.com/user-attachments/assets/17b886b8-ad6d-4503-85dd-10ea2f734c09)|
|U+1FB00...U+1FBFF|![sprite_face_diff-U+1FB00 U+1FBFF-9x17+1](https://github.com/user-attachments/assets/c24814ea-67ef-4030-819b-a3f3d6ddac0c)|![sprite_face_diff-U+1FB00 U+1FBFF-11x21+2](https://github.com/user-attachments/assets/354ebadf-5d9c-4681-86c8-f6c21f82932e)|![sprite_face_diff-U+1FB00 U+1FBFF-12x24+3](https://github.com/user-attachments/assets/9fbb2c21-9ccd-466c-9bde-b8ce63e5df8b)|![sprite_face_diff-U+1FB00 U+1FBFF-18x36+4](https://github.com/user-attachments/assets/f76866ab-21c4-43b8-a591-009c4399ce17)|
2025-07-01 17:42:51 -06:00
Mitchell Hashimoto
d88adb131c linux: add install target to systemd user service (#7757)
This will allow users to enable Ghostty startup on login. Users will
need to explicitly enable startup on login via this command:

```sh
systemctl enable --user com.mitchellh.ghostty.service
```
2025-07-01 16:03:58 -07:00
Mitchell Hashimoto
d9d884b6e2 reload configuration on SIGUSR2 (#7759)
This is done at the apprt-level for a couple reasons.

  (1) For libghostty, we don't have a way to know what the embedding
      application is doing, so its risky to create signal handlers that
      might overwrite the application's signal handlers.

  (2) It's extremely messy to deal with signals and multi-threading.
      Apprts have framework access that handles this for us.

For GTK, we use g_unix_signal_add.

For macOS, we use `DispatchSource.makeSignalSource`. This is an awkward
API but made for this purpose.
2025-07-01 16:03:48 -07:00
Qwerasd
cff6860fd9 font/sprite: update reference images 2025-07-01 17:03:10 -06:00
Qwerasd
0cd95a791f font/sprite: add sflc supplement circle/ellipse glyphs 2025-07-01 16:52:17 -06:00
Mitchell Hashimoto
2fa4fc8902 reload configuration on SIGUSR2
This is done at the apprt-level for a couple reasons.

  (1) For libghostty, we don't have a way to know what the embedding
      application is doing, so its risky to create signal handlers that
      might overwrite the application's signal handlers.

  (2) It's extremely messy to deal with signals and multi-threading.
      Apprts have framework access that handles this for us.

For GTK, we use g_unix_signal_add.

For macOS, we use `DispatchSource.makeSignalSource`. This is an awkward
API but made for this purpose.
2025-07-01 15:51:58 -07:00