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:
Christopher Allen Lane
2022-08-07 10:16:52 -04:00
parent 4fdec50487
commit d598d96fce
6 changed files with 68 additions and 57 deletions

30
internal/config/editor.go Normal file
View File

@@ -0,0 +1,30 @@
package config
import (
"fmt"
"os"
"os/exec"
"runtime"
)
// Editor attempts to locate an editor that's appropriate for the environment.
func Editor() (string, error) {
// default to `notepad.exe` on Windows
if runtime.GOOS == "windows" {
return "notepad", nil
}
// look for `nano` on the `PATH`
nano, _ := exec.LookPath("nano")
// search for `$VISUAL`, `$EDITOR`, and then `nano`, in that order
for _, editor := range []string{os.Getenv("VISUAL"), os.Getenv("EDITOR"), nano} {
if editor != "" {
return editor, nil
}
}
// return an error if no path is found
return "", fmt.Errorf("no editor set")
}