Wire up applying of font config

This commit is contained in:
Kovid Goyal
2024-05-18 13:27:34 +05:30
parent 726f62b948
commit 94d056ed4f
3 changed files with 47 additions and 4 deletions

View File

@@ -2,9 +2,12 @@ package choose_fonts
import ( import (
"fmt" "fmt"
"path/filepath"
"strings" "strings"
"kitty/tools/config"
"kitty/tools/tui/loop" "kitty/tools/tui/loop"
"kitty/tools/utils"
) )
var _ = fmt.Print var _ = fmt.Print
@@ -72,6 +75,26 @@ func (self *final_pane) on_key_event(event *loop.KeyEvent) (err error) {
self.handler.current_pane = &self.handler.faces self.handler.current_pane = &self.handler.faces
return self.handler.draw_screen() return self.handler.draw_screen()
} }
if event.MatchesPressOrRepeat("enter") {
event.Handled = true
patcher := config.Patcher{Write_backup: true}
path := filepath.Join(utils.ConfigDir(), "kitty.conf")
updated, err := patcher.Patch(path, "KITTY_FONTS", self.settings.serialized(), "font_family", "bold_font", "italic_font", "bold_italic_font")
if err != nil {
return err
}
if updated {
switch self.handler.opts.Reload_in {
case "parent":
config.ReloadConfigInKitty(true)
case "all":
config.ReloadConfigInKitty(false)
}
}
self.lp.Quit(0)
return nil
}
return return
} }

View File

@@ -13,7 +13,7 @@ var _ = fmt.Print
var debugprintln = tty.DebugPrintln var debugprintln = tty.DebugPrintln
var output_on_exit string var output_on_exit string
func main() (rc int, err error) { func main(opts *Options) (rc int, err error) {
if err = kitty_font_backend.start(); err != nil { if err = kitty_font_backend.start(); err != nil {
return 1, err return 1, err
} }
@@ -32,7 +32,7 @@ func main() (rc int, err error) {
return 1, err return 1, err
} }
lp.MouseTrackingMode(loop.FULL_MOUSE_TRACKING) lp.MouseTrackingMode(loop.FULL_MOUSE_TRACKING)
h := &handler{lp: lp} h := &handler{lp: lp, opts: opts}
lp.OnInitialize = func() (string, error) { lp.OnInitialize = func() (string, error) {
lp.AllowLineWrapping(false) lp.AllowLineWrapping(false)
lp.SetWindowTitle(`Choose a font for kitty`) lp.SetWindowTitle(`Choose a font for kitty`)
@@ -67,13 +67,32 @@ func main() (rc int, err error) {
return lp.ExitCode(), nil return lp.ExitCode(), nil
} }
type Options struct {
Reload_in string
}
func EntryPoint(root *cli.Command) { func EntryPoint(root *cli.Command) {
ans := root.AddSubCommand(&cli.Command{ ans := root.AddSubCommand(&cli.Command{
Name: "choose-fonts", Name: "choose-fonts",
ShortDescription: "Choose the fonts used in kitty",
Run: func(cmd *cli.Command, args []string) (rc int, err error) { Run: func(cmd *cli.Command, args []string) (rc int, err error) {
return main() opts := Options{}
if err = cmd.GetOptionValues(&opts); err != nil {
return 1, err
}
return main(&opts)
}, },
}) })
ans.Add(cli.OptionSpec{
Name: "--reload-in",
Dest: "Reload_in",
Type: "choices",
Choices: "parent, all, none",
Default: "parent",
Help: `By default, this kitten will signal only the parent kitty instance it is
running in to reload its config, after making changes. Use this option to
instead either not reload the config at all or in all running kitty instances.`,
})
clone := root.AddClone(ans.Group, ans) clone := root.AddClone(ans.Group, ans)
clone.Hidden = false clone.Hidden = false
clone.Name = "choose_fonts" clone.Name = "choose_fonts"

View File

@@ -40,6 +40,7 @@ type pane interface {
} }
type handler struct { type handler struct {
opts *Options
lp *loop.Loop lp *loop.Loop
state State state State
err_mutex sync.Mutex err_mutex sync.Mutex