Skip to content

Commit 4557201

Browse files
authored
Merge pull request #3174 from carapace-sh/ghostty-font-family
ghostty: use font families provided by ghostty
2 parents 296a7af + ae129cf commit 4557201

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

completers/common/ghostty_completer/cmd/listFonts.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package cmd
22

33
import (
44
"github.com/carapace-sh/carapace"
5-
"github.com/carapace-sh/carapace-bin/pkg/actions/os"
5+
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/ghostty"
66
"github.com/spf13/cobra"
77
)
88

@@ -22,6 +22,6 @@ func init() {
2222
rootCmd.AddCommand(listFontsCmd)
2323

2424
carapace.Gen(listFontsCmd).FlagCompletion(carapace.ActionMap{
25-
"family": os.ActionFontFamilies(),
25+
"family": ghostty.ActionFontFamilies(),
2626
})
2727
}

completers/common/ghostty_completer/cmd/root.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cmd
33
import (
44
"github.com/carapace-sh/carapace"
55
"github.com/carapace-sh/carapace-bin/pkg/actions/color"
6-
"github.com/carapace-sh/carapace-bin/pkg/actions/os"
76
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/ghostty"
87
"github.com/carapace-sh/carapace-bridge/pkg/actions/bridge"
98
"github.com/carapace-sh/carapace/pkg/style"
@@ -181,13 +180,13 @@ func addConfigs(cmd *cobra.Command) {
181180
case 0:
182181
return carapace.ActionValues() // TODO codepoint
183182
default:
184-
return os.ActionFontFamilies()
183+
return ghostty.ActionFontFamilies()
185184
}
186185
}),
187-
"font-family": os.ActionFontFamilies(),
188-
"font-family-bold": os.ActionFontFamilies(),
189-
"font-family-bold-italic": os.ActionFontFamilies(),
190-
"font-family-italic": os.ActionFontFamilies(),
186+
"font-family": ghostty.ActionFontFamilies(),
187+
"font-family-bold": ghostty.ActionFontFamilies(),
188+
"font-family-bold-italic": ghostty.ActionFontFamilies(),
189+
"font-family-italic": ghostty.ActionFontFamilies(),
191190
"font-feature": carapace.ActionValues(), // TODO font-features
192191
"font-style": carapace.ActionValues(), // TODO font style
193192
"font-style-bold": carapace.ActionValues(), // TODO font style
@@ -232,7 +231,7 @@ func addConfigs(cmd *cobra.Command) {
232231
"window-padding-color": ghostty.ActionWindowPaddingColors(),
233232
"window-save-state": ghostty.ActionWindowSaveStates(),
234233
"window-theme": ghostty.ActionWindowThemes(),
235-
"window-title-font-family": os.ActionFontFamilies(),
234+
"window-title-font-family": ghostty.ActionFontFamilies(),
236235
"working-directory": carapace.ActionDirectories(),
237236
})
238237
}

pkg/actions/tools/ghostty/font.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package ghostty
22

3-
import "github.com/carapace-sh/carapace"
3+
import (
4+
"strings"
5+
6+
"github.com/carapace-sh/carapace"
7+
)
48

59
// ActionFontSyntheticStyles completes font synthetic styles
610
//
@@ -16,7 +20,7 @@ func ActionFontSyntheticStyles() carapace.Action {
1620
"no-bold-italic", "disable for bold-italic",
1721
"no-italic", "disable for italic",
1822
"true", "completely enable",
19-
)
23+
).Tag("font synthetic styles")
2024
}
2125

2226
// ActionFreetypeLoadFlags completes freetype load flags
@@ -33,5 +37,23 @@ func ActionFreetypeLoadFlags() carapace.Action {
3337
"no-force-autohint", "Do not se the freetype auto-hinter",
3438
"no-monochrome", "Do not use 1-bit monochrome rendering",
3539
"no-autohint", "Do not use the freetype auto-hinter",
36-
)
40+
).Tag("freetype load flags")
41+
}
42+
43+
// ActionFontFamilies completes font families
44+
//
45+
// FreeMono
46+
// FreeSans
47+
func ActionFontFamilies() carapace.Action {
48+
return carapace.ActionExecCommand("ghostty", "+list-fonts")(func(output []byte) carapace.Action {
49+
lines := strings.Split(string(output), "\n")
50+
51+
vals := make([]string, 0)
52+
for _, line := range lines {
53+
if line != "" && !strings.HasPrefix(line, " ") {
54+
vals = append(vals, line)
55+
}
56+
}
57+
return carapace.ActionValues(vals...)
58+
}).Tag("font families")
3759
}

0 commit comments

Comments
 (0)