mirror of
https://github.com/cheat/cheat.git
synced 2024-11-21 21:41:35 +01:00
fix: config fixes for Windows
- Update the default config file to use `more` instead of `less` as the default pager, in order to support Windows out-of-the-box. (#655, #665). - Use `terminal` Chroma formatter (rather than `terminal16m`) in order to accommodate less capable terminal emulators like `cmd.exe` by default. Similarly, default to `colorize: false` in configs (changed from `true`) (#665). - Comment out default `style` in order to avoid printing ANSI color codes into terminals without color support (#665) - Attempt to intelligently choose a default editor, rather than rely on a hard-coded `vim` in the configs. This should make it easier to use `cheat` immediately without needing to specify configs. It should also improve `cheat`'s Windows compatibility. (#665)
This commit is contained in:
parent
a8c2c396ed
commit
e6f12147df
@ -9,22 +9,23 @@ import (
|
||||
func configs() string {
|
||||
return strings.TrimSpace(`---
|
||||
# The editor to use with 'cheat -e <sheet>'. Defaults to $EDITOR or $VISUAL.
|
||||
editor: vim
|
||||
# editor: vim
|
||||
|
||||
# Should 'cheat' always colorize output?
|
||||
colorize: true
|
||||
colorize: false
|
||||
|
||||
# Which 'chroma' colorscheme should be applied to the output?
|
||||
# Options are available here:
|
||||
# https://github.com/alecthomas/chroma/tree/master/styles
|
||||
style: monokai
|
||||
# style: monokai
|
||||
|
||||
# Which 'chroma' "formatter" should be applied?
|
||||
# One of: "terminal", "terminal256", "terminal16m"
|
||||
formatter: terminal16m
|
||||
formatter: terminal
|
||||
|
||||
# Through which pager should output be piped? (Unset this key for no pager.)
|
||||
pager: less -FRX
|
||||
pager: more
|
||||
# pager: less -FRX # <- recommended where available
|
||||
|
||||
# The paths at which cheatsheets are available. Tags associated with a cheatpath
|
||||
# are automatically attached to all cheatsheets residing on that path.
|
||||
|
@ -1,21 +1,22 @@
|
||||
---
|
||||
# The editor to use with 'cheat -e <sheet>'. Defaults to $EDITOR or $VISUAL.
|
||||
editor: vim
|
||||
# editor: vim
|
||||
|
||||
# Should 'cheat' always colorize output?
|
||||
colorize: true
|
||||
colorize: false
|
||||
|
||||
# Which 'chroma' colorscheme should be applied to the output?
|
||||
# Options are available here:
|
||||
# https://github.com/alecthomas/chroma/tree/master/styles
|
||||
style: monokai
|
||||
# style: monokai
|
||||
|
||||
# Which 'chroma' "formatter" should be applied?
|
||||
# One of: "terminal", "terminal256", "terminal16m"
|
||||
formatter: terminal16m
|
||||
formatter: terminal
|
||||
|
||||
# Through which pager should output be piped? (Unset this key for no pager.)
|
||||
pager: less -FRX
|
||||
pager: more
|
||||
# pager: less -FRX # <- recommended where available
|
||||
|
||||
# The paths at which cheatsheets are available. Tags associated with a cheatpath
|
||||
# are automatically attached to all cheatsheets residing on that path.
|
||||
|
@ -4,7 +4,9 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
cp "github.com/cheat/cheat/internal/cheatpath"
|
||||
@ -98,8 +100,22 @@ func New(opts map[string]interface{}, confPath string, resolve bool) (Config, er
|
||||
conf.Editor = os.Getenv("VISUAL")
|
||||
} else if os.Getenv("EDITOR") != "" {
|
||||
conf.Editor = os.Getenv("EDITOR")
|
||||
} else if runtime.GOOS == "windows" {
|
||||
conf.Editor = "notepad"
|
||||
} else {
|
||||
return Config{}, fmt.Errorf("no editor set")
|
||||
// try to fall back to `nano`
|
||||
path, err := exec.LookPath("nano")
|
||||
if err != nil {
|
||||
return Config{}, fmt.Errorf("failed to locate nano: %s", err)
|
||||
}
|
||||
|
||||
// use `nano` if we found it
|
||||
if path != "" {
|
||||
conf.Editor = "nano"
|
||||
// otherwise, give up
|
||||
} else {
|
||||
return Config{}, fmt.Errorf("no editor set")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,12 +126,13 @@ func New(opts map[string]interface{}, confPath string, resolve bool) (Config, er
|
||||
|
||||
// if a chroma formatter was not provided, set a default
|
||||
if conf.Formatter == "" {
|
||||
conf.Formatter = "terminal16m"
|
||||
conf.Formatter = "terminal"
|
||||
}
|
||||
|
||||
// if a pager was not provided, set a default
|
||||
if strings.TrimSpace(conf.Pager) == "" {
|
||||
conf.Pager = ""
|
||||
// attempt to fall back to `PAGER` if a pager is not specified in configs
|
||||
conf.Pager = strings.TrimSpace(conf.Pager)
|
||||
if conf.Pager == "" && os.Getenv("PAGER") != "" {
|
||||
conf.Pager = os.Getenv("PAGER")
|
||||
}
|
||||
|
||||
return conf, nil
|
||||
|
@ -85,8 +85,8 @@ func TestEmptyEditor(t *testing.T) {
|
||||
|
||||
// initialize a config
|
||||
conf, err := New(map[string]interface{}{}, mock.Path("conf/empty.yml"), false)
|
||||
if err == nil {
|
||||
t.Errorf("failed to return an error on empty editor")
|
||||
if err != nil {
|
||||
t.Errorf("failed to initialize test: %v", err)
|
||||
}
|
||||
|
||||
// set editor, and assert that it is respected
|
||||
|
Loading…
Reference in New Issue
Block a user