diff options
author | Stefan Haller <stefan@haller-berlin.de> | 2024-03-23 23:49:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-23 23:49:22 +0100 |
commit | fb675b79f8a4a949294e8cab85ce72fed3883362 (patch) | |
tree | 65bd182497bcb3137932ef0a4a9a4cf7fc50d21a | |
parent | e1c3ef66295bf949de5e7781c0a60ac7f79c47ce (diff) | |
parent | f30be824b3655492a54a99b38b7d6ad8805e85e1 (diff) |
Set the `TERM` env variable (#3420)
Resolves #3419
I have tested this change with all the pagers shown in [the
docs](https://github.com/jesseduffield/lazygit/blob/master/docs/Custom_Pagers.md).
Are there others that people frequently use and I should test?
A nice side effect of setting `TERM=dumb` is that `less` now correctly
complains (e.g. when forgetting to set `--paging=never` for delta:
![image](https://github.com/jesseduffield/lazygit/assets/4602612/33e9c048-6ab0-4196-95f6-86ee8effc873)
## Pagers Tested
### none
![image](https://github.com/jesseduffield/lazygit/assets/4602612/4e408fe6-5f19-4142-9183-de56fd738962)
### Delta
![image](https://github.com/jesseduffield/lazygit/assets/4602612/90dd12fa-ed58-4d49-9f71-da5e57f63a74)
```yaml
git:
paging:
colorArg: always
pager: delta --paging=never
```
#### diff-so-fancy
![image](https://github.com/jesseduffield/lazygit/assets/4602612/930e6b93-904e-49a2-bfc2-9b5d9639f514)
```yaml
git:
paging:
colorArg: always
pager: diff-so-fancy
```
#### ydiff
![image](https://github.com/jesseduffield/lazygit/assets/4602612/c2464f0c-f34f-4ebc-9624-8bc0350d92a7)
```yaml
git:
paging:
colorArg: always
pager: ydiff -p cat
```
#### difft
![image](https://github.com/jesseduffield/lazygit/assets/4602612/599dee7a-6568-40e4-9213-76ba643d651f)
```yaml
git:
paging:
externalDiffCommand: difft --color=always
```
-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_") +} |