Skip to content

Commit

Permalink
feat #194: Added flag and env to start with full screen
Browse files Browse the repository at this point in the history
  • Loading branch information
F1bonacc1 committed Aug 9, 2024
1 parent 4ce8ac7 commit 5c83437
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/cmd/project_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ func runTui(project *app.ProjectRunner) error {
func startTui(runner app.IProject) {
tuiOptions := []tui.Option{
tui.WithRefreshRate(*pcFlags.RefreshRate),
tui.WithReadOnlyMode(*pcFlags.IsReadOnlyMode),
tui.WithFullScreen(*pcFlags.IsTuiFullScreen),
}
if !*pcFlags.IsReadOnlyMode {
config.CreateProcCompHome()
Expand All @@ -101,7 +103,7 @@ func startTui(runner app.IProject) {
ternary(pcFlags.SortColumnChanged,
tui.WithStateSorter(getColumnId(*pcFlags.SortColumn), !*pcFlags.IsReverseSort),
tui.WithStateSorter(getColumnId(settings.Sort.By), !settings.Sort.IsReversed)),
tui.WithReadOnlyMode(*pcFlags.IsReadOnlyMode))
)

tui.SetupTui(runner, tuiOptions...)
}
Expand Down
1 change: 1 addition & 0 deletions src/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func init() {
rootCmd.PersistentFlags().StringVarP(pcFlags.LogFile, "log-file", "L", *pcFlags.LogFile, "Specify the log file path (env: "+config.LogPathEnvVarName+")")
rootCmd.PersistentFlags().BoolVar(pcFlags.IsReadOnlyMode, "read-only", *pcFlags.IsReadOnlyMode, "enable read-only mode (env: "+config.EnvVarReadOnlyMode+")")
rootCmd.Flags().BoolVar(pcFlags.DisableDotEnv, "disable-dotenv", *pcFlags.DisableDotEnv, "disable .env file loading (env: "+config.EnvVarDisableDotEnv+"=1)")
rootCmd.Flags().BoolVar(pcFlags.IsTuiFullScreen, "tui-fs", *pcFlags.IsTuiFullScreen, "enable TUI full screen (env: "+config.EnvVarTuiFullScreen+"=1)")
rootCmd.Flags().AddFlag(commonFlags.Lookup(flagReverse))
rootCmd.Flags().AddFlag(commonFlags.Lookup(flagSort))
rootCmd.Flags().AddFlag(commonFlags.Lookup(flagTheme))
Expand Down
3 changes: 3 additions & 0 deletions src/config/Flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const (
EnvVarUnixSocketPath = "PC_SOCKET_PATH"
EnvVarReadOnlyMode = "PC_READ_ONLY"
EnvVarDisableDotEnv = "PC_DISABLE_DOTENV"
EnvVarTuiFullScreen = "PC_TUI_FULL_SCREEN"
)

// Flags represents PC configuration flags.
Expand Down Expand Up @@ -66,6 +67,7 @@ type Flags struct {
IsReadOnlyMode *bool
OutputFormat *string
DisableDotEnv *bool
IsTuiFullScreen *bool
}

// NewFlags returns new configuration flags.
Expand Down Expand Up @@ -93,6 +95,7 @@ func NewFlags() *Flags {
IsReadOnlyMode: toPtr(getReadOnlyDefault()),
OutputFormat: toPtr(""),
DisableDotEnv: toPtr(getDisableDotEnvDefault()),
IsTuiFullScreen: toPtr(getTuiFullScreenDefault()),
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,8 @@ func getDisableDotEnvDefault() bool {
_, found := os.LookupEnv(EnvVarDisableDotEnv)
return found
}

func getTuiFullScreenDefault() bool {
_, found := os.LookupEnv(EnvVarTuiFullScreen)
return found
}
7 changes: 7 additions & 0 deletions src/tui/tui_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,10 @@ func WithReadOnlyMode(isReadOnly bool) Option {
return nil
}
}

func WithFullScreen(isFullScreen bool) Option {
return func(view *pcView) error {
view.setFullScreen(isFullScreen)
return nil
}
}
10 changes: 7 additions & 3 deletions src/tui/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,7 @@ func (pv *pcView) setShortCutsActions() {
pv.shortcuts.setAction(ActionThemeSelector, pv.showThemeSelector)
pv.shortcuts.setAction(ActionSendToBackground, pv.runShellProcess)
pv.shortcuts.setAction(ActionFullScreen, func() {
pv.isFullScreen = !pv.isFullScreen
pv.logsText.SetBorder(!pv.isFullScreen)
pv.redrawGrid()
pv.setFullScreen(!pv.isFullScreen)
})
pv.shortcuts.setAction(ActionFocusChange, pv.changeFocus)
pv.shortcuts.setAction(ActionProcFilter, func() {
Expand All @@ -237,6 +235,12 @@ func (pv *pcView) setShortCutsActions() {
})
}

func (pv *pcView) setFullScreen(isFullScreen bool) {
pv.isFullScreen = isFullScreen
pv.logsText.SetBorder(!pv.isFullScreen)
pv.redrawGrid()
}

func (pv *pcView) loadThemes() {
pv.themes.AddListener(pv)
pv.themes.AddListener(pv.helpDialog)
Expand Down

0 comments on commit 5c83437

Please sign in to comment.