This commit is contained in:
Kovid Goyal 2022-08-15 14:17:26 +05:30
parent a7f0a471ed
commit 06bd1f5d48
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 16 additions and 2 deletions

View File

@ -323,7 +323,7 @@ func show_usage(cmd *cobra.Command) error {
} }
output_text := output.String() output_text := output.String()
if stdout_is_terminal && cmd.Annotations["allow-pager"] != "no" { if stdout_is_terminal && cmd.Annotations["allow-pager"] != "no" {
pager := exec.Command("less", "-iRXF"); pager := exec.Command(kitty.DefaultPager[0], kitty.DefaultPager[1:]...);
pager.Stdin = strings.NewReader(output_text) pager.Stdin = strings.NewReader(output_text)
pager.Stdout = os.Stdout pager.Stdout = os.Stdout
pager.Stderr = os.Stderr pager.Stderr = os.Stderr

View File

@ -2,10 +2,13 @@ package kitty
import ( import (
_ "embed" _ "embed"
"encoding/json"
"fmt" "fmt"
"os"
"regexp" "regexp"
"runtime/debug" "runtime/debug"
"strconv" "strconv"
"strings"
) )
//go:embed kitty/constants.py //go:embed kitty/constants.py
@ -19,6 +22,7 @@ var VersionString string
var Version VersionType var Version VersionType
var VCSRevision string var VCSRevision string
var WebsiteBaseUrl string var WebsiteBaseUrl string
var DefaultPager []string
func init() { func init() {
verpat := regexp.MustCompile(`Version\((\d+),\s*(\d+),\s*(\d+)\)`) verpat := regexp.MustCompile(`Version\((\d+),\s*(\d+),\s*(\d+)\)`)
@ -47,5 +51,15 @@ func init() {
if matches[1] == "" { if matches[1] == "" {
panic(fmt.Errorf("Failed to find the website base url")) panic(fmt.Errorf("Failed to find the website base url"))
} }
pager_pat := regexp.MustCompile(`default_pager_for_help\s+=\s+\((.+?)\)`)
matches = pager_pat.FindStringSubmatch(raw)
if matches[1] == "" {
panic(fmt.Errorf("Failed to find the default_pager_for_help"))
}
text := strings.ReplaceAll("[" + matches[1] + "]", "'", "\"")
err = json.Unmarshal([]byte(text), &DefaultPager)
if err != nil {
fmt.Fprintln(os.Stderr, "Failed to unmarshal default pager text:", text)
panic(err)
}
} }