MCPcopy
hub / github.com/cli/cli / longPager

Function longPager

pkg/cmd/root/help_reference.go:16–41  ·  view source on GitHub ↗

longPager provides a pager over a commands Long message. It is currently only used for the reference command

(io *iostreams.IOStreams)

Source from the content-addressed store, hash-verified

14// longPager provides a pager over a commands Long message.
15// It is currently only used for the reference command
16func 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
43func stringifyReference(cmd *cobra.Command) string {
44 buf := bytes.NewBufferString("# gh reference\n\n")

Callers 1

NewCmdRootFunction · 0.85

Calls 10

RenderFunction · 0.92
WithThemeFunction · 0.92
WithWrapFunction · 0.92
dedentFunction · 0.85
IsStdoutTTYMethod · 0.80
DetectTerminalThemeMethod · 0.80
TerminalWidthMethod · 0.80
TerminalThemeMethod · 0.80
StartPagerMethod · 0.80
StopPagerMethod · 0.80

Tested by

no test coverage detected