Skip to content

Commit

Permalink
feat #268: Added setting to disable the exit confirmation in TUI
Browse files Browse the repository at this point in the history
  • Loading branch information
F1bonacc1 committed Nov 9, 2024
1 parent dd2cb88 commit 9bb8297
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 47 deletions.
9 changes: 5 additions & 4 deletions src/cmd/project_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
5 changes: 3 additions & 2 deletions src/config/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
)

Expand Down
7 changes: 7 additions & 0 deletions src/tui/tui_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
85 changes: 45 additions & 40 deletions src/tui/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"}).
Expand Down
3 changes: 2 additions & 1 deletion www/docs/tui.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.

0 comments on commit 9bb8297

Please sign in to comment.