533 Commits

Author SHA1 Message Date
Mitchell Hashimoto
df97c19a37 macOS: "option-as-alt" defaults to "true" for US keyboard layouts
A common issue for US-centric users of a terminal is that the "option"
key on macOS is not treated as the "alt" key in the terminal.

## Background

macOS does not have an "alt" key, but instead has an "option" key. The "option"
key is used for a variety of purposes, but the troublesome behavior for some
(and expected/desired behavior for others) is that it is used to input special
characters.

For example, on a US standard layout, `option-b` inputs `∫`. This is not
a typically desired character when using a terminal and most users will
instead expect that `option-b` maps to `alt-b` for keybinding purposes
with whatever shell, TUI, editor, etc. they're using.

On non-US layouts, the "option" key is a critical modifier key for
inputting certain characters in the same way "shift" is a critical
modifier key for inputting certain characters on US layouts.

We previously tried to change the default for `macos-option-as-alt`
to `left` (so that the left option key behaves as alt) because I had the
wrong assumption that international users always used the right option
key with terminals or were used to this. But very quickly beta users
with different layouts (such as German, I believe) noted that this is
not the case and broke their idiomatic input behavior. This behavior was
therefore reverted.

## Solution

This confusing behavior happened frequently enough that I decided to
implement the more complex behavior in this commit. The new behavior is
that when a US layout is active, `macos-option-as-alt` defaults to true
if it is unset. When a non-US layout is active, `macos-option-as-alt`
defaults to false if it is unset. This happens live as users change
their keyboard layout.

**An important goal of Ghostty is to have zero-config defaults** that
satisfy the majority of users. Fiddling with configurations is -- for
most -- an annoying task and software that works well enough out of the
box is delightful. Based on surveying beta users, I believe this commit
will result in less configuration for the majority of users.

## Other Terminals

This behavior is unique amongst terminals as far as I know.
Terminal.app, Kitty, iTerm2, Alacritty (I stopped checking there) all
default to the default macOS behavior (option is option and special
characters are inputted).

All of the aforementioned terminals have a setting to change this
behavior, identical to Ghostty (or, Ghostty identical to them perhaps
since they all predate Ghostty).

I couldn't find any history where users requested the behavior of
defaulting this to something else for US based keyboards. That's
interesting since this has come up so frequently during the Ghostty
beta!
2024-12-11 10:27:08 -08:00
Mitchell Hashimoto
43a7dece02 config: title can reload at runtime
Related to #2898
2024-12-08 11:22:15 -08:00
Valentin Shinkarev
e7bfc17318 fix slow scroll in mouseReport 2024-12-01 22:58:46 +03:00
Mitchell Hashimoto
dca3cd7c10 Merge pull request #2788 from ghostty-org/push-rxpmmzxptqwt
surface needs to preserve original config working-directory
2024-11-23 10:05:16 -08:00
Mitchell Hashimoto
2b30186259 surface needs to preserve original config working-directory
Fixes #2785
2024-11-23 09:54:19 -08:00
Mitchell Hashimoto
6658aae21f Merge pull request #2771 from ghostty-org/push-quwzwysosskr
mode 2031 should send updates on any color palette change
2024-11-23 09:53:53 -08:00
Mitchell Hashimoto
cd49015243 App applies conditional state, supports theme setting
The prior light/dark mode awareness work works on surface-level APIs. As
a result, configurations used at the app-level (such as split divider
colors, inactive split opacity, etc.) are not aware of the current theme
configurations and default to the "light" theme.

This commit adds APIs to specify app-level color scheme changes. This
changes the configuration for the app and sets the default conditional
state to use that new theme. This latter point makes it so that future
surfaces use the correct theme on load rather than requiring some apprt
event loop ticks. Some users have already reported a short "flicker" to
load the correct theme, so this should help alleviate that.
2024-11-22 14:08:35 -08:00
Mitchell Hashimoto
1c6adf4065 mode 2031 should send updates on any color palette change
Related #2755

From the mode 2031 spec[1]:

> Send CSI ? 2031 h to the terminal to enable unsolicited DSR (device status
> report) messages for color palette updates and CSI ? 2031 l respectively to
> disable it again.
>
> The sent out DSR looks equivalent to the already above mentioned. This
> notification is not just sent when dark/light mode has been changed by the
> operating system / desktop, but also if the user explicitly changed color
> scheme, e.g. by configuration.

My reading of this paired with the original discussion is that this is
meant to be sent out for anything that could possibly change terminal
colors.

Previous to this commit, we only sent out the DSR when the actual system
light/dark mode changed. This commit changes it to send out the DSR on
any operation that _may_ change the terminal colors.

