1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-15 00:15:32 +02:00

Add screen-mode command line argument (#4103)

Introduce a new "screen-mode" command line argument (`-sm
normal|half|full` / `--screen-mode normal|half|full`) 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.

- **PR Description**

- **Please check if the PR fulfills these requirements**

* [x] Cheatsheets are up-to-date (run `go generate ./...`)
* [x] Code has been formatted (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting))
* [ ] Tests have been added/updated (see
[here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md)
for the integration test guide)
* [ ] Text is internationalised (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation))
* [ ] If a new UserConfig entry was added, make sure it can be
hot-reloaded (see
[here](https://github.com/jesseduffield/lazygit/blob/master/docs/dev/Codebase_Guide.md#using-userconfig))
* [ ] Docs have been updated if necessary
* [x] You've read through your own file changes for silly mistakes etc

<!--
Be sure to name your PR with an imperative e.g. 'Add worktrees view'
see https://github.com/jesseduffield/lazygit/releases/tag/v0.40.0 for
examples
-->
This commit is contained in:
Jesse Duffield
2025-01-02 16:09:09 +11:00
committed by GitHub
3 changed files with 30 additions and 18 deletions

View File

@ -29,16 +29,17 @@ type cliArgs struct {
RepoPath string RepoPath string
FilterPath string FilterPath string
GitArg string GitArg string
UseConfigDir string
WorkTree string
GitDir string
CustomConfigFile string
ScreenMode string
PrintVersionInfo bool PrintVersionInfo bool
Debug bool Debug bool
TailLogs bool TailLogs bool
Profile bool Profile bool
PrintDefaultConfig bool PrintDefaultConfig bool
PrintConfigDir bool PrintConfigDir bool
UseConfigDir string
WorkTree string
GitDir string
CustomConfigFile string
} }
type BuildInfo struct { type BuildInfo struct {
@ -164,7 +165,7 @@ func Start(buildInfo *BuildInfo, integrationTest integrationTypes.IntegrationTes
parsedGitArg := parseGitArg(cliArgs.GitArg) parsedGitArg := parseGitArg(cliArgs.GitArg)
Run(appConfig, common, appTypes.NewStartArgs(cliArgs.FilterPath, parsedGitArg, integrationTest)) Run(appConfig, common, appTypes.NewStartArgs(cliArgs.FilterPath, parsedGitArg, cliArgs.ScreenMode, integrationTest))
} }
func parseCliArgsAndEnvVars() *cliArgs { func parseCliArgsAndEnvVars() *cliArgs {
@ -209,6 +210,9 @@ func parseCliArgsAndEnvVars() *cliArgs {
customConfigFile := "" customConfigFile := ""
flaggy.String(&customConfigFile, "ucf", "use-config-file", "Comma separated list to custom config file(s)") flaggy.String(&customConfigFile, "ucf", "use-config-file", "Comma separated list to custom config file(s)")
screenMode := ""
flaggy.String(&screenMode, "sm", "screen-mode", "The initial screen-mode, which determines the size of the focused panel. Valid options: 'normal' (default), 'half', 'full'")
flaggy.Parse() flaggy.Parse()
if os.Getenv("DEBUG") == "TRUE" { if os.Getenv("DEBUG") == "TRUE" {
@ -229,6 +233,7 @@ func parseCliArgsAndEnvVars() *cliArgs {
WorkTree: workTree, WorkTree: workTree,
GitDir: gitDir, GitDir: gitDir,
CustomConfigFile: customConfigFile, CustomConfigFile: customConfigFile,
ScreenMode: screenMode,
} }
} }

View File

@ -6,12 +6,14 @@ import (
// StartArgs is the struct that represents some things we want to do on program start // StartArgs is the struct that represents some things we want to do on program start
type StartArgs struct { type StartArgs struct {
// FilterPath determines which path we're going to filter on so that we only see commits from that file.
FilterPath string
// GitArg determines what context we open in // GitArg determines what context we open in
GitArg GitArg GitArg GitArg
// integration test (only relevant when invoking lazygit in the context of an integration test) // integration test (only relevant when invoking lazygit in the context of an integration test)
IntegrationTest integrationTypes.IntegrationTest IntegrationTest integrationTypes.IntegrationTest
// FilterPath determines which path we're going to filter on so that we only see commits from that file.
FilterPath string
// ScreenMode determines the initial Screen Mode (normal, half or full) to use
ScreenMode string
} }
type GitArg string type GitArg string
@ -24,10 +26,11 @@ const (
GitArgStash GitArg = "stash" GitArgStash GitArg = "stash"
) )
func NewStartArgs(filterPath string, gitArg GitArg, test integrationTypes.IntegrationTest) StartArgs { func NewStartArgs(filterPath string, gitArg GitArg, screenMode string, test integrationTypes.IntegrationTest) StartArgs {
return StartArgs{ return StartArgs{
FilterPath: filterPath, FilterPath: filterPath,
GitArg: gitArg, GitArg: gitArg,
ScreenMode: screenMode,
IntegrationTest: test, IntegrationTest: test,
} }
} }

View File

@ -580,12 +580,17 @@ func initialWindowViewNameMap(contextTree *context.ContextTree) *utils.ThreadSaf
} }
func initialScreenMode(startArgs appTypes.StartArgs, config config.AppConfigurer) types.WindowMaximisation { func initialScreenMode(startArgs appTypes.StartArgs, config config.AppConfigurer) types.WindowMaximisation {
if startArgs.FilterPath != "" || startArgs.GitArg != appTypes.GitArgNone { if startArgs.ScreenMode != "" {
return getWindowMaximisation(startArgs.ScreenMode)
} else if startArgs.FilterPath != "" || startArgs.GitArg != appTypes.GitArgNone {
return types.SCREEN_FULL return types.SCREEN_FULL
} else { } else {
defaultWindowSize := config.GetUserConfig().Gui.WindowSize return getWindowMaximisation(config.GetUserConfig().Gui.WindowSize)
}
}
switch defaultWindowSize { func getWindowMaximisation(modeString string) types.WindowMaximisation {
switch modeString {
case "half": case "half":
return types.SCREEN_HALF return types.SCREEN_HALF
case "full": case "full":
@ -593,7 +598,6 @@ func initialScreenMode(startArgs appTypes.StartArgs, config config.AppConfigurer
default: default:
return types.SCREEN_NORMAL return types.SCREEN_NORMAL
} }
}
} }
func initialContext(contextTree *context.ContextTree, startArgs appTypes.StartArgs) types.IListContext { func initialContext(contextTree *context.ContextTree, startArgs appTypes.StartArgs) types.IListContext {