mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 14:18:26 +02:00
Implement using effective kitty config options for kittens
Also centralise reading of kitty options
This commit is contained in:
@@ -4,7 +4,6 @@ package diff
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -25,7 +24,7 @@ type KittyOpts struct {
|
|||||||
Copy_on_select bool
|
Copy_on_select bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func read_relevant_kitty_opts(path string) KittyOpts {
|
func read_relevant_kitty_opts() KittyOpts {
|
||||||
ans := KittyOpts{Wheel_scroll_multiplier: kitty.KittyConfigDefaults.Wheel_scroll_multiplier}
|
ans := KittyOpts{Wheel_scroll_multiplier: kitty.KittyConfigDefaults.Wheel_scroll_multiplier}
|
||||||
handle_line := func(key, val string) error {
|
handle_line := func(key, val string) error {
|
||||||
switch key {
|
switch key {
|
||||||
@@ -39,13 +38,12 @@ func read_relevant_kitty_opts(path string) KittyOpts {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
cp := config.ConfigParser{LineHandler: handle_line}
|
config.ReadKittyConfig(handle_line)
|
||||||
_ = cp.ParseFiles(path)
|
|
||||||
return ans
|
return ans
|
||||||
}
|
}
|
||||||
|
|
||||||
var RelevantKittyOpts = sync.OnceValue(func() KittyOpts {
|
var RelevantKittyOpts = sync.OnceValue(func() KittyOpts {
|
||||||
return read_relevant_kitty_opts(filepath.Join(utils.ConfigDir(), "kitty.conf"))
|
return read_relevant_kitty_opts()
|
||||||
})
|
})
|
||||||
|
|
||||||
func (self *Handler) handle_wheel_event(up bool) {
|
func (self *Handler) handle_wheel_event(up bool) {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"slices"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -211,7 +210,7 @@ type KittyOpts struct {
|
|||||||
Select_by_word_characters string
|
Select_by_word_characters string
|
||||||
}
|
}
|
||||||
|
|
||||||
func read_relevant_kitty_opts(path string) KittyOpts {
|
func read_relevant_kitty_opts() KittyOpts {
|
||||||
ans := KittyOpts{
|
ans := KittyOpts{
|
||||||
Select_by_word_characters: kitty.KittyConfigDefaults.Select_by_word_characters,
|
Select_by_word_characters: kitty.KittyConfigDefaults.Select_by_word_characters,
|
||||||
Url_excluded_characters: kitty.KittyConfigDefaults.Url_excluded_characters}
|
Url_excluded_characters: kitty.KittyConfigDefaults.Url_excluded_characters}
|
||||||
@@ -228,8 +227,7 @@ func read_relevant_kitty_opts(path string) KittyOpts {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
cp := config.ConfigParser{LineHandler: handle_line}
|
config.ReadKittyConfig(handle_line)
|
||||||
_ = cp.ParseFiles(path) // ignore errors and use defaults
|
|
||||||
if ans.Url_prefixes == nil {
|
if ans.Url_prefixes == nil {
|
||||||
ans.Url_prefixes = utils.NewSetWithItems(kitty.KittyConfigDefaults.Url_prefixes...)
|
ans.Url_prefixes = utils.NewSetWithItems(kitty.KittyConfigDefaults.Url_prefixes...)
|
||||||
}
|
}
|
||||||
@@ -237,7 +235,7 @@ func read_relevant_kitty_opts(path string) KittyOpts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var RelevantKittyOpts = sync.OnceValue(func() KittyOpts {
|
var RelevantKittyOpts = sync.OnceValue(func() KittyOpts {
|
||||||
return read_relevant_kitty_opts(filepath.Join(utils.ConfigDir(), "kitty.conf"))
|
return read_relevant_kitty_opts()
|
||||||
})
|
})
|
||||||
|
|
||||||
var debugprintln = tty.DebugPrintln
|
var debugprintln = tty.DebugPrintln
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -225,7 +224,7 @@ type KittyOpts struct {
|
|||||||
Term, Shell_integration string
|
Term, Shell_integration string
|
||||||
}
|
}
|
||||||
|
|
||||||
func read_relevant_kitty_opts(path string) KittyOpts {
|
func read_relevant_kitty_opts() KittyOpts {
|
||||||
ans := KittyOpts{Term: kitty.KittyConfigDefaults.Term, Shell_integration: kitty.KittyConfigDefaults.Shell_integration}
|
ans := KittyOpts{Term: kitty.KittyConfigDefaults.Term, Shell_integration: kitty.KittyConfigDefaults.Shell_integration}
|
||||||
handle_line := func(key, val string) error {
|
handle_line := func(key, val string) error {
|
||||||
switch key {
|
switch key {
|
||||||
@@ -236,11 +235,10 @@ func read_relevant_kitty_opts(path string) KittyOpts {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
cp := config.ConfigParser{LineHandler: handle_line}
|
config.ReadKittyConfig(handle_line)
|
||||||
cp.ParseFiles(path)
|
|
||||||
return ans
|
return ans
|
||||||
}
|
}
|
||||||
|
|
||||||
var RelevantKittyOpts = sync.OnceValue(func() KittyOpts {
|
var RelevantKittyOpts = sync.OnceValue(func() KittyOpts {
|
||||||
return read_relevant_kitty_opts(filepath.Join(utils.ConfigDir(), "kitty.conf"))
|
return read_relevant_kitty_opts()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"kitty"
|
"kitty"
|
||||||
"maps"
|
"maps"
|
||||||
"path/filepath"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -170,8 +169,7 @@ func ReadKittyColorSettings() map[string]string {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
cp := config.ConfigParser{LineHandler: handle_line}
|
config.ReadKittyConfig(handle_line)
|
||||||
cp.ParseFiles(filepath.Join(utils.ConfigDir(), "kitty.conf"))
|
|
||||||
return settings
|
return settings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -400,3 +400,19 @@ func ReloadConfigInKitty(in_parent_only bool) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ReadKittyConfig(line_handler func(key, val string) error) error {
|
||||||
|
kitty_conf_path := ""
|
||||||
|
kp := os.Getenv("KITTY_PID")
|
||||||
|
if _, err := strconv.Atoi(kp); err == nil {
|
||||||
|
effective_config_path := filepath.Join(utils.CacheDir(), "effective-config", kp)
|
||||||
|
if unix.Access(effective_config_path, unix.R_OK) == nil {
|
||||||
|
kitty_conf_path = effective_config_path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if kitty_conf_path == "" {
|
||||||
|
kitty_conf_path = filepath.Join(utils.ConfigDir(), "kitty.conf")
|
||||||
|
}
|
||||||
|
cp := ConfigParser{LineHandler: line_handler}
|
||||||
|
return cp.ParseFiles(kitty_conf_path)
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ package tui
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"kitty"
|
"kitty"
|
||||||
@@ -268,9 +267,8 @@ func (m *MouseState) ApplyHoverStyles(lp *loop.Loop, style ...string) {
|
|||||||
if len(style) == 0 {
|
if len(style) == 0 {
|
||||||
if !m.default_url_style.loaded {
|
if !m.default_url_style.loaded {
|
||||||
m.default_url_style.loaded = true
|
m.default_url_style.loaded = true
|
||||||
conf := filepath.Join(utils.ConfigDir(), "kitty.conf")
|
|
||||||
color, style := kitty.DefaultUrlColor, kitty.DefaultUrlStyle
|
color, style := kitty.DefaultUrlColor, kitty.DefaultUrlStyle
|
||||||
cp := config.ConfigParser{LineHandler: func(key, val string) error {
|
line_handler := func(key, val string) error {
|
||||||
switch key {
|
switch key {
|
||||||
case "url_color":
|
case "url_color":
|
||||||
color = val
|
color = val
|
||||||
@@ -278,9 +276,8 @@ func (m *MouseState) ApplyHoverStyles(lp *loop.Loop, style ...string) {
|
|||||||
style = val
|
style = val
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
|
||||||
}
|
}
|
||||||
_ = cp.ParseFiles(conf) // ignore errors and use defaults
|
config.ReadKittyConfig(line_handler)
|
||||||
if style != "none" && style != "" {
|
if style != "none" && style != "" {
|
||||||
m.default_url_style.value = fmt.Sprintf("u=%s uc=%s", style, color)
|
m.default_url_style.value = fmt.Sprintf("u=%s uc=%s", style, color)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ type KittyOpts struct {
|
|||||||
Shell, Shell_integration string
|
Shell, Shell_integration string
|
||||||
}
|
}
|
||||||
|
|
||||||
func read_relevant_kitty_opts(path string) KittyOpts {
|
func read_relevant_kitty_opts() KittyOpts {
|
||||||
ans := KittyOpts{Shell: kitty.KittyConfigDefaults.Shell, Shell_integration: kitty.KittyConfigDefaults.Shell_integration}
|
ans := KittyOpts{Shell: kitty.KittyConfigDefaults.Shell, Shell_integration: kitty.KittyConfigDefaults.Shell_integration}
|
||||||
handle_line := func(key, val string) error {
|
handle_line := func(key, val string) error {
|
||||||
switch key {
|
switch key {
|
||||||
@@ -41,8 +41,7 @@ func read_relevant_kitty_opts(path string) KittyOpts {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
cp := config.ConfigParser{LineHandler: handle_line}
|
config.ReadKittyConfig(handle_line)
|
||||||
_ = cp.ParseFiles(path)
|
|
||||||
if ans.Shell == "" {
|
if ans.Shell == "" {
|
||||||
ans.Shell = kitty.KittyConfigDefaults.Shell
|
ans.Shell = kitty.KittyConfigDefaults.Shell
|
||||||
}
|
}
|
||||||
@@ -63,7 +62,7 @@ func get_effective_ksi_env_var(x string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var relevant_kitty_opts = sync.OnceValue(func() KittyOpts {
|
var relevant_kitty_opts = sync.OnceValue(func() KittyOpts {
|
||||||
return read_relevant_kitty_opts(filepath.Join(utils.ConfigDir(), "kitty.conf"))
|
return read_relevant_kitty_opts()
|
||||||
})
|
})
|
||||||
|
|
||||||
func get_shell_from_kitty_conf() (shell string) {
|
func get_shell_from_kitty_conf() (shell string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user