This commit is contained in:
Kovid Goyal 2022-08-15 15:02:58 +05:30
parent 083deec663
commit 63da2e1ec6
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 9 additions and 8 deletions

View File

@ -24,7 +24,7 @@ import (
var RootCmd *cobra.Command
func GetTTYSize() (*unix.Winsize, error) {
if (stdout_is_terminal) {
if stdout_is_terminal {
return unix.IoctlGetWinsize(int(os.Stdout.Fd()), unix.TIOCGWINSZ)
}
return nil, fmt.Errorf("STDOUT is not a TTY")
@ -78,7 +78,6 @@ var yellow_fmt = color.New(color.FgYellow).SprintFunc()
var blue_fmt = color.New(color.FgBlue).SprintFunc()
var green_fmt = color.New(color.FgGreen).SprintFunc()
func format_line_with_indent(output io.Writer, text string, indent string, screen_width int) {
x := len(indent)
fmt.Fprint(output, indent)
@ -105,9 +104,11 @@ func format_line_with_indent(output io.Writer, text string, indent string, scree
for i, r := range text {
if in_escape > 0 {
if (in_escape == 1 && (r == ']' || r == '[')) {
if in_escape == 1 && (r == ']' || r == '[') {
in_escape = 2
if (r == ']') { in_escape = 3 }
if r == ']' {
in_escape = 3
}
}
if (in_escape == 2 && r == 'm') || (in_escape == 3 && r == '\\' && text[i-1] == 0x1b) {
in_escape = 0
@ -321,9 +322,9 @@ func show_usage(cmd *cobra.Command) error {
} else {
fmt.Fprintln(&output, italic_fmt(RootCmd.Name()), opt_fmt(RootCmd.Version), "created by", title_fmt("Kovid Goyal"))
}
output_text := output.String()
output_text := output.String()
if stdout_is_terminal && cmd.Annotations["allow-pager"] != "no" {
pager := exec.Command(kitty.DefaultPager[0], kitty.DefaultPager[1:]...);
pager := exec.Command(kitty.DefaultPager[0], kitty.DefaultPager[1:]...)
pager.Stdin = strings.NewReader(output_text)
pager.Stdout = os.Stdout
pager.Stderr = os.Stderr
@ -348,7 +349,7 @@ func UsageAndError(cmd *cobra.Command, err string) {
}
func SubCommandRequired(cmd *cobra.Command, args []string) {
UsageAndError(cmd, "No command specified: " + exe_fmt(full_command_name(cmd)) + err_fmt(" add-a-command-here"))
UsageAndError(cmd, "No command specified: "+exe_fmt(full_command_name(cmd))+err_fmt(" add-a-command-here"))
os.Exit(1)
}

View File

@ -56,7 +56,7 @@ func init() {
if matches[1] == "" {
panic(fmt.Errorf("Failed to find the default_pager_for_help"))
}
text := strings.ReplaceAll("[" + matches[1] + "]", "'", "\"")
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)