feat(pagination): implement paginated output

Implement a `pager` config option. If configured, `cheat` will
automatically pipe output through the configured pager (where
appropriate).
This commit is contained in:
Chris Lane
2020-06-25 18:21:51 -04:00
parent 8e602b0e93
commit 59d5c96c24
9 changed files with 78 additions and 10 deletions

View File

@ -5,6 +5,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
cp "github.com/cheat/cheat/internal/cheatpath"
@ -19,6 +20,7 @@ type Config struct {
Cheatpaths []cp.Cheatpath `yaml:"cheatpaths"`
Style string `yaml:"style"`
Formatter string `yaml:"formatter"`
Pager string `yaml:"pager"`
}
// New returns a new Config struct
@ -111,5 +113,10 @@ func New(opts map[string]interface{}, confPath string, resolve bool) (Config, er
conf.Formatter = "terminal16m"
}
// if a pager was not provided, set a default
if strings.TrimSpace(conf.Pager) == "" {
conf.Pager = ""
}
return conf, nil
}