313 Commits

Author SHA1 Message Date
Bruno Bachmann
bb58710fa8 Fix typo in binding comments 2025-01-19 14:49:59 -08:00
Adam Wolf
8102fddceb apprt/gtk: add toggle_maximize keybind and window-maximize config option 2025-01-10 22:42:41 -06:00
Mitchell Hashimoto
200aee9acf macos: rework toggle_visibility to better match iTerm2
Two major changes:

1. Hiding uses `NSApp.hide` which hides all windows, preserves tabs, and
   yields focus to the next app.

2. Unhiding manually tracks and brings forward only the windows we hid.
   Proper focus should be retained.
2025-01-10 14:40:02 -08:00
Bryan Lee
5213edfa6c Add keybind action copy_url_to_clipboard 2025-01-08 13:22:33 -08:00
Bryan Lee
140ac93884 Add close_tab keybinding action for macOS
Implement `close_tab` keybinding action to close the current tab and all splits within that tab.
2025-01-08 12:04:40 -08:00
Sabarigirish Manikandan
306c7ea2be close_tab keybind (gtk apprt only) (#4033)
Title. Adds a close_tab keybind that essentially behaves the exact same
as clicking the tab close button on the tab bar.
2025-01-08 19:07:00 +00:00
Mitchell Hashimoto
359c390218 config: unbind keybind triggers unbinds both translated and physical
Fixes #4703

This changes `unbind` so it always removes all keybinds with the given
trigger pattern regardless of if it is translated or physical.

The previous behavior was technically correct, but this implements the pattern
of least surprise. I can't think of a scenario where you really want to
be exact about what key you're unbinding. And if that scenario does
exist, you can always fix it by rebinding after unbind.
2025-01-06 09:47:21 -08:00
Mitchell Hashimoto
305e5b3533 fix typo: CSI header (#4565)
Fixes a typo in the keybindings documentation comments.
Originally opened on the website repo at
https://github.com/ghostty-org/website/pull/259
2025-01-04 14:27:23 -08:00
Kiril Angov
2dc518d8b0 Improve the documentation for move_tab keybind action 2025-01-04 12:57:38 -05:00
dkmar
69e4428d80 fix typo: CSI header 2025-01-03 23:34:39 -08:00
Caleb Norton
2610f5b4e2 Docs: update goto_split documentation
In #4388, documentation was added for goto_split but in #3427 this
documentation was made outdated but not updated. This makes the
documentation up to date and brings the ordering in line with new_split
2025-01-03 14:32:39 -06:00
Mitchell Hashimoto
ab9b14215c input: legacy encoding falls back to mapping of logical key for ctrlseq (#4528)
Fixes #4518

If our UTF8 encoding is not recognized, we fall back to the ASCII
mapping of the logical key for the control sequence. This allows
cyrillic control characters to work.

I also verified that non-cyrllic (US) and alternate layouts (Dvorak)
work as expected still.
2025-01-03 11:09:09 -08:00
Peter Cock
6459e5c8ca Fixing a few typos in the source code comments (#4529) 2025-01-03 11:00:45 -08:00
Mitchell Hashimoto
45d005ce65 input: legacy encoding falls back to mapping of logical key for ctrlseq
Fixes #4518

If our UTF8 encoding is not recognized, we fall back to the ASCII
mapping of the logical key for the control sequence. This allows
cyrillic control characters to work.

I also verified that non-cyrllic (US) and alternate layouts (Dvorak)
work as expected still.
2025-01-03 10:53:54 -08:00
Mitchell Hashimoto
e2f9eb6a6f keybindings: improve sort to include key value 1,2,3,4... (#4399)
Current sort used by `+list-keybinds` doesn't include the value of the
key:
```
ctrl  + shift + v                      paste_from_clipboard
ctrl  + shift + a                      select_all
...
ctrl  + shift + q                      quit
ctrl  + shift + n                      new_window
...
alt   + five                           goto_tab:5
alt   + eight                          goto_tab:8
...
alt   + six                            goto_tab:6
alt   + seven                          goto_tab:7
```
adding the key value improves the sort order

```
ctrl  + shift + a                      select_all
ctrl  + shift + c                      copy_to_clipboard
...
ctrl  + shift + n                      new_window
ctrl  + shift + o                      new_split:right
ctrl  + shift + q                      quit
...
alt   + one                            goto_tab:1
alt   + two                            goto_tab:2
alt   + three                          goto_tab:3
...
alt   + eight                          goto_tab:8
alt   + nine                           last_tab
alt   + f4                             close_window
2025-01-02 19:43:19 -08:00
Mitchell Hashimoto
7e1b7bb8b3 performable: prefix (#4345)
closes #4328
closes #3970

makes this possible now
```
keybind = performable:ctrl+c=copy_to_clipboard # copy if theres a selection else send sigint
keybind = ctrl+v=paste_from_clipboard
```
2025-01-02 16:11:24 -08:00
Mitchell Hashimoto
95b73f197f Add docs for performable 2025-01-02 15:41:01 -08:00
Mitchell Hashimoto
9503c9fe50 Rename goto_split top/bottom directions to up/down. (#3427)
Renames the top/bottom directions of `goto_split` to up/down. I have
tested this on linux (nixos) but given that `goto_split` is broken on
linux anyway (#2866) there's not a whole lot to test.

I have no way to build on macOS so I can't verify that I've changed
everything correctly for that.

Closes #3237
2025-01-02 07:08:16 -08:00
Mitchell Hashimoto
75571fb804 Improve resize_split documentation (#4393) 2025-01-02 07:02:33 -08:00
Mitchell Hashimoto
4047c89c24 Improve new_split documentation (#4389) 2025-01-02 07:02:23 -08:00
Anund
913a1404be keybindings: improve sort to include key value 1,2,3,4... 2025-01-03 01:53:07 +11:00
Jade
355ac91c0a Improve resize_split documentation 2025-01-02 21:33:47 +08:00
Jade
cd809106c4 Improve new_split documentation 2025-01-02 21:05:56 +08:00
Jade
80fe32be32 Update Binding.zig 2025-01-02 20:58:50 +08:00
Jade
15ceb18fcb Improve goto_split documentation 2025-01-02 20:54:42 +08:00
Ethan Conneely
98aa046a4d Add performable flag 2025-01-02 00:18:39 +00:00
Mitchell Hashimoto
aa81c16ba1 input: parse triggers with codepoints that map to keys as translated
Fixes #4146

This makes it so that keys such as `cmd+1` and `cmd+one` are identical.
2024-12-30 21:06:43 -08:00
Daniel Patterson
3e11476d32 Add "top" and "bottom" aliases 2024-12-29 22:05:28 +00:00
Ronit Gandhi
38643ec4fe docs: add guide for setting quick terminal toggle keybind 2024-12-28 12:57:17 -08:00
xaviduds
96753aa7e0 Update doc inform toggle_quick_terminal macOS only 2024-12-27 11:52:20 -08:00
Daniel Patterson
a4daabb28a Rename goto_split top/bottom directions to up/down. 2024-12-27 14:56:48 +00:00
Lucas Crownover
6217dbebcf Update help comment for backslash 2024-12-26 14:58:43 -08:00
Mitchell Hashimoto
0f588d72c7 Change to F3 legacy encoding with modifiers (#3019)
The [fixterms](http://www.leonerd.org.uk/hacks/fixterms/) "Really
Special Keypresses" section suggests using CSI 1 ; Ps R for F3, but this
is also a valid cursor position report. The intention was to make
back-compatible changes, so this is fairly considered a specification
bug.

This changes F3 in legacy mode to send CSI 13 ; Ps ~ instead, this is a
variant listed in fixterms, is what kitty protocol uses, and lacks the
problematic overlap with cursor positions.

The KeyEncoder.zig unit test has been changed accordingly, and all tests
pass on my machine.
2024-12-20 08:25:30 -08:00
Sam Atman
8cadc7030c Change to F3 legacy encoding with modifiers
The [fixterms](http://www.leonerd.org.uk/hacks/fixterms/) "Really
Special Keypresses" section suggests using CSI 1 ; Ps R for F3, but this
is also a valid cursor position report.  The intention was to make back-
compatible changes, so this is fairly considered a specification bug.

This changes F3 in legacy mode to send CSI 13 ; Ps ~ instead, this is a
variant listed in fixterms, is what kitty protocol uses, and lacks the
problematic overlap with cursor positions.

The KeyEncoder.zig unit test has been changed accordingly, and all tests
pass on my machine.
2024-12-19 17:05:29 -05:00
Sam Atman
d885a266d4 Docfix: correct comment for modifyOtherKeys sequence
The comment in `function_keys.zig` was missing the `>` character for the
sequence.  I've confirmed that this was just the comment, Ghostty treats
the original as an SGR sequence, which it is.  Conversely, it does treat
`\x1b[>4:2m` as activating modifyOtherKeys.
2024-12-19 16:51:28 -05:00
Mitchell Hashimoto
0ee90bb248 keybind: format leader bindings into multiple entries (#2923)
**Context**

Currently, if there are multiple keybindings with a shared prefix,
they are grouped into a nested series of Binding.Sets.
For example, as reported in #2734, the following bindings:

    keybind = ctrl+z>1=goto_tab:1
    keybind = ctrl+z>2=goto_tab:2
    keybind = ctrl+z>3=goto_tab:3

Result in roughly the following structure (in pseudo-code):

    Keybinds{
        Trigger("ctrl+z"): Value.leader{
            Trigger("1"): Value.leaf{action: "goto_tab:1"},
            Trigger("2"): Value.leaf{action: "goto_tab:2"},
            Trigger("3"): Value.leaf{action: "goto_tab:3"},
        }
    }

When this is formatted into a string (and therefore in +list-keybinds),
it is turned into the following as Value.format just concatenates
all the sibling bindings ('1', '2', '3') into consecutive bindings,
and this is then fed into a single configuration entry:

    keybind = ctrl+z>1=goto_tab:1>3=goto_tab:3>2=goto_tab:2

**Fix**

To fix this, Value needs to produce a separate configuration entry
for each sibling binding in the Value.leader case.
So we can't produce the entry (formatter.formatEntry) in Keybinds
and need to pass information down the Value tree to the leaf nodes,
each of which will produce a separate entry with that function.

This is accomplished with the help of a new Value.formatEntries method
that recursively builds up the prefix for the keybinding,
finally flushing it to the formatter when it reaches a leaf node.

This is done without extra allocations by using a FixedBufferStream
with the same buffer as before, sharing it between calls to nested
siblings of the same prefix.

**Testing**

Besides the included unit tests, I ran the GLFW-based app
and verified that the resulting binary produced the correct output
with `ghostty +show-config`:

```
❯ .zig-cache//o/02a32e7ba516d2692577a46f1a0df682/ghostty +show-config 2>/dev/null | grep goto_tab
keybind = ctrl+z>1=goto_tab:1
keybind = ctrl+z>3=goto_tab:3
keybind = ctrl+z>2=goto_tab:2
```

**Caveats**

We do not track the order in which the bindings were added
so the order is not retained in the formatConfig output.

Resolves #2734
2024-12-11 10:51:21 -08:00
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
Abhinav Gupta
495e4081e4 fix: NoSpaceLeft => OutOfMemory
NoSpaceLeft is not permitted to be returned in this context,
so turn it into OutOfMemory when we fail to write to the buffer.
2024-12-11 09:21:31 -08:00
Abhinav Gupta
e2e12efbbf keybind: format leader bindings into multiple entries
**Context**

Currently, if there are multiple keybindings with a shared prefix,
they are grouped into a nested series of Binding.Sets.
For example, as reported in #2734, the following bindings:

    keybind = ctrl+z>1=goto_tab:1
    keybind = ctrl+z>2=goto_tab:2
    keybind = ctrl+z>3=goto_tab:3

Result in roughly the following structure (in pseudo-code):

    Keybinds{
        Trigger("ctrl+z"): Value.leader{
            Trigger("1"): Value.leaf{action: "goto_tab:1"}),
            Trigger("2"): Value.leaf{action: "goto_tab:2"}),
            Trigger("3"): Value.leaf{action: "goto_tab:3"}),
        }
    }

When this is formatted into a string (and therefore in +list-keybinds),
it is turned into the following as Value.format just concatenates
all the sibling bindings ('1', '2', '3') into consecutive bindings,
and this is then fed into a single configuration entry:

    keybind = ctrl+z>1=goto_tab:1>3=goto_tab:3>2=goto_tab:2

**Fix**

To fix this, Value needs to produce a separate configuration entry
for each sibling binding in the Value.leader case.
So we can't produce the entry (formatter.formatEntry) in Keybinds
and need to pass information down the Value tree to the leaf nodes,
each of which will produce a separate entry with that function.

This is accomplished with the help of a new Value.formatEntries method
that recursively builds up the prefix for the keybinding,
finally flushing it to the formatter when it reaches a leaf node.

This is done without extra allocations by using a FixedBufferStream
with the same buffer as before, sharing it between calls to nested
siblings of the same prefix.

**Caveats**

We do not track the order in which the bindings were added
so the order is not retained in the formatConfig output.

Resolves #2734
2024-12-10 21:23:26 -08:00
Mitchell Hashimoto
9ac929ef8e macos: unicode keybindings must convert to string properly
Fixes #2848

The proper way to convert a unicode scalar in Swift is to use the
`String` initializer that takes a `UnicodeScalar` as an argument. We
were converting a number to a string before, which is incorrect.
2024-11-29 14:21:46 -08:00
Mitchell Hashimoto
9171cb5c29 config: implement clone for RepeatableLink
Fixes #2819
2024-11-26 10:50:13 -08:00
Mitchell Hashimoto
e187a412fa input: Binding set clone must deep clone actions
Fixes a crash found in Discord.

Cloning the keybinding set previously shallow copied the actions, but
actions may contain pointers. These pointer values must be deep copied
to avoid dangling references when the underlying memory is freed.
2024-11-21 10:07:44 -08:00
Paul Berg
1e003b2e0f gtk: implement toggle_split_zoom 2024-11-06 09:59:10 +01:00
Mitchell Hashimoto
28751ae5b8 Merge pull request #2485 from axdank/move_current_Tab
gui: add move_current_tab action
2024-10-25 14:15:16 -07:00
Mitchell Hashimoto
4885ffd042 input: note that toggle_split_zoom is macOS only 2024-10-25 09:34:53 -07:00
axdank
520dda65cb apply review changes 2024-10-25 08:07:11 -03:00
Mitchell Hashimoto
a651dbf3bf macos: fix goto last tab 2024-10-24 19:58:13 -07:00
axdank
465d60def8 gui: add move_current_tab action 2024-10-24 00:01:54 -03:00
Mitchell Hashimoto
0cf12cd88b input: make clear the open keybinding uses xdg-open 2024-10-14 09:32:38 -07:00
Mitchell Hashimoto
8d7367fa64 input: return a K/V entry for the binding set get 2024-10-08 06:29:54 -10:00