From 156ccaa04d94eb253c6cb5790fa8f6f3642b0ec5 Mon Sep 17 00:00:00 2001 From: Gerrit Germis Date: Wed, 19 Feb 2025 18:00:12 +0100 Subject: [PATCH 1/2] make flashDelay configurable --- internal/config/json/schemas/k9s.json | 1 + internal/config/k9s.go | 13 +++++++++---- internal/config/types.go | 1 + internal/model/flash.go | 3 --- internal/ui/app.go | 3 ++- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/internal/config/json/schemas/k9s.json b/internal/config/json/schemas/k9s.json index e6fc4d83cf..844a6b6d33 100644 --- a/internal/config/json/schemas/k9s.json +++ b/internal/config/json/schemas/k9s.json @@ -11,6 +11,7 @@ "screenDumpDir": {"type": "string"}, "refreshRate": { "type": "integer" }, "maxConnRetry": { "type": "integer" }, + "flashDelay": { "type": "integer" }, "readOnly": { "type": "boolean" }, "noExitOnCtrlC": { "type": "boolean" }, "skipLatestRevCheck": { "type": "boolean" }, diff --git a/internal/config/k9s.go b/internal/config/k9s.go index 5cc2ec411b..58b05ffc20 100644 --- a/internal/config/k9s.go +++ b/internal/config/k9s.go @@ -6,16 +6,15 @@ package config import ( "errors" "fmt" + "github.com/derailed/k9s/internal/client" + "github.com/derailed/k9s/internal/config/data" + "github.com/rs/zerolog/log" "io/fs" "net/http" "net/url" "os" "path/filepath" "sync" - - "github.com/derailed/k9s/internal/client" - "github.com/derailed/k9s/internal/config/data" - "github.com/rs/zerolog/log" ) // K9s tracks K9s configuration options. @@ -24,6 +23,7 @@ type K9s struct { ScreenDumpDir string `json:"screenDumpDir" yaml:"screenDumpDir,omitempty"` RefreshRate int `json:"refreshRate" yaml:"refreshRate"` MaxConnRetry int `json:"maxConnRetry" yaml:"maxConnRetry"` + FlashDelay int `json:"flashDelay" yaml:"flashDelay"` ReadOnly bool `json:"readOnly" yaml:"readOnly"` NoExitOnCtrlC bool `json:"noExitOnCtrlC" yaml:"noExitOnCtrlC"` UI UI `json:"ui" yaml:"ui"` @@ -53,6 +53,7 @@ func NewK9s(conn client.Connection, ks data.KubeSettings) *K9s { return &K9s{ RefreshRate: defaultRefreshRate, MaxConnRetry: defaultMaxConnRetry, + FlashDelay: defaultFlashDelay, ScreenDumpDir: AppDumpsDir, Logger: NewLogger(), Thresholds: NewThreshold(), @@ -99,6 +100,7 @@ func (k *K9s) Merge(k1 *K9s) { k.ScreenDumpDir = k1.ScreenDumpDir k.RefreshRate = k1.RefreshRate k.MaxConnRetry = k1.MaxConnRetry + k.FlashDelay = k1.FlashDelay k.ReadOnly = k1.ReadOnly k.NoExitOnCtrlC = k1.NoExitOnCtrlC k.UI = k1.UI @@ -347,6 +349,9 @@ func (k *K9s) Validate(c client.Connection, ks data.KubeSettings) { if k.MaxConnRetry <= 0 { k.MaxConnRetry = defaultMaxConnRetry } + if k.FlashDelay <= 0 { + k.FlashDelay = defaultFlashDelay + } if k.getActiveConfig() == nil { if n, err := ks.CurrentContextName(); err == nil { diff --git a/internal/config/types.go b/internal/config/types.go index 6938e55585..81e6871b00 100644 --- a/internal/config/types.go +++ b/internal/config/types.go @@ -6,6 +6,7 @@ package config const ( defaultRefreshRate = 2 defaultMaxConnRetry = 5 + defaultFlashDelay = 3 ) // UI tracks ui specific configs. diff --git a/internal/model/flash.go b/internal/model/flash.go index d4bb7c8dc1..0a71ba5c9e 100644 --- a/internal/model/flash.go +++ b/internal/model/flash.go @@ -12,9 +12,6 @@ import ( ) const ( - // DefaultFlashDelay sets the flash clear delay. - DefaultFlashDelay = 3 * time.Second - // FlashInfo represents an info message. FlashInfo FlashLevel = iota // FlashWarn represents an warning message. diff --git a/internal/ui/app.go b/internal/ui/app.go index 16f9ebcfcf..e9d7c8974a 100644 --- a/internal/ui/app.go +++ b/internal/ui/app.go @@ -6,6 +6,7 @@ package ui import ( "os" "sync" + "time" "github.com/derailed/k9s/internal/client" "github.com/derailed/k9s/internal/config" @@ -36,7 +37,7 @@ func NewApp(cfg *config.Config, context string) *App { actions: NewKeyActions(), Configurator: Configurator{Config: cfg, Styles: config.NewStyles()}, Main: NewPages(), - flash: model.NewFlash(model.DefaultFlashDelay), + flash: model.NewFlash(time.Duration(cfg.K9s.FlashDelay) * time.Second), cmdBuff: model.NewFishBuff(':', model.CommandBuffer), } From 1830ed080689c3c02047280052fe8a57155a7671 Mon Sep 17 00:00:00 2001 From: Gerrit Germis Date: Wed, 19 Feb 2025 18:05:34 +0100 Subject: [PATCH 2/2] do not move imports --- internal/config/k9s.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/config/k9s.go b/internal/config/k9s.go index 58b05ffc20..dc026c9445 100644 --- a/internal/config/k9s.go +++ b/internal/config/k9s.go @@ -6,15 +6,16 @@ package config import ( "errors" "fmt" - "github.com/derailed/k9s/internal/client" - "github.com/derailed/k9s/internal/config/data" - "github.com/rs/zerolog/log" "io/fs" "net/http" "net/url" "os" "path/filepath" "sync" + + "github.com/derailed/k9s/internal/client" + "github.com/derailed/k9s/internal/config/data" + "github.com/rs/zerolog/log" ) // K9s tracks K9s configuration options.