Use a pager for the help interactive command as well
This commit is contained in:
parent
5e880b92f5
commit
a4e43b3925
@ -92,6 +92,14 @@ func (self *Command) ShowHelp() {
|
||||
self.ShowHelpWithCommandString(strings.TrimSpace(self.CommandStringForUsage()))
|
||||
}
|
||||
|
||||
func ShowHelpInPager(text string) {
|
||||
pager := exec.Command(kitty.DefaultPager[0], kitty.DefaultPager[1:]...)
|
||||
pager.Stdin = strings.NewReader(text)
|
||||
pager.Stdout = os.Stdout
|
||||
pager.Stderr = os.Stderr
|
||||
pager.Run()
|
||||
}
|
||||
|
||||
func (self *Command) ShowHelpWithCommandString(cs string) {
|
||||
formatter := markup.New(tty.IsTerminal(os.Stdout.Fd()))
|
||||
screen_width := 80
|
||||
@ -144,12 +152,8 @@ func (self *Command) ShowHelpWithCommandString(cs string) {
|
||||
output_text := output.String()
|
||||
// fmt.Printf("%#v\n", output_text)
|
||||
if formatter.EscapeCodesAllowed() {
|
||||
pager := exec.Command(kitty.DefaultPager[0], kitty.DefaultPager[1:]...)
|
||||
pager.Stdin = strings.NewReader(output_text)
|
||||
pager.Stdout = os.Stdout
|
||||
pager.Stderr = os.Stderr
|
||||
pager.Run()
|
||||
ShowHelpInPager(output_text)
|
||||
} else {
|
||||
os.Stdout.Write([]byte(output_text))
|
||||
os.Stdout.WriteString(output_text)
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,19 +96,21 @@ func shell_loop(rl *readline.Readline, kill_if_signaled bool) (int, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func print_basic_help() {
|
||||
fmt.Println("Control kitty by sending it commands.")
|
||||
fmt.Println()
|
||||
fmt.Println(formatter.Title("Commands") + ":")
|
||||
func show_basic_help() {
|
||||
output := strings.Builder{}
|
||||
fmt.Fprintln(&output, "Control kitty by sending it commands.")
|
||||
fmt.Fprintln(&output)
|
||||
fmt.Fprintln(&output, formatter.Title("Commands")+":")
|
||||
r := EntryPoint(cli.NewRootCommand())
|
||||
for _, g := range r.SubCommandGroups {
|
||||
for _, sc := range g.SubCommands {
|
||||
fmt.Println(" ", formatter.Green(sc.Name))
|
||||
fmt.Println(" ", sc.ShortDescription)
|
||||
fmt.Fprintln(&output, " ", formatter.Green(sc.Name))
|
||||
fmt.Fprintln(&output, " ", sc.ShortDescription)
|
||||
}
|
||||
}
|
||||
fmt.Println(" ", formatter.Green("exit"))
|
||||
fmt.Println(" ", "Exit this shell")
|
||||
fmt.Fprintln(&output, " ", formatter.Green("exit"))
|
||||
fmt.Fprintln(&output, " ", "Exit this shell")
|
||||
cli.ShowHelpInPager(output.String())
|
||||
}
|
||||
|
||||
func exec_command(rl *readline.Readline, cmdline string) bool {
|
||||
@ -131,7 +133,7 @@ func exec_command(rl *readline.Readline, cmdline string) bool {
|
||||
hi.ExitCode = 0
|
||||
defer rl.AddHistoryItem(hi)
|
||||
if len(parsed_cmdline) == 1 {
|
||||
print_basic_help()
|
||||
show_basic_help()
|
||||
return true
|
||||
}
|
||||
switch parsed_cmdline[1] {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user