mirror of
https://github.com/cheat/cheat.git
synced 2026-03-07 11:13:33 +01:00
fix(Config): colorization without pager (#687)
Fix an issue whereby colorization would output ANSI codes if a pager was not configured. The solution here is to stop guessing about the state of the user's system at runtime, as well as the user's intention. The installer now chooses an appropriate installer when generating configs, and no longer bothers searching for pagers at runtime.
This commit is contained in:
26
internal/config/pager.go
Normal file
26
internal/config/pager.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// Pager attempts to locate a pager that's appropriate for the environment.
|
||||
func Pager() string {
|
||||
|
||||
// if $PAGER is set, return the corresponding pager
|
||||
if os.Getenv("PAGER") != "" {
|
||||
return os.Getenv("PAGER")
|
||||
}
|
||||
|
||||
// Otherwise, search for `pager`, `less`, and `more` on the `$PATH`. If
|
||||
// none are found, return an empty pager.
|
||||
for _, pager := range []string{"pager", "less", "more"} {
|
||||
if path, err := exec.LookPath(pager); err != nil {
|
||||
return path
|
||||
}
|
||||
}
|
||||
|
||||
// default to no pager
|
||||
return ""
|
||||
}
|
||||
Reference in New Issue
Block a user