From 9bb82973c5f80bc7a41213f53dc8e1775288eedb Mon Sep 17 00:00:00 2001 From: Berger Eugene Date: Sun, 3 Nov 2024 00:26:24 +0200 Subject: [PATCH] feat #268: Added setting to disable the exit confirmation in TUI --- src/cmd/project_runner.go | 9 +++-- src/config/settings.go | 5 ++- src/tui/tui_option.go | 7 ++++ src/tui/view.go | 85 +++++++++++++++++++++------------------ www/docs/tui.md | 3 +- 5 files changed, 62 insertions(+), 47 deletions(-) diff --git a/src/cmd/project_runner.go b/src/cmd/project_runner.go index 15a3fa3f..877cdee6 100644 --- a/src/cmd/project_runner.go +++ b/src/cmd/project_runner.go @@ -82,16 +82,17 @@ func runTui(project *app.ProjectRunner) error { } func startTui(runner app.IProject, isAsync bool) { + if !*pcFlags.IsReadOnlyMode { + config.CreateProcCompHome() + } + settings := config.NewSettings().Load() tuiOptions := []tui.Option{ tui.WithRefreshRate(*pcFlags.RefreshRate), tui.WithReadOnlyMode(*pcFlags.IsReadOnlyMode), tui.WithFullScreen(*pcFlags.IsTuiFullScreen), tui.WithDisabledHidden(*pcFlags.HideDisabled), + tui.WithDisabledExitConfirm(settings.DisableExitConfirmation), } - if !*pcFlags.IsReadOnlyMode { - config.CreateProcCompHome() - } - settings := config.NewSettings().Load() tuiOptions = append(tuiOptions, ternary(pcFlags.PcThemeChanged, tui.WithTheme(*pcFlags.PcTheme), tui.WithTheme(settings.Theme))) diff --git a/src/config/settings.go b/src/config/settings.go index 2233dcdd..c8888704 100644 --- a/src/config/settings.go +++ b/src/config/settings.go @@ -12,8 +12,9 @@ type ( IsReversed bool `yaml:"isReversed"` } Settings struct { - Theme string `yaml:"theme"` - Sort Sort `yaml:"sort"` + Theme string `yaml:"theme"` + Sort Sort `yaml:"sort"` + DisableExitConfirmation bool `yaml:"disable_exit_confirmation"` } ) diff --git a/src/tui/tui_option.go b/src/tui/tui_option.go index ac3c1871..0cef9539 100644 --- a/src/tui/tui_option.go +++ b/src/tui/tui_option.go @@ -45,3 +45,10 @@ func WithDisabledHidden(isHidden bool) Option { return nil } } + +func WithDisabledExitConfirm(isDisabled bool) Option { + return func(view *pcView) error { + view.isExitConfirmDisabled = isDisabled + return nil + } +} diff --git a/src/tui/view.go b/src/tui/view.go index 7e6276ab..28cbdf70 100644 --- a/src/tui/view.go +++ b/src/tui/view.go @@ -47,46 +47,47 @@ const shutDownAfterSec = 10 var pcv *pcView type pcView struct { - procTable *tview.Table - statTable *tview.Table - appView *tview.Application - logsText *LogView - statusText *tview.TextView - helpText *tview.TextView - pages *tview.Pages - procNames []string - logFollow bool - logSelect bool - scrSplitState scrSplitState - loggedProc string - shortcuts *ShortCuts - procCountCell *tview.TableCell - procMemCpuCell *tview.TableCell - mainGrid *tview.Grid - logsTextArea *tview.TextArea - project app.IProject - sortMtx sync.Mutex - stateSorter StateSorter - procRegex *regexp.Regexp - procRegexMtx sync.Mutex - procColumns map[ColumnID]string - refreshRate time.Duration - cancelFn context.CancelFunc - cancelLogFn context.CancelFunc - cancelSigFn context.CancelFunc - ctxApp context.Context - cancelAppFn context.CancelFunc - selectedNsMtx sync.Mutex - selectedNs string - selectedNsChanged atomic.Bool - hideDisabled atomic.Bool - commandModeType commandType - styles *config.Styles - themes *config.Themes - helpDialog *helpDialog - settings *config.Settings - isFullScreen bool - isReadOnlyMode bool + procTable *tview.Table + statTable *tview.Table + appView *tview.Application + logsText *LogView + statusText *tview.TextView + helpText *tview.TextView + pages *tview.Pages + procNames []string + logFollow bool + logSelect bool + scrSplitState scrSplitState + loggedProc string + shortcuts *ShortCuts + procCountCell *tview.TableCell + procMemCpuCell *tview.TableCell + mainGrid *tview.Grid + logsTextArea *tview.TextArea + project app.IProject + sortMtx sync.Mutex + stateSorter StateSorter + procRegex *regexp.Regexp + procRegexMtx sync.Mutex + procColumns map[ColumnID]string + refreshRate time.Duration + cancelFn context.CancelFunc + cancelLogFn context.CancelFunc + cancelSigFn context.CancelFunc + ctxApp context.Context + cancelAppFn context.CancelFunc + selectedNsMtx sync.Mutex + selectedNs string + selectedNsChanged atomic.Bool + hideDisabled atomic.Bool + commandModeType commandType + styles *config.Styles + themes *config.Themes + helpDialog *helpDialog + settings *config.Settings + isFullScreen bool + isReadOnlyMode bool + isExitConfirmDisabled bool } func newPcView(project app.IProject) *pcView { @@ -337,6 +338,10 @@ func (pv *pcView) terminateAppView() { if pv.project.IsRemote() { result = "" } + if pv.isExitConfirmDisabled { + go pv.handleShutDown() + return + } m := tview.NewModal(). SetText("Are you sure you want to quit?\n" + result). AddButtons([]string{"Quit", "Cancel"}). diff --git a/www/docs/tui.md b/www/docs/tui.md index 1ad248ab..e34f2847 100644 --- a/www/docs/tui.md +++ b/www/docs/tui.md @@ -170,7 +170,7 @@ style: ## TUI State Settings -TUI will automatically save its state when the after changing the following: +TUI will automatically save its state after changing the following: 1. TUI Theme 2. Processes sort column @@ -187,6 +187,7 @@ theme: Cobalt sort: by: NAME isReversed: false +disable_exit_confirmation: false # if true, will disable the TUI exit confirmation dialog ``` > :bulb: The auto save feature can be disabled by using the `--read-only` flag.