MCPcopy
hub / github.com/cli/cli / printHumanComment

Function printHumanComment

pkg/cmd/discussion/view/view.go:488–588  ·  view source on GitHub ↗
(opts *ViewOptions, out io.Writer, c client.DiscussionComment, indent string, isReply bool, isNewest bool)

Source from the content-addressed store, hash-verified

486}
487
488func printHumanComment(opts *ViewOptions, out io.Writer, c client.DiscussionComment, indent string, isReply bool, isNewest bool) error {
489 cs := opts.IO.ColorScheme()
490 now := opts.Now()
491
492 action := "commented"
493 if isReply {
494 action = "replied"
495 }
496
497 header := fmt.Sprintf("%s%s %s • %s",
498 indent,
499 cs.Bold(c.Author.Login),
500 action,
501 text.FuzzyAgoAbbr(now, c.CreatedAt),
502 )
503 if c.IsAnswer {
504 header += fmt.Sprintf(" • %s %s", cs.SuccessIcon(), cs.Green("Answer"))
505 }
506 if isNewest {
507 kind := "comment"
508 if isReply {
509 kind = "reply"
510 }
511 header += fmt.Sprintf(" • %s", fmt.Sprintf(cs.CyanBold("Newest %s"), kind))
512 }
513 fmt.Fprintln(out, header)
514
515 if c.Body != "" {
516 md, err := markdown.Render(c.Body,
517 markdown.WithTheme(opts.IO.TerminalTheme()),
518 markdown.WithWrap(opts.IO.TerminalWidth()))
519 if err != nil {
520 return err
521 }
522 if indent != "" {
523 md = text.Indent(md, indent)
524 }
525 fmt.Fprint(out, md)
526 }
527
528 if reactions := reactionGroupList(c.ReactionGroups); reactions != "" {
529 fmt.Fprintf(out, "%s%s\n", indent, reactions)
530 }
531
532 fmt.Fprintln(out)
533
534 if isReply {
535 // Replies are leaf nodes, so there won't be children replies/comments.
536 return nil
537 }
538
539 if len(c.Replies.Comments) == 0 {
540 return nil
541 }
542
543 if c.Replies.Direction == client.DiscussionCommentListDirectionBackward {
544 if shown := len(c.Replies.Comments); shown < c.Replies.TotalCount {
545 remaining := c.Replies.TotalCount - shown

Callers 2

printHumanViewFunction · 0.85

Calls 15

FuzzyAgoAbbrFunction · 0.92
RenderFunction · 0.92
WithThemeFunction · 0.92
WithWrapFunction · 0.92
IndentFunction · 0.92
reactionGroupListFunction · 0.85
ColorSchemeMethod · 0.80
BoldMethod · 0.80
SuccessIconMethod · 0.80
GreenMethod · 0.80
CyanBoldMethod · 0.80
TerminalThemeMethod · 0.80

Tested by

no test coverage detected