[1]: https://contour-terminal.org/vt-extensions/color-palette-update-notifications/#example-source-code
2024-11-22 13:14:12 -08:00
Mitchell Hashimoto
a191f3c396 apprt: switch to reload_config action that calls update_config API 2024-11-22 11:52:34 -08:00
Mitchell Hashimoto
fadfb08efe apprt: add config_change action 2024-11-21 10:30:27 -08:00
Mitchell Hashimoto
b7f1eaa145 apprt: action to change conditional state, implement for embedded 2024-11-19 15:36:31 -08:00
Mitchell Hashimoto
7605472922 Balance padding uses the explicit padding value for grid calculations
This fixes window resize not working properly when
`window-padding-balance` is set to true.
2024-11-15 15:16:00 -08:00
Mitchell Hashimoto
bdf3d1cb5f apprt/embedded: fix new size struct 2024-11-14 13:58:15 -08:00
Mitchell Hashimoto
b3b5e15e96 renderer/metal: use new size struct 2024-11-14 13:44:05 -08:00
Mitchell Hashimoto
90c59f2462 termio: change all sizes to the new size type 2024-11-14 13:31:10 -08:00
Mitchell Hashimoto
dcb1ce8377 termio: change resize message to use new size struct 2024-11-14 13:23:24 -08:00
Mitchell Hashimoto
ca8130bec9 core: make surface use only renderer.Size 2024-11-14 13:15:56 -08:00
Mitchell Hashimoto
3ca246ceb9 apprt: support a pwd change action 2024-11-13 12:29:30 -08:00
Mitchell Hashimoto
aed51fd0b0 terminal: PageList rename "page" to "node" everywhere
This is more correct: a pagelist is a linked list of nodes, not pages.
The nodes themselves contain pages but we were previously calling the
nodes "pages" which was confusing, especially as I plan some future
changes to the way pages are stored.
2024-11-07 13:44:39 -08:00
Mitchell Hashimoto
65f1cefb4e config: add "initial-command" config, "-e" sets that
Fixes #2601

It is more expected behavior that `-e` affects only the first window. By
introducing a dedicated configuration we avoid making `-e` too magical:
its simply syntax sugar for setting the "initial-command" configuration.
2024-11-05 16:58:20 -08:00
Mitchell Hashimoto
b56cb7038a core: only do cursor click to move without a mouse selection 2024-10-31 09:34:46 -07:00
Mitchell Hashimoto
c97c0858be macos: rectangle select only requires option + drag
Fixes #2537

This matches Terminal.app. iTerm2 requires cmd+option (our old
behavior). Kitty doesn't seem to support rectangle select or I couldn't
figure out how to make it work. WezTerm matches Terminal.app too.
Outside of terminal emulators, this is also the rectangular select
binding for neovim.
2024-10-30 20:47:24 -04:00
Mitchell Hashimoto
569d887de8 core: show mouse whenever focus state changes on surface
Related to #2525
2024-10-30 18:03:16 -04:00
Mitchell Hashimoto
1065359b9a apprt: rename set_bg/fg to "color_change" to report all color changes 2024-10-30 16:33:18 -04:00
CJ van den Berg
a2a1d93d5c apprt: propagate OSC10/11 (set term fore/background color) through to apprt
This is to allow the running apprt to set the UI theme to match the
terminal application coloring.
2024-10-30 17:35:34 +01:00
Jeffrey C. Ollie
348287c620 core: add a .txt extenstion to scrollback file
This should make it easier for open or xdg-open to find an appropriate
application to open the scrollback file with.
2024-10-27 16:03:18 -05:00
Mitchell Hashimoto
de5ec5d83e macos: make move_tab work 2024-10-25 11:54:07 -07:00
axdank
520dda65cb apply review changes 2024-10-25 08:07:11 -03:00
axdank
465d60def8 gui: add move_current_tab action 2024-10-24 00:01:54 -03:00
Tim Culverhouse
4f1cee8eb9 fix: report correct screen pixel size
Mode 2048 and CSI 14 t are size report control sequences which contain
the text area size in pixels. The text area is defined to be the extents
of the grid (rows and columns). Ghostty calculates the available size
for the text area by setting the available padding, and then filling as
much of the remaining space as possible. However, if there are remainder
pixels these are still reported as part of the text area size.

Pass the cell_size geometry through so that we can always report the
correct value: columns * cell width and rows * cell height.
2024-10-18 22:29:52 -05:00
Mitchell Hashimoto
3f1d6eb301 expand explicit error set usage
This continues our work to improve the amount of explicit error sets
we use in the codebase. Explicit error sets make it easier to understand
possible failure scenarios, allow us to use exhaustive matching, create
compiler errors if errors are unexpectedly added or removed, etc.

The goal eventually is 100% coverage but we're not even close yet.
This just moves us a little closer.
2024-10-18 08:10:41 -07:00
Qwerasd
de16541bca macOS: fix quicklook position
Account for padding and properly calculate text baseline, since that is
the position that the NSView `showDefinition` method ultimately needs.
2024-10-15 15:40:15 -04:00
Mitchell Hashimoto
745079cbb5 core: simplify scroll math, fix horizontal scroll direction on macOS
This simplifies the math for calculating scroll vectors based on mouse
scroll events. This was done to fix inverted horizontal scrolling on
macOS with natural scrolling enabled. Many assertions were added for
assumptions and our preconditions are clearly documented.

The preconditions are:

  * Apprt scroll offsets are negative down/left, positive up/right
  * Terminal vertical scroll is postive down, negative up (opposite
    since scroll for a terminal means how many rows to move down).
  * `Surface.scrollCallback` is always call with an apprt offset.
  * Apprt is responsible for implementing natural scrolling. Surface
    always assumes negative is down/left.
2024-10-10 16:24:16 -07:00
Mitchell Hashimoto
e90dec04be core: support mouse button 6/7 for mouse reports
Fixes #2423

This corresponds to horizontal scroll on macOS and likely other mice.
2024-10-09 11:24:36 -07:00
Mitchell Hashimoto
4ffb1c8cf9 core: modifier-only keys do not reset pending key sequences
This allows nested key sequences to be used such as `ctrl+a>ctrl+b>c`.
2024-10-09 09:46:16 -07:00
Mitchell Hashimoto
5c1ffbb642 apprt: implement key_sequence action 2024-10-08 21:55:00 -07:00
Mitchell Hashimoto
8d7367fa64 input: return a K/V entry for the binding set get 2024-10-08 06:29:54 -10:00
Leah Amelia Chen
fbc621a7d8 gtk: implement splitting leftwards and upwards 2024-10-07 18:19:27 -07:00
Mitchell Hashimoto
65c907ddab core: negative x/y for cursor position indicates mouse exited viewport 2024-10-06 15:20:17 -10:00
Mitchell Hashimoto
520c21d665 core: refresh hyperlink state without hacky cursorPosCallback
This fixes a longstanding piece of tech debt which caused all sorts of
bugs. Instead of trying to jam cursorPosCallback into a modsChanged
event we bring out the link refreshing into a dedicated method that is
shared.
2024-10-05 15:31:36 -10:00
theprimeagen
f0591b4afb fix: scrolling with fraction produces different lines count due to @floor vs @trunc (-1 vs 1) 2024-10-03 11:19:41 -06:00
Mitchell Hashimoto
1d09cdb382 Mouse movement events are sent with shift until a button is pressed
Ghostty was previously treating shift as a way to always stop mouse
reporting. That's true for mouse button events, but not for mouse
movement events. For mouse movement events, shift should be treated as
a modifier until a button (any mouse button) is pressed. Once it is
pressed, we pause mouse reporting until all buttons are released.

Found by @ldemailly. This matches the behavior of Kitty, Alacritty,
WezTerm, and xterm.
2024-10-02 17:08:37 -07:00
Mitchell Hashimoto
be3ae56bc8 font: add stylistic variants for built-in font, fix naming convention
Fixes #2364

This adds the bold, italic, and bold italic variants of JB Mono so it is
built-in. This also fixes up the naming convention for the embedded font
files across tests and removes redundant embedded font files.
2024-10-02 15:17:18 -07:00
Mitchell Hashimoto
66f2d75ddd Change copy-on-select behavior to be more idiomatic for Linux
Fixes #2345

The new docs for `copy-on-select`:

Whether to automatically copy selected text to the clipboard. `true`
will prefer to copy to the selection clipboard if supported by the
OS, otherwise it will copy to the system clipboard.

The value `clipboard` will always copy text to the system clipboard
(for supported systems) as well as the system clipboard. This is sometimes
a preferred behavior on Linux.

Middle-click paste will always use the selection clipboard on Linux
and the system clipboard on macOS. Middle-click paste is always enabled
even if this is `false`.

The default value is true on Linux and false on macOS. macOS copy on
select behavior is not typical for applications so it is disabled by
default. On Linux, this is a standard behavior so it is enabled by
default.
2024-10-01 20:38:27 -07:00
Mitchell Hashimoto
6d68db3bdc core: only extend selection on mouse if click interval is exceeded
Previously, once we had one click registered, shift+click would always
go into selection extend mode. This is not the behavior we want, since
we want shift+double/triple click to work in alternate screens.

This commit changes the behavior so that we only extend the selection
after the multi-click interval has passed.

I see a lot of opportunity to improve this whole callback much more but
I don't want to risk introducing new bugs since this is a hard to test
area, so I'm going to leave it for now.
2024-09-27 14:21:27 -07:00
Mitchell Hashimoto
f6f91b5eb5 core: fix invalid action call that wasn't setting our metrics properly
Fixes #2308
2024-09-27 12:28:15 -07:00
Paul Berg
f1474c220d bind: add toggle_tab_overview binding 2024-09-27 10:13:05 -07:00
Mitchell Hashimoto
4ae20212bf libghostty: unified action dispatch
First, this commit modifies libghostty to use a single unified action
dispatch system based on a tagged union versus the one-off callback
system that was previously in place. This change simplifies the code on
both the core and consumer sides of the library. Importantly, as we
introduce new actions, we can now maintain ABI compatibility so long as
our union size does not change (something I don't promise yet).

Second, this moves a lot more of the functions call on a surface into
the action system. This affects all apprts and continues the previous
work of introducing a more unified API for optional surface features.
2024-09-26 22:00:11 -07:00
Mitchell Hashimoto
4cc4eb5ed0 core: remove more hasdecls 2024-09-26 14:21:06 -07:00
Mitchell Hashimoto
e29918ebb8 core: more actions 2024-09-26 10:20:44 -07:00