From 6e398ed6fbc9f3175ffbb2ba09c5156c0bb4a28d Mon Sep 17 00:00:00 2001 From: Ben Blackmore Date: Tue, 26 Jul 2022 15:54:46 +0200 Subject: [PATCH] feat: allow disable CTRL-C behavior (#1672) Fixes #1599 --- README.md | 2 ++ internal/config/config_test.go | 2 ++ internal/config/k9s.go | 1 + internal/ui/app.go | 6 +++++- 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1233ec70..6a178026 100644 --- a/README.md +++ b/README.md @@ -301,6 +301,8 @@ K9s uses aliases to navigate most K8s resources. crumbsless: false # Indicates whether modification commands like delete/kill/edit are disabled. Default is false readOnly: false + # Toggles whether k9s should exit when CTRL-C is pressed. When set to true, you will need to exist k9s via the :quit command. Default is false. + noExitOnCtrlC: false # Toggles icons display as not all terminal support these chars. noIcons: false # Logs configuration diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 29cc70f5..91750fd3 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -284,6 +284,7 @@ var expectedConfig = `k9s: logoless: false crumbsless: false readOnly: true + noExitOnCtrlC: false noIcons: false logger: tail: 500 @@ -378,6 +379,7 @@ var resetConfig = `k9s: logoless: false crumbsless: false readOnly: false + noExitOnCtrlC: false noIcons: false logger: tail: 200 diff --git a/internal/config/k9s.go b/internal/config/k9s.go index d6e679b6..2ed38fff 100644 --- a/internal/config/k9s.go +++ b/internal/config/k9s.go @@ -18,6 +18,7 @@ type K9s struct { Logoless bool `yaml:"logoless"` Crumbsless bool `yaml:"crumbsless"` ReadOnly bool `yaml:"readOnly"` + NoExitOnCtrlC bool `yaml:"noExitOnCtrlC"` NoIcons bool `yaml:"noIcons"` Logger *Logger `yaml:"logger"` CurrentContext string `yaml:"currentContext"` diff --git a/internal/ui/app.go b/internal/ui/app.go index 5770e07c..55fa2a18 100644 --- a/internal/ui/app.go +++ b/internal/ui/app.go @@ -193,8 +193,12 @@ func (a *App) quitCmd(evt *tcell.EventKey) *tcell.EventKey { if a.InCmdMode() { return evt } - a.BailOut() + if !a.Config.K9s.NoExitOnCtrlC { + a.BailOut() + } + + // overwrite the default ctrl-c behavior of tview return nil }