diff options
author | Tau <git@tau.garden> | 2024-03-23 16:39:37 +0100 |
---|---|---|
committer | Stefan Haller <stefan@haller-berlin.de> | 2024-03-23 23:46:37 +0100 |
commit | f30be824b3655492a54a99b38b7d6ad8805e85e1 (patch) | |
tree | 65bd182497bcb3137932ef0a4a9a4cf7fc50d21a | |
parent | e1c3ef66295bf949de5e7781c0a60ac7f79c47ce (diff) |
Set the `TERM` env variable
This communicates to pagers that we're in a very simple
terminal that they should not expect to have much capabilities.
See #3419
-rw-r--r-- | pkg/gui/pty.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/pkg/gui/pty.go b/pkg/gui/pty.go index 3f59373b7..cf3176f75 100644 --- a/pkg/gui/pty.go +++ b/pkg/gui/pty.go @@ -12,6 +12,7 @@ import ( "github.com/creack/pty" "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/utils" + "github.com/samber/lo" ) func (gui *Gui) desiredPtySize() *pty.Winsize { @@ -54,6 +55,13 @@ func (gui *Gui) newPtyTask(view *gocui.View, cmd *exec.Cmd, prefix string) error cmdStr := strings.Join(cmd.Args, " ") + // This communicates to pagers that we're in a very simple + // terminal that they should not expect to have much capabilities. + // Moving the cursor, clearing the screen, or querying for colors are among such "advanced" capabilities. + // Context: https://github.com/jesseduffield/lazygit/issues/3419 + cmd.Env = removeExistingTermEnvVars(cmd.Env) + cmd.Env = append(cmd.Env, "TERM=dumb") + cmd.Env = append(cmd.Env, "GIT_PAGER="+pager) manager := gui.getManager(view) @@ -87,3 +95,20 @@ func (gui *Gui) newPtyTask(view *gocui.View, cmd *exec.Cmd, prefix string) error return nil } + +func removeExistingTermEnvVars(env []string) []string { + return lo.Filter(env, func(envVar string, _ int) bool { + return !isTermEnvVar(envVar) + }) +} + +// Terminals set a variety of different environment variables +// to identify themselves to processes. This list should catch the most common among them. +func isTermEnvVar(envVar string) bool { + return strings.HasPrefix(envVar, "TERM=") || + strings.HasPrefix(envVar, "TERM_PROGRAM=") || + strings.HasPrefix(envVar, "TERM_PROGRAM_VERSION=") || + strings.HasPrefix(envVar, "TERMINAL_EMULATOR=") || + strings.HasPrefix(envVar, "TERMINAL_NAME=") || + strings.HasPrefix(envVar, "TERMINAL_VERSION_") +} |