From 2eee2b05608cb57051bac5774d03c3c7fc5f110b Mon Sep 17 00:00:00 2001 From: tjp Date: Wed, 3 Jan 2024 20:16:51 -0700 Subject: auto_pager config option --- actions.go | 13 +++++++++++++ files.go | 2 ++ help.go | 12 ++++++++++-- main.go | 1 + state.go | 1 + 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/actions.go b/actions.go index c2dd934..065b673 100644 --- a/actions.go +++ b/actions.go @@ -320,6 +320,19 @@ func print(state *BrowserState) error { if state.Modal != nil { out = state.Modal } + + if state.AutoPager { + less, err := exec.LookPath("less") + if err != nil { + return err + } + cmd := exec.Command(less, "-F") + cmd.Stdin = bytes.NewBuffer(out) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + return cmd.Run() + } + _, err := os.Stdout.Write(out) return err } diff --git a/files.go b/files.go index 842a030..05c04cc 100644 --- a/files.go +++ b/files.go @@ -19,6 +19,7 @@ type ConfigMain struct { DownloadFolder string `toml:"download_folder"` VimKeys bool `toml:"vim_keys"` Quiet bool `toml:"quiet"` + AutoPager bool `toml:"auto_pager"` } type Config struct { @@ -44,6 +45,7 @@ func getConfig() (*Config, error) { SoftWrap: 80, DownloadFolder: home, Quiet: false, + AutoPager: true, }, } if _, err := toml.DecodeFile(path, &c); err != nil { diff --git a/help.go b/help.go index 16fda43..9a72c56 100644 --- a/help.go +++ b/help.go @@ -27,7 +27,7 @@ var helpTopics = map[string]string{ help topics ----------- commands: Basics of x-1 commands, and a full listing of them. Each - command is also its own help topic. + command also has its own help topic. urls: The forms of URLs which can be entered into x-1 commands. mark: Information on the "mark" meta-command. tour: Information about the "tour" meta-command. @@ -96,9 +96,12 @@ The section "[main]" contains general configuration options: link indices. * download_folder (string): The folder in which to store files saved by the "save" command. This string may also start with "~", which - stands in for $HOME. The default is "~" (or $HOME). + 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. `[1:], @@ -213,6 +216,11 @@ Displays the current page. This will happen anyway by default with any navigation action, but the "quiet" configuration option can disable that. + +By default, the print action (whether automatic or upon the print +command) will pipe the output through "less -F", where the -F switch +disables the pager if the output fits in one screen. This can be +disabled with the "auto_pager" configuration option. `[1:], "pipe": ` diff --git a/main.go b/main.go index 2916be7..2e88ce6 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,7 @@ func main() { state := NewBrowserState() state.Quiet = conf.Quiet + state.AutoPager = conf.AutoPager rl, err := readline.New(Prompt) if err != nil { diff --git a/state.go b/state.go index 1ec000d..141fafb 100644 --- a/state.go +++ b/state.go @@ -18,6 +18,7 @@ type BrowserState struct { CurrentTour *Tour Quiet bool + AutoPager bool Readline *readline.Instance } -- cgit v1.2.3