longPager provides a pager over a commands Long message. It is currently only used for the reference command
(io *iostreams.IOStreams)
| 14 | // longPager provides a pager over a commands Long message. |
| 15 | // It is currently only used for the reference command |
| 16 | func longPager(io *iostreams.IOStreams) func(*cobra.Command, []string) { |
| 17 | return func(cmd *cobra.Command, args []string) { |
| 18 | wrapWidth := 0 |
| 19 | if io.IsStdoutTTY() { |
| 20 | io.DetectTerminalTheme() |
| 21 | wrapWidth = io.TerminalWidth() |
| 22 | } |
| 23 | |
| 24 | md, err := markdown.Render(cmd.Long, |
| 25 | markdown.WithTheme(io.TerminalTheme()), |
| 26 | markdown.WithWrap(wrapWidth)) |
| 27 | if err != nil { |
| 28 | fmt.Fprintln(io.ErrOut, err) |
| 29 | return |
| 30 | } |
| 31 | |
| 32 | if !io.IsStdoutTTY() { |
| 33 | fmt.Fprint(io.Out, dedent(md)) |
| 34 | return |
| 35 | } |
| 36 | |
| 37 | _ = io.StartPager() |
| 38 | defer io.StopPager() |
| 39 | fmt.Fprint(io.Out, md) |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | func stringifyReference(cmd *cobra.Command) string { |
| 44 | buf := bytes.NewBufferString("# gh reference\n\n") |
no test coverage detected