MCPcopy Create free account
hub / github.com/cli/cli / printHumanComment

Function printHumanComment

pkg/cmd/discussion/view/view.go:495–595  ·  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

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