mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-05-13 16:37:27 +00:00
Dont use a global var for mocking
This commit is contained in:
parent
86a6685446
commit
795bf7fb52
3 changed files with 8 additions and 8 deletions
|
|
@ -224,7 +224,7 @@ type KittyOpts struct {
|
|||
Term, Shell_integration string
|
||||
}
|
||||
|
||||
func read_relevant_kitty_opts() KittyOpts {
|
||||
func read_relevant_kitty_opts(override_conf_path ...string) KittyOpts {
|
||||
ans := KittyOpts{Term: kitty.KittyConfigDefaults.Term, Shell_integration: kitty.KittyConfigDefaults.Shell_integration}
|
||||
handle_line := func(key, val string) error {
|
||||
switch key {
|
||||
|
|
@ -235,7 +235,7 @@ func read_relevant_kitty_opts() KittyOpts {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
config.ReadKittyConfig(handle_line)
|
||||
config.ReadKittyConfig(handle_line, override_conf_path...)
|
||||
return ans
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import (
|
|||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"kitty/tools/config"
|
||||
"kitty/tools/utils/shlex"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
|
@ -67,10 +66,8 @@ func TestParseSSHArgs(t *testing.T) {
|
|||
func TestRelevantKittyOpts(t *testing.T) {
|
||||
tdir := t.TempDir()
|
||||
path := filepath.Join(tdir, "kitty.conf")
|
||||
config.OverrideEffectiveConfigPath = path
|
||||
defer func() { config.OverrideEffectiveConfigPath = "" }()
|
||||
os.WriteFile(path, []byte("term XXX\nshell_integration changed\nterm abcd"), 0o600)
|
||||
rko := read_relevant_kitty_opts()
|
||||
rko := read_relevant_kitty_opts(path)
|
||||
if rko.Term != "abcd" {
|
||||
t.Fatalf("Unexpected TERM: %s", RelevantKittyOpts().Term)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -403,9 +403,12 @@ func ReloadConfigInKitty(in_parent_only bool) error {
|
|||
|
||||
var OverrideEffectiveConfigPath string
|
||||
|
||||
func ReadKittyConfig(line_handler func(key, val string) error) error {
|
||||
func ReadKittyConfig(line_handler func(key, val string) error, override_effective_config_path ...string) error {
|
||||
kp := os.Getenv("KITTY_PID")
|
||||
kitty_conf_path := OverrideEffectiveConfigPath
|
||||
kitty_conf_path := ""
|
||||
if len(override_effective_config_path) > 0 {
|
||||
kitty_conf_path = override_effective_config_path[0]
|
||||
}
|
||||
if _, err := strconv.Atoi(kp); err == nil && kitty_conf_path == "" {
|
||||
effective_config_path := filepath.Join(utils.CacheDir(), "effective-config", kp)
|
||||
if unix.Access(effective_config_path, unix.R_OK) == nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue