Skip to content

Commit 4de70bf

Browse files
authored
Merge pull request #3159 from carapace-sh/ghostty-flags
ghostty: fix flags (incomplete)
2 parents 7d4ff3b + eac16d8 commit 4de70bf

File tree

10 files changed

+178
-19
lines changed

10 files changed

+178
-19
lines changed

cmd/carapace/cmd/macros_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ func TestMacros(t *testing.T) {
1313
Expect(carapace.ActionStyledValues(
1414
"Green", "color2",
1515
"Grey", "color8",
16-
).Usage("--macro [macro] [...args]"))
16+
).Tag("xterm colors").
17+
Usage("--macro [macro] [...args]"))
1718
})
1819
}

completers/common/ghostty_completer/cmd/root.go

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/carapace-sh/carapace-bridge/pkg/actions/bridge"
88
"github.com/carapace-sh/carapace/pkg/style"
99
"github.com/spf13/cobra"
10+
"github.com/spf13/pflag"
1011
)
1112

1213
var rootCmd = &cobra.Command{
@@ -21,51 +22,70 @@ func Execute() error {
2122
}
2223
func init() {
2324
carapace.Gen(rootCmd).Standalone()
25+
rootCmd.Flags().SetInterspersed(false)
2426

25-
rootCmd.Flags().StringS("e", "e", "", "run command")
27+
rootCmd.Flags().BoolS("e", "e", false, "run command") // if set positional arguments accept a command
2628
rootCmd.Flags().Bool("help", false, "show help")
2729
rootCmd.Flags().Bool("version", false, "show version")
2830
addConfigs(rootCmd)
2931

30-
carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
31-
"e": bridge.ActionCarapaceBin().Split(),
32-
})
32+
carapace.Gen(rootCmd).PositionalAnyCompletion(
33+
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
34+
if rootCmd.Flag("e").Changed {
35+
return bridge.ActionCarapaceBin()
36+
}
37+
return carapace.ActionValues()
38+
}),
39+
)
3340
}
3441

3542
func addConfigs(cmd *cobra.Command) {
36-
cmd.Flags().Bool("_xdg-terminal-exec", false, "Set to true if Ghostty was executed as xdg-terminal-exec on Linux")
3743
cmd.Flags().String("abnormal-command-exit-runtime", "", "The number of milliseconds of runtime below which we consider a process exit to be abnormal")
3844
cmd.Flags().String("adjust-box-thickness", "", "Thickness in pixels of box drawing characters")
3945
cmd.Flags().String("adjust-cell-height", "", "Height of the cell")
4046
cmd.Flags().String("adjust-cell-width", "", "Witdth of the cell")
4147
cmd.Flags().String("adjust-cursor-height", "", "Height in pixels of the cursor")
4248
cmd.Flags().String("adjust-cursor-thickness", "", "Thickness in pixels of the bar cursor and outlined rect cursor")
4349
cmd.Flags().String("adjust-font-baseline", "", "Distance in pixels from the bottom of the cell to the text baseline")
50+
cmd.Flags().String("adjust-icon-height", "", "Height in pixels or percentage adjustment of maximum height for nerd font icons")
4451
cmd.Flags().String("adjust-overline-position", "", "Distance in pixels from the top of the cell to the top of the overline")
4552
cmd.Flags().String("adjust-overline-thickness", "", "Thickness in pixels of the overline")
4653
cmd.Flags().String("adjust-strikethrough-position", "", "Distance in pixels from the top of the cell to the top of the strikethrough")
4754
cmd.Flags().String("adjust-strikethrough-thickness", "", "Thickness in pixels of the strikethrough")
4855
cmd.Flags().String("adjust-underline-position", "", "Distance in pixels from the top of the cell to the top of the underline")
4956
cmd.Flags().String("adjust-underline-thickness", "", "Thickness in pixels of the underline")
50-
cmd.Flags().String("adw-toolbar-style", "", "Determines the appearance of the top and bottom bars when using the Adwaita tab bar")
57+
cmd.Flags().String("alpha-blending", "", "What color space to use when performing alpha blending")
58+
cmd.Flags().String("app-notifications", "", "Control the in-app notifications that Ghostty shows")
59+
cmd.Flags().String("async-backend", "", "Configures the low-level API to use for async IO, eventing, etc.")
5160
cmd.Flags().String("auto-update", "", "Control the auto-update functionality of Ghostty")
5261
cmd.Flags().String("auto-update-channel", "", "The release channel to use for auto-updates")
53-
cmd.Flags().String("background-blur-radius", "", "A positive value enables blurring of the background when background-opacity is less than 1")
62+
cmd.Flags().String("background", "", "Background color for the window")
63+
cmd.Flags().String("background-blur", "", "Whether to blur the background when `background-opacity` is less than 1")
64+
cmd.Flags().String("background-image", "", "Background image for the terminal")
65+
cmd.Flags().String("background-image-fit", "", "Background image fit")
66+
cmd.Flags().String("background-image-opacity", "", "Background image opacity")
67+
cmd.Flags().String("background-image-position", "", "Background image position")
68+
cmd.Flags().Bool("background-image-repeat", false, "Whether to repeat the background image or not")
5469
cmd.Flags().String("background-opacity", "", "The opacity level (opposite of transparency) of the background")
55-
cmd.Flags().Bool("bold-is-bright", false, "If `true`, the bold text will use the bright color palette")
70+
cmd.Flags().Bool("background-opacity-cells", false, "Applies background opacity to cells with an explicit background color set")
71+
cmd.Flags().String("bell-audio-path", "", "If `audio` is an enabled bell feature, this is a path to an audio file")
72+
cmd.Flags().String("bell-audio-volume", "", "If `audio` is an enabled bell feature, this is the volume to play the audio file at")
73+
cmd.Flags().String("bell-features", "", "Bell features to enable if bell support is available in your runtime")
74+
cmd.Flags().String("bold-color", "", "Modifies the color used for bold text in the terminal")
75+
cmd.Flags().String("class", "", "The setting that will change the application class value")
5676
cmd.Flags().String("click-repeat-interval", "", "The time in milliseconds between clicks to consider a click a repeat")
5777
cmd.Flags().Bool("clipboard-paste-bracketed-safe", false, "If true, bracketed pastes will be considered safe")
5878
cmd.Flags().Bool("clipboard-paste-protection", false, "Require confirmation before pasting text that appears unsafe")
5979
cmd.Flags().String("clipboard-read", "", "Whether to allow programs running in the terminal to read from the system clipboard")
6080
cmd.Flags().Bool("clipboard-trim-trailing-spaces", false, "Trims trailing whitespace on data that is copied to the clipboard")
6181
cmd.Flags().String("clipboard-write", "", "Whether to allow programs running in the terminal to write to the system clipboard")
82+
cmd.Flags().String("command", "", "The command to run, usually a shell")
6283
cmd.Flags().Bool("config-default-files", false, "When this is true, the default configuration file paths will be loaded")
6384
cmd.Flags().StringArray("config-file", nil, "Additional configuration files to read")
6485
cmd.Flags().Bool("confirm-close-surface", false, "Confirms that a surface should be closed before closing it")
6586
cmd.Flags().String("copy-on-select", "", "Whether to automatically copy selected text to the clipboard")
6687
cmd.Flags().Bool("cursor-click-to-move", false, "Enables the ability to move the cursor at prompts")
6788
cmd.Flags().String("cursor-color", "", "The color of the cursor")
68-
cmd.Flags().Bool("cursor-invert-fg-bg", false, "Swap the foreground and background colors of the cell under the cursor")
6989
cmd.Flags().String("cursor-opacity", "", "The opacity level (opposite of transparency) of the cursor")
7090
cmd.Flags().String("cursor-style", "", "The style of the cursor")
7191
cmd.Flags().Bool("cursor-style-blink", false, "Sets the default blinking state of the cursor")
@@ -98,6 +118,7 @@ func addConfigs(cmd *cobra.Command) {
98118
cmd.Flags().String("gtk-single-instance", "", "Run in single-instance mode")
99119
cmd.Flags().String("gtk-tabs-location", "", "Determines the side of the screen that the GTK tab bar will stick to")
100120
cmd.Flags().Bool("gtk-titlebar", false, "Display the full GTK titlebar")
121+
cmd.Flags().Bool("gtk-toolbar-style", false, "Determines the appearance of the top and bottom bars tab bar")
101122
cmd.Flags().Bool("gtk-wide-tabs", false, "Use \"wide\" GTK tabs")
102123
cmd.Flags().String("image-storage-limit", "", "The total amount of bytes that can be used for image data")
103124
cmd.Flags().String("initial-command", "", "This is the same as \"command\", but only applies to the first terminal surface created")
@@ -135,7 +156,6 @@ func addConfigs(cmd *cobra.Command) {
135156
cmd.Flags().String("scrollback-limit", "", "The size of the scrollback buffer in bytes")
136157
cmd.Flags().String("selection-background", "", "The background color for selection")
137158
cmd.Flags().String("selection-foreground", "", "The foreground color for selection")
138-
cmd.Flags().Bool("selection-invert-fg-bg", false, "Swap the foreground and background colors of cells for selection")
139159
cmd.Flags().String("shell-integration", "", "Whether to enable shell integration auto-injection or not")
140160
cmd.Flags().String("shell-integration-features", "", "Shell integration features to enable")
141161
cmd.Flags().String("unfocused-split-fill", "", "The color to dim the unfocused split")
@@ -161,13 +181,40 @@ func addConfigs(cmd *cobra.Command) {
161181
cmd.Flags().String("working-directory", "", "The directory to change to after starting the command")
162182
cmd.Flags().String("x11-instance-name", "", "This controls the instance name field of the `WM_CLASS` X11 property")
163183

184+
cmd.Flags().VisitAll(func(f *pflag.Flag) {
185+
if f.Value.Type() != "bool" {
186+
f.NoOptDefVal = " " // flag arguments need to be passed in attached mode
187+
}
188+
})
189+
164190
// TODO use font-families from `+list-fonts`?
165191
carapace.Gen(cmd).FlagCompletion(carapace.ActionMap{
166-
"adw-toolbar-style": ghostty.ActionAdwToolbarStyles(),
167-
"auto-update": ghostty.ActionAutoUpdateModes(),
168-
"auto-update-channel": ghostty.ActionReleaseChannels(),
192+
"alpha-blending": ghostty.ActionAlphaBlendings(),
193+
"app-notifications": ghostty.ActionNotifications().UniqueList(","),
194+
"async-backend": ghostty.ActionAsyncBackends(),
195+
"auto-update": ghostty.ActionAutoUpdateModes(),
196+
"auto-update-channel": ghostty.ActionReleaseChannels(),
197+
"background": carapace.Batch(
198+
color.ActionHexColors(),
199+
color.ActionXtermColorNames(),
200+
).ToA(),
201+
"background-blur": carapace.ActionValuesDescribed(
202+
"false", "equivalent to a blur intensity of 0",
203+
"true", "equivalent to the default blur intensity of 20",
204+
).StyleF(style.ForKeyword),
205+
"background-image": carapace.ActionFiles(),
206+
"background-image-fit": ghostty.ActionBackgroundImageFits(),
207+
"background-image-position": ghostty.ActionBackgroundImagePositions(),
208+
"bell-audio-path": carapace.ActionFiles(),
209+
"bell-features": ghostty.ActionBellFeatures().UniqueList(","),
210+
"bold-color": carapace.Batch(
211+
color.ActionHexColors(),
212+
color.ActionXtermColorNames(),
213+
carapace.ActionValues("bright"),
214+
).ToA(),
169215
"clipboard-read": carapace.ActionValues("ask", "allow", "deny").StyleF(style.ForKeyword),
170216
"clipboard-write": carapace.ActionValues("ask", "allow", "deny").StyleF(style.ForKeyword),
217+
"command": bridge.ActionCarapaceBin().SplitP(),
171218
"config-file": carapace.ActionFiles(),
172219
"copy-on-select": ghostty.ActionCopyOnSelectModes(),
173220
"cursor-color": color.ActionHexColors(),
@@ -201,6 +248,7 @@ func addConfigs(cmd *cobra.Command) {
201248
"grapheme-width-method": ghostty.ActionGraphemeWidthMethods(),
202249
"gtk-single-instance": carapace.ActionValues("true", "false", "detect").StyleF(style.ForKeyword),
203250
"gtk-tabs-location": carapace.ActionValues("top", "bottom", "left", "right", "hidden"),
251+
"gtk-toolbar-style": ghostty.ActionGtkToolbarStyles(),
204252
"initial-command": bridge.ActionCarapaceBin().Split(),
205253
"linux-cgroup": carapace.ActionValuesDescribed(
206254
"never", "Never use cgroups",

pkg/actions/color/hex.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,6 @@ func ActionHexColors() carapace.Action {
269269
"#dadada", "Grey85", style.XTerm256Color(253),
270270
"#e4e4e4", "Grey89", style.XTerm256Color(254),
271271
"#eeeeee", "Grey93", style.XTerm256Color(255),
272-
)
272+
).Tag("hex colors")
273273
})
274274
}

pkg/actions/color/xterm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ func ActionXtermColorNames() carapace.Action {
2828
"Fuchsia", style.XTerm256Color(13),
2929
"Aqua", style.XTerm256Color(14),
3030
"White", style.XTerm256Color(15),
31-
)
31+
).Tag("xterm colors")
3232
})
3333
}

pkg/actions/tools/ghostty/alpha.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package ghostty
2+
3+
import "github.com/carapace-sh/carapace"
4+
5+
// ActionAlphaBlendings completes alpha blendings
6+
//
7+
// native (Perform alpha blending in the native color space for the OS)
8+
// linear (Perform alpha blending in linear space)
9+
func ActionAlphaBlendings() carapace.Action {
10+
return carapace.ActionValuesDescribed(
11+
"native", "Perform alpha blending in the native color space for the OS",
12+
"linear", "Perform alpha blending in linear space",
13+
"linear-corrected", "Same as `linear`, but with a correction step applied",
14+
)
15+
}

pkg/actions/tools/ghostty/async.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package ghostty
2+
3+
import (
4+
"github.com/carapace-sh/carapace"
5+
"github.com/carapace-sh/carapace/pkg/style"
6+
)
7+
8+
// ActionAsyncBackends completes async backends
9+
//
10+
// epoll (Use the `epoll` API)
11+
// io_uring (Use the `io_uring` API)
12+
func ActionAsyncBackends() carapace.Action {
13+
return carapace.ActionStyledValuesDescribed(
14+
"auto", "Automatically choose the best backend for the platform based on available options",
15+
"epoll", "Use the `epoll` API",
16+
"io_uring", "Use the `io_uring` API",
17+
).StyleF(style.ForKeyword).
18+
Tag("async backends")
19+
}

pkg/actions/tools/ghostty/bell.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package ghostty
2+
3+
import "github.com/carapace-sh/carapace"
4+
5+
// ActionBellFeatures completes bell features
6+
//
7+
// audio (Play a custom sound)
8+
// attention (Request the user's attention when Ghostty is unfocused)
9+
func ActionBellFeatures() carapace.Action {
10+
return carapace.ActionValuesDescribed(
11+
"system", "Instruct the system to notify the user using built-in system functions",
12+
"audio", "Play a custom sound",
13+
"attention", "Request the user's attention when Ghostty is unfocused",
14+
"title", "Prepend a bell emoji (🔔) to the title of the alerted surface",
15+
"border", "Display a border around the alerted surface",
16+
).Tag("bell features")
17+
}

pkg/actions/tools/ghostty/image.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package ghostty
2+
3+
import (
4+
"github.com/carapace-sh/carapace"
5+
"github.com/carapace-sh/carapace/pkg/style"
6+
)
7+
8+
// ActionBackgroundImageFits completes background image fits
9+
//
10+
// contain (scale to the largest size that can still be contained)
11+
// cover (scale to the smallest size that can completely cover the terminal)
12+
func ActionBackgroundImageFits() carapace.Action {
13+
return carapace.ActionValuesDescribed(
14+
"contain", "scale to the largest size that can still be contained",
15+
"cover", "scale to the smallest size that can completely cover the terminal",
16+
"stretch", "stretch the background image to the full size of the terminal",
17+
"none", "don't scale the background image",
18+
).StyleF(style.ForKeyword).
19+
Tag("background image fits")
20+
}
21+
22+
// ActionBackgroundImagePositions completes background image positions
23+
//
24+
// top-left
25+
// top-center
26+
func ActionBackgroundImagePositions() carapace.Action {
27+
return carapace.ActionValues(
28+
"top-left",
29+
"top-center",
30+
"top-right",
31+
"center-left",
32+
"center",
33+
"center-right",
34+
"bottom-left",
35+
"bottom-center",
36+
"bottom-right",
37+
).Tag("background image positions")
38+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package ghostty
2+
3+
import (
4+
"github.com/carapace-sh/carapace"
5+
"github.com/carapace-sh/carapace/pkg/style"
6+
)
7+
8+
// ActionNotifications completes app notifications
9+
//
10+
// clipboard-copy (Show a notification when text is copied to the clipboard)
11+
// config-reload (Show a notification when the configuration is reloaded)
12+
func ActionNotifications() carapace.Action {
13+
return carapace.ActionValuesDescribed(
14+
"clipboard-copy", "Show a notification when text is copied to the clipboard",
15+
"config-reload", "Show a notification when the configuration is reloaded",
16+
"no-clipboard-copy", "Do not show a notification when text is copied to the clipboard",
17+
"no-config-reload", "Do not show a notification when the configuration is reloaded",
18+
"false", "disable all notifications",
19+
"true", "will enable all notifications",
20+
).StyleF(style.ForKeyword)
21+
}

pkg/actions/tools/ghostty/toolbar.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ package ghostty
22

33
import "github.com/carapace-sh/carapace"
44

5-
// ActionAdwToolbarStyles completes adw toolbar styles
5+
// ActionGtkToolbarStyles completes adw toolbar styles
66
//
77
// flat (Top and bottom bars are flat with the terminal window)
88
// raised (Top and bottom bars cast a shadow on the terminal area)
9-
func ActionAdwToolbarStyles() carapace.Action {
9+
func ActionGtkToolbarStyles() carapace.Action {
1010
return carapace.ActionValuesDescribed(
1111
"flat", "Top and bottom bars are flat with the terminal window",
1212
"raised", "Top and bottom bars cast a shadow on the terminal area",
1313
"raised-border", "Similar to `raised` but the shadow is replaced with a more subtle border",
14-
).Tag("adw toolbar styles")
14+
).Tag("gtk toolbar styles")
1515
}

0 commit comments

Comments
 (0)