From a8bfa115fb7186643258d1d654b770c9773bff4a Mon Sep 17 00:00:00 2001 From: tjp Date: Fri, 5 Jan 2024 10:02:07 -0700 Subject: auto_pager bool to pager string always/auto/never --- actions.go | 15 +++++++++++---- files.go | 4 ++-- help.go | 7 ++++--- main.go | 2 +- state.go | 2 +- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/actions.go b/actions.go index 08838a8..09e6a07 100644 --- a/actions.go +++ b/actions.go @@ -440,20 +440,27 @@ func print(state *BrowserState) error { out = state.Modal } - if state.AutoPager { + lessarg := []string{} + switch state.Pager { + case "auto": + lessarg = []string{"-F"} + fallthrough + case "always": less, err := exec.LookPath("less") if err != nil { return err } - cmd := exec.Command(less, "-F") + cmd := exec.Command(less, lessarg...) cmd.Stdin = bytes.NewBuffer(out) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr return cmd.Run() + case "never": + _, err := os.Stdout.Write(out) + return err } - _, err := os.Stdout.Write(out) - return err + return errors.New("invalid 'pager' value in configuration") } func Print(state *BrowserState) error { diff --git a/files.go b/files.go index 05c04cc..e0c822c 100644 --- a/files.go +++ b/files.go @@ -19,7 +19,7 @@ type ConfigMain struct { DownloadFolder string `toml:"download_folder"` VimKeys bool `toml:"vim_keys"` Quiet bool `toml:"quiet"` - AutoPager bool `toml:"auto_pager"` + Pager string `toml:"pager"` } type Config struct { @@ -45,7 +45,7 @@ func getConfig() (*Config, error) { SoftWrap: 80, DownloadFolder: home, Quiet: false, - AutoPager: true, + Pager: "auto", }, } if _, err := toml.DecodeFile(path, &c); err != nil { diff --git a/help.go b/help.go index ab36c7d..f402ec9 100644 --- a/help.go +++ b/help.go @@ -99,9 +99,10 @@ The section "[main]" contains general configuration options: stands in for $HOME. The default is "~" (the user's home directory). * quiet (boolean): Disables automatically printing the page after any navigation action. The default is false. - * auto_pager (boolean): Sends pages through "less -F", where the -F - switch disables the pager if the output fits in a single screen. - This is true by default. + * pager (string): Set this to "always", "never", or "auto". "always" + will pipe every page printed through less(1), "never" will not, and + "auto" will pipe it through "less -F", which skips the pager when + the output fits on a single screen anyway. `[1:], diff --git a/main.go b/main.go index 97cce21..a303485 100644 --- a/main.go +++ b/main.go @@ -17,7 +17,7 @@ func main() { state := NewBrowserState() state.Quiet = conf.Quiet - state.AutoPager = conf.AutoPager + state.Pager = conf.Pager rl, err := readline.New(Prompt) if err != nil { diff --git a/state.go b/state.go index feeff53..6a6c885 100644 --- a/state.go +++ b/state.go @@ -18,7 +18,7 @@ type BrowserState struct { CurrentTour *Tour Quiet bool - AutoPager bool + Pager string Readline *readline.Instance } -- cgit v1.2.3