5828 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
Khang Nguyen Duy
cb67fbd08d gtk: pass surface to clipboard window by reference instead of by value
The surface might be mutated during the clipboard confirmation
(resized in my case), leading to the copied cursor page_pin being
invalidated.
2024-12-12 00:21:59 +07: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
Mitchell Hashimoto
3f21921568 Add zsh completions and improve fish completions (#2925)
Adds zsh completion generation and improves fish completion generation
to cover all actions with arguments.

<details>
  <summary>Generated _ghostty contents</summary>
  
  ```zsh
#compdef ghostty

_fonts () {
  local font_list=$(ghostty +list-fonts | grep -Z '^[A-Z]')
  local fonts=(${(f)font_list})
  _describe -t fonts 'fonts' fonts
}

_themes() {
  local theme_list=$(ghostty +list-themes | sed -E 's/^(.*) \(.*\$/\0/')
  local themes=(${(f)theme_list})
  _describe -t themes 'themes' themes
}
_config() {
  _arguments \
    "--help" \
    "--version" \
    "--font-family=-:::_fonts" \
    "--font-family-bold=-:::_fonts" \
    "--font-family-italic=-:::_fonts" \
    "--font-family-bold-italic=-:::_fonts" \
    "--font-style=-:::( )" \
    "--font-style-bold=-:::( )" \
    "--font-style-italic=-:::( )" \
    "--font-style-bold-italic=-:::( )" \
"--font-synthetic-style=-:::(bold no-bold italic no-italic bold-italic
no-bold-italic)" \
    "--font-feature=-:::( )" \
    "--font-size=-:::( )" \
    "--font-variation=-:::( )" \
    "--font-variation-bold=-:::( )" \
    "--font-variation-italic=-:::( )" \
    "--font-variation-bold-italic=-:::( )" \
    "--font-codepoint-map=-:::( )" \
    "--font-thicken=-:::(true false)" \
    "--adjust-cell-width=-:::( )" \
    "--adjust-cell-height=-:::( )" \
    "--adjust-font-baseline=-:::( )" \
    "--adjust-underline-position=-:::( )" \
    "--adjust-underline-thickness=-:::( )" \
    "--adjust-strikethrough-position=-:::( )" \
    "--adjust-strikethrough-thickness=-:::( )" \
    "--adjust-cursor-thickness=-:::( )" \
    "--grapheme-width-method=-:::(legacy unicode)" \
"--freetype-load-flags=-:::(hinting no-hinting force-autohint
no-force-autohint monochrome no-monochrome autohint no-autohint)" \
    "--theme=-:::_themes" \
    "--background=-:::( )" \
    "--foreground=-:::( )" \
    "--selection-foreground=-:::( )" \
    "--selection-background=-:::( )" \
    "--selection-invert-fg-bg=-:::(true false)" \
    "--minimum-contrast=-:::( )" \
    "--palette=-:::( )" \
    "--cursor-color=-:::( )" \
    "--cursor-invert-fg-bg=-:::(true false)" \
    "--cursor-opacity=-:::( )" \
    "--cursor-style=-:::(bar block underline block_hollow)" \
    "--cursor-style-blink=-:::( )" \
    "--cursor-text=-:::( )" \
    "--cursor-click-to-move=-:::(true false)" \
    "--mouse-hide-while-typing=-:::(true false)" \
    "--mouse-shift-capture=-:::(false true always never)" \
    "--mouse-scroll-multiplier=-:::( )" \
    "--background-opacity=-:::( )" \
    "--background-blur-radius=-:::( )" \
    "--unfocused-split-opacity=-:::( )" \
    "--unfocused-split-fill=-:::( )" \
    "--command=-:::( )" \
    "--initial-command=-:::( )" \
    "--wait-after-command=-:::(true false)" \
    "--abnormal-command-exit-runtime=-:::( )" \
    "--scrollback-limit=-:::( )" \
    "--link=-:::( )" \
    "--link-url=-:::(true false)" \
    "--fullscreen=-:::(true false)" \
    "--title=-:::( )" \
    "--class=-:::( )" \
    "--x11-instance-name=-:::( )" \
    "--working-directory=-:::{_files -/}" \
    "--keybind=-:::( )" \
    "--window-padding-x=-:::( )" \
    "--window-padding-y=-:::( )" \
    "--window-padding-balance=-:::(true false)" \
    "--window-padding-color=-:::(background extend extend-always)" \
    "--window-vsync=-:::(true false)" \
    "--window-inherit-working-directory=-:::(true false)" \
    "--window-inherit-font-size=-:::(true false)" \
    "--window-decoration=-:::(true false)" \
    "--window-title-font-family=-:::( )" \
    "--window-theme=-:::(auto system light dark ghostty)" \
    "--window-colorspace=-:::(srgb display-p3)" \
    "--window-height=-:::( )" \
    "--window-width=-:::( )" \
    "--window-save-state=-:::(default never always)" \
    "--window-step-resize=-:::(true false)" \
    "--window-new-tab-position=-:::(current end)" \
    "--resize-overlay=-:::(always never after-first)" \
"--resize-overlay-position=-:::(center top-left top-center top-right
bottom-left bottom-center bottom-right)" \
    "--resize-overlay-duration=-:::( )" \
    "--focus-follows-mouse=-:::(true false)" \
    "--clipboard-read=-:::(allow deny ask)" \
    "--clipboard-write=-:::(allow deny ask)" \
    "--clipboard-trim-trailing-spaces=-:::(true false)" \
    "--clipboard-paste-protection=-:::(true false)" \
    "--clipboard-paste-bracketed-safe=-:::(true false)" \
    "--image-storage-limit=-:::( )" \
    "--copy-on-select=-:::(false true clipboard)" \
    "--click-repeat-interval=-:::( )" \
    "--config-file=-:::_files" \
    "--config-default-files=-:::(true false)" \
    "--confirm-close-surface=-:::(true false)" \
    "--quit-after-last-window-closed=-:::(true false)" \
    "--quit-after-last-window-closed-delay=-:::( )" \
    "--initial-window=-:::(true false)" \
    "--quick-terminal-position=-:::(top bottom left right)" \
    "--quick-terminal-screen=-:::(main mouse macos-menu-bar)" \
    "--quick-terminal-animation-duration=-:::( )" \
    "--shell-integration=-:::(none detect bash elvish fish zsh)" \
"--shell-integration-features=-:::(cursor no-cursor sudo no-sudo title
no-title)" \
    "--osc-color-report-format=-:::(none 8-bit 16-bit)" \
    "--vt-kam-allowed=-:::(true false)" \
    "--custom-shader=-:::_files" \
    "--custom-shader-animation=-:::(false true always)" \
    "--macos-non-native-fullscreen=-:::(false true visible-menu)" \
    "--macos-titlebar-style=-:::(native transparent tabs hidden)" \
    "--macos-titlebar-proxy-icon=-:::(visible hidden)" \
    "--macos-option-as-alt=-:::(false true left right)" \
    "--macos-window-shadow=-:::(true false)" \
    "--macos-auto-secure-input=-:::(true false)" \
    "--macos-secure-input-indication=-:::(true false)" \
    "--linux-cgroup=-:::(never always single-instance)" \
    "--linux-cgroup-memory-limit=-:::( )" \
    "--linux-cgroup-processes-limit=-:::( )" \
    "--linux-cgroup-hard-fail=-:::(true false)" \
    "--gtk-single-instance=-:::(desktop false true)" \
    "--gtk-titlebar=-:::(true false)" \
    "--gtk-tabs-location=-:::(top bottom left right)" \
    "--adw-toolbar-style=-:::(flat raised raised-border)" \
    "--gtk-wide-tabs=-:::(true false)" \
    "--gtk-adwaita=-:::(true false)" \
    "--desktop-notifications=-:::(true false)" \
    "--bold-is-bright=-:::(true false)" \
    "--term=-:::( )" \
    "--enquiry-response=-:::( )" \
    "--auto-update=-:::(off check download)" \

}

_ghostty() {
  typeset -A opt_args
  local context state line
  local opt=('--help' '--version')

  _arguments -C \
    '1:actions:->actions' \
    '*:: :->rest' \

  if [[ "$line[1]" == "--help" || "$line[1]" == "--version" ]]; then
    return
  fi

  if [[ "$line[1]" == -* ]]; then
    _config
    return
  fi

  case "$state" in
    (actions)
      local actions; actions=(
        '+version'
        '+help'
        '+list-fonts'
        '+list-keybinds'
        '+list-themes'
        '+list-colors'
        '+list-actions'
        '+show-config'
        '+validate-config'
        '+crash-report'
      )
      _describe '' opt
      _describe -t action 'action' actions
    ;;
    (rest)
      if [[ "$line[2]" == "--help" ]]; then
        return
      fi

      local help=('--help')
      _describe '' help

      case $line[1] in
        (+list-fonts)
          _arguments \
            '--family=-:::( )' \
            '--style=-:::( )' \
            '--bold=-:::(true false)' \
            '--italic=-:::(true false)' \
        ;;
        (+list-keybinds)
          _arguments \
            '--default=-:::(true false)' \
            '--docs=-:::(true false)' \
            '--plain=-:::(true false)' \
        ;;
        (+list-themes)
          _arguments \
            '--path=-:::(true false)' \
            '--plain=-:::(true false)' \
        ;;
        (+list-actions)
          _arguments \
            '--docs=-:::(true false)' \
        ;;
        (+show-config)
          _arguments \
            '--default=-:::(true false)' \
            '--changes-only=-:::(true false)' \
            '--docs=-:::(true false)' \
        ;;
        (+validate-config)
          _arguments \
            '--config-file=-:::_files' \
        ;;
      esac
    ;;
  esac
}

_ghostty "$@"

  ```
</details>

I agree to relicense my commits to MIT
2024-12-11 08:57:59 -08:00
Anund
54bd012443 fish: reuse Action options iteration code 2024-12-11 21:11:44 +11:00
Anund
c7deea6a7f zsh: add completions generation 2024-12-11 21:11:38 +11:00
Khang Nguyen Duy
cb5848c7b7 command: fix hostname test compatibility
hostname is not guaranteed on *nix as in the comment.
For example, Arch does not have hostname by default.
2024-12-11 16:54:28 +07: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
Qwerasd
7e5a164be8 font/opentype: add table parsing for head, hhea, post, and OS/2
(and a utility for parsing SFNT font files and fetching table data from
them)
2024-12-10 16:35:51 -05:00
Qwerasd
2f31e1b7fa fix(kittygfx): don't respond to T commands with no i or I
If a transmit and display command does not specify an ID or a number,
then it should not be responded to. We currently automatically assign
IDs in this situation, which isn't ideal since collisions can happen
which shouldn't, but this at least fixes the glaring observable issue
where transmit-and-display commands yield unexpected OK responses.
2024-12-10 14:30:59 -05:00
deftdawg
9252378c82 Merge branch 'ghostty-org:main' into alt-keybindings-copy-and-paste 2024-12-09 23:04:31 -05:00
Mitchell Hashimoto
cac776a994 config: "-e" arguments must stay at the end of replay steps
Fixes #2908

When loading `config-file`, we need to ensure that all loaded
configuration is loaded _prior_ to any `-e` values from the CLI.

To do this, I inserted a new `-e` special tag type in our replay steps.
This can be used to find when `-e` starts and ensure it remains at the
end of replay steps when the replay steps are being modified.

This commit also found a similar (but not exercised) issue where this
could happen with light/dark themeing.
2024-12-09 14:18:09 -08:00
Mitchell Hashimoto
247409d705 New Ghostty icon
❤️👻

This is the icon that we'll launch Ghostty 1.0 with. It was designed by
Michael Flareup at PixelResort. It retains the style of the original
Ghostty icon by Alasdair Monk, but brings in the new Ghost character and
adds details that make it more Apple-like.

The new Ghost character is an important evolution from the original
since it separates us from looking too much like PacMan. The new Ghost
is more unique and recognizable to Ghostty (or, hopefully will be!).

The icon itself has more details: the aluminum around the edge has
texture for the large enough sizes, there are visible scanlines, the
glow of a screen emanates from the ghost.

The icon itself is stylistic more Apple-like than other platforms. I
think Apple icons tend to look very good in more environments than the
reverse and I'm a big fan of the Apple aesthetic so I wanted to bring
that to Ghostty for all platforms.
2024-12-09 10:01:18 -08:00
Mitchell Hashimoto
ae2cf8dc37 doc: remove outdated statement for fullscreen option (#2904)
We can use `macos-non-native-fullscreen` with `fullscreen` together
since #1377 was closed.
2024-12-08 16:35:42 -08:00
Mitchell Hashimoto
43a7dece02 config: title can reload at runtime
Related to #2898
2024-12-08 11:22:15 -08:00
moni
250bd35830 termio: clear kitty images when deleting above the cursor 2024-12-08 10:27:15 -08:00
Dmitry Zhlobo
aa4e704d95 doc: remove outdated statement for fullscreen option
We can use `macos-non-native-fullscreen` with `fullscreen` together
since #1377 was closed.
2024-12-08 17:20:25 +01:00
Mitchell Hashimoto
2fb92dd4aa flake: update to Nix 24.11 (#2894)
This is probably going to cause some issues, this is the soonest we've
ever tried this. CI seems quite happy about the change though so moving
forward quickly is good with me.
2024-12-05 14:08:14 -08:00
Mitchell Hashimoto
1ee7da174b flake: update to Nix 24.11 2024-12-05 12:15:48 -08:00
Mitchell Hashimoto
bb185cf6b6 apprt/gtk: force X11 backend on GTK 4.14
I'm unsure if this is an environmental issue just for me or if this is
more widespread or what other downsides this may have. I'm more than
willing to revert this if it ends up causing different issues.

I found that with NixOS 24.11 and GTK 4.14 on my system, the default
Wayland GDK backend fails to initialize EGL. With GTK 4.16 everything
is fine.

If I force X11 then everything also works fine. This commit forces X11
for GTK 4.14 specifically (4.16+ is allowed to use Wayland).
2024-12-05 11:26:46 -08:00
Mitchell Hashimoto
50b36c5d86 comments 2024-12-04 12:38:40 -08:00
Mitchell Hashimoto
b9dda6ad87 terminal: PageListSearch works! 2024-12-04 12:30:14 -08:00
Mitchell Hashimoto
6361bf47f7 terminal: update comments/docs on sliding window search 2024-12-04 11:25:25 -08:00
Mitchell Hashimoto
34fb840cf9 terminal: search match on overlap case 2024-12-04 11:16:45 -08:00
Mitchell Hashimoto
852e04fa00 terminal: test for match in second slice of circ buf 2024-12-04 10:58:38 -08:00
Mitchell Hashimoto
af1ee4d95f terminal: search match across page boundary 2024-12-04 10:36:22 -08:00
Mitchell Hashimoto
79026a1148 terminal: test no match pruning 2024-12-03 15:55:18 -08:00
Mitchell Hashimoto
09e4cccd2c terminal: remove unused pagesearch 2024-12-03 15:53:13 -08:00
Mitchell Hashimoto
b487aa8e1f terminal: search across two pages and pruning appears to be working 2024-12-03 15:53:12 -08:00
Mitchell Hashimoto
d307b02e40 terminal: sliding window search can move the cursor 2024-12-03 15:53:12 -08:00
Mitchell Hashimoto
6ed298c9c1 terminal: sliding window search starts working 2024-12-03 15:53:12 -08:00
Mitchell Hashimoto
2a13c6b6a3 terminal: working on a pagelist sliding window for search 2024-12-03 15:53:12 -08:00
Mitchell Hashimoto
8abbd80e06 CircBuf: add ensureUnusedCapacity, appendSlice 2024-12-03 15:53:12 -08:00
Mitchell Hashimoto
eaddb69500 datastruct: CircBuf can be initialized empty 2024-12-03 15:53:12 -08:00
Mitchell Hashimoto
61c5fb8115 terminal: single pagelist node search 2024-12-03 15:53:12 -08:00
Mitchell Hashimoto
204e4f8663 terminal: support cell_map for encodeUtf8 2024-12-03 15:53:12 -08:00
Mitchell Hashimoto
bcefbfd7b4 terminal: move UTF8 encoding to Page and wrap around it 2024-12-03 15:53:12 -08:00
Mitchell Hashimoto
e712314f31 terminal: PageList.reset has to zero arena memory to avoid reuse
Fixes #2877

As the comment in the diff states, we rely on `mmap` to zero our memory.
When we reset we are reusing previously allocated memory so we won't hit
an `mmap`. We need to zero the memory ourselves.

This is pretty slow if there is a lot of memory but in every case except
allocation failures, we expect there to be only a few pages allocated.
2024-12-03 08:58:57 -05:00
Mitchell Hashimoto
212bd3d5fb terminal: fullReset uses the new screen reset methods 2024-12-02 17:44:07 -05:00
Mitchell Hashimoto
d7fcaefdf3 terminal: PageList.reset 2024-12-02 17:26:19 -05:00
Mitchell Hashimoto
d57d1d2395 terminal: failing tracked pin test on fullReset 2024-12-02 09:39:43 -05:00
DeftDawg
1e5b02302b - Add alt keybindings for ctrl+ins = Copy and shift+ins = Paste for non-MacOS systems 2024-12-02 02:47:42 -05:00
Valentin Shinkarev
e7bfc17318 fix slow scroll in mouseReport 2024-12-01 22:58:46 +03:00
Mitchell Hashimoto
853ba9e3c7 terminal: reset should preserve desired default mode values
Fixes #2857

Some terminal modes always reset, but there are others that should be
conditional based on how the terminal's default state is configured.
Primarily from #2857 is the grapheme clustering mode (mode 2027) which
was always resetting to false but should be conditional based on the
the `grapheme-width-method` configuration.
2024-11-29 14:42:01 -08:00
Mitchell Hashimoto
ffb5fff555 Merge pull request #2856 from ghostty-org/push-nmsumxnrsyrq
macos: unicode keybindings must convert to string properly
2024-11-29 14:31:19 -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
Mike Hartington
df4a6f2161 font/sprite: add missing chevron powerline fonts 2024-11-29 14:26:22 -05:00
Mitchell Hashimoto
423f58c24c Merge pull request #2843 from ghostty-org/push-lqkuvlyttoul
config: need to dupe filepath for diagnostics
2024-11-27 08:51:51 -08:00
Mitchell Hashimoto
5b01cb353d config: need to dupe filepath for diagnostics
Fixes #2800

The source string with the filepath is not guaranteed to exist beyond
the lifetime of the parse operation. We must copy it.
2024-11-27 08:46:47 -08:00
Mitchell Hashimoto
ba4185f6b7 macos: disable background opacity/blur in native fullscreen
See #2840
2024-11-27 08:35:13 -08:00