Skip to content

Commit f2109a4

Browse files
alewis001jesseduffield
authored andcommitted
Add screen-mode command line argument
Introduce a new "screen-mode" command line argument that allows a user to specify which screen mode (normal, half or full) Lazygit should use when it runs. This argument will take precedence over a default Window Size specified in user config.
1 parent 3573289 commit f2109a4

File tree

3 files changed

+30
-18
lines changed

3 files changed

+30
-18
lines changed

pkg/app/entry_point.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,17 @@ type cliArgs struct {
2929
RepoPath string
3030
FilterPath string
3131
GitArg string
32+
UseConfigDir string
33+
WorkTree string
34+
GitDir string
35+
CustomConfigFile string
36+
ScreenMode string
3237
PrintVersionInfo bool
3338
Debug bool
3439
TailLogs bool
3540
Profile bool
3641
PrintDefaultConfig bool
3742
PrintConfigDir bool
38-
UseConfigDir string
39-
WorkTree string
40-
GitDir string
41-
CustomConfigFile string
4243
}
4344

4445
type BuildInfo struct {
@@ -164,7 +165,7 @@ func Start(buildInfo *BuildInfo, integrationTest integrationTypes.IntegrationTes
164165

165166
parsedGitArg := parseGitArg(cliArgs.GitArg)
166167

167-
Run(appConfig, common, appTypes.NewStartArgs(cliArgs.FilterPath, parsedGitArg, integrationTest))
168+
Run(appConfig, common, appTypes.NewStartArgs(cliArgs.FilterPath, parsedGitArg, cliArgs.ScreenMode, integrationTest))
168169
}
169170

170171
func parseCliArgsAndEnvVars() *cliArgs {
@@ -209,6 +210,9 @@ func parseCliArgsAndEnvVars() *cliArgs {
209210
customConfigFile := ""
210211
flaggy.String(&customConfigFile, "ucf", "use-config-file", "Comma separated list to custom config file(s)")
211212

213+
screenMode := ""
214+
flaggy.String(&screenMode, "sm", "screen-mode", "The initial screen-mode, which determines the size of the focused panel. Valid options: 'normal' (default), 'half', 'full'")
215+
212216
flaggy.Parse()
213217

214218
if os.Getenv("DEBUG") == "TRUE" {
@@ -229,6 +233,7 @@ func parseCliArgsAndEnvVars() *cliArgs {
229233
WorkTree: workTree,
230234
GitDir: gitDir,
231235
CustomConfigFile: customConfigFile,
236+
ScreenMode: screenMode,
232237
}
233238
}
234239

pkg/app/types/types.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import (
66

77
// StartArgs is the struct that represents some things we want to do on program start
88
type StartArgs struct {
9-
// FilterPath determines which path we're going to filter on so that we only see commits from that file.
10-
FilterPath string
119
// GitArg determines what context we open in
1210
GitArg GitArg
1311
// integration test (only relevant when invoking lazygit in the context of an integration test)
1412
IntegrationTest integrationTypes.IntegrationTest
13+
// FilterPath determines which path we're going to filter on so that we only see commits from that file.
14+
FilterPath string
15+
// ScreenMode determines the initial Screen Mode (normal, half or full) to use
16+
ScreenMode string
1517
}
1618

1719
type GitArg string
@@ -24,10 +26,11 @@ const (
2426
GitArgStash GitArg = "stash"
2527
)
2628

27-
func NewStartArgs(filterPath string, gitArg GitArg, test integrationTypes.IntegrationTest) StartArgs {
29+
func NewStartArgs(filterPath string, gitArg GitArg, screenMode string, test integrationTypes.IntegrationTest) StartArgs {
2830
return StartArgs{
2931
FilterPath: filterPath,
3032
GitArg: gitArg,
33+
ScreenMode: screenMode,
3134
IntegrationTest: test,
3235
}
3336
}

pkg/gui/gui.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -580,19 +580,23 @@ func initialWindowViewNameMap(contextTree *context.ContextTree) *utils.ThreadSaf
580580
}
581581

582582
func initialScreenMode(startArgs appTypes.StartArgs, config config.AppConfigurer) types.WindowMaximisation {
583-
if startArgs.FilterPath != "" || startArgs.GitArg != appTypes.GitArgNone {
583+
if startArgs.ScreenMode != "" {
584+
return getWindowMaximisation(startArgs.ScreenMode)
585+
} else if startArgs.FilterPath != "" || startArgs.GitArg != appTypes.GitArgNone {
584586
return types.SCREEN_FULL
585587
} else {
586-
defaultWindowSize := config.GetUserConfig().Gui.WindowSize
588+
return getWindowMaximisation(config.GetUserConfig().Gui.WindowSize)
589+
}
590+
}
587591

588-
switch defaultWindowSize {
589-
case "half":
590-
return types.SCREEN_HALF
591-
case "full":
592-
return types.SCREEN_FULL
593-
default:
594-
return types.SCREEN_NORMAL
595-
}
592+
func getWindowMaximisation(modeString string) types.WindowMaximisation {
593+
switch modeString {
594+
case "half":
595+
return types.SCREEN_HALF
596+
case "full":
597+
return types.SCREEN_FULL
598+
default:
599+
return types.SCREEN_NORMAL
596600
}
597601
}
598602

0 commit comments

Comments
 (0)