// TODO: fix printing notes when the line-width is too small
fix printing notes when the line-width is too small
// TODO : fix printing notes when the line - width is too small
func printNote(note *gitlab.Note, isReply bool, mrURL string, cfg printNoteCfg) string {
	lab.CmdLogger().Debugf("printNote id=%d Author=%s isReply=%v", note.ID, note.Author.Username, isReply)
	var b strings.Builder
	resolved := ""
	if note.Resolved {
		resolved = "RESOLVED"
	}
	position := ""
	if note.Position != nil && !isReply {
		context := getContext(note.Position.HeadSHA, note.Position.NewPath, note.Position.NewLine, cfg)
		position = fmt.Sprintf("\n%s:%d %s", note.Position.NewPath, note.Position.NewLine, context)
	}
	indent := " "
	if isReply {
		indent = strings.Repeat(" ", 4) + "| "
	}
	bodyWidth := cfg.lineLen - len(indent)
	if cfg.showURL {
		webURL := mrURL + "#note_" + strconv.Itoa(note.ID)
		fmt.Fprintf(&b, "%s%s\n", indent, webURL)
	}
	fmt.Fprintf(&b, "%s@%*s %s %s%s\n%s%s",
		indent, -40, note.Author.Username, note.CreatedAt, resolved, position,
		indent, strings.Repeat("-", 80))
	if cfg.nowrap {
		b.WriteString(note.Body)
	} else {
		lab.CmdLogger().Debugf("printNote.justify %d", len(note.Body))
		for i, line := range strings.Split(note.Body, "\n") {
			lab.CmdLogger().Debugf("printNote.justify.line %d", i)
			if len(line) == 0 {
				fmt.Fprintf(&b, "\n%s", indent)
				continue
			}
			pos := 0
			rs := []rune(line)
			for {
				lab.CmdLogger().Debugf("printNote.justify.line.loop %d", pos)
				lastPos := pos
				for pos > 0 && pos < len(rs) && unicode.IsSpace(rs[pos]) {
					pos++
				}
				if pos >= len(rs) {
					break
				}
				endPos := pos + bodyWidth
				if endPos >= len(rs) {
					endPos = len(rs) - 1
				}
				for pos <= endPos && endPos+1 < len(rs) && !unicode.IsSpace(rs[endPos+1]) {
					endPos--
				}
				fmt.Fprintf(&b, "\n%s%s", indent, string(rs[pos:endPos+1]))
				pos = endPos + 1
				if pos == lastPos {
					fmt.Fprintf(&b, "\n%s%s", indent, string(rs[endPos+1:len(rs)-1]))
					break
				}
			}
		}
	}
	fmt.Fprintf(&b, "\n\n")
	return b.String()
}
func printNote ( note * gitlab . Note , isReply bool , mrURL string , cfg printNoteCfg ) string { lab . CmdLogger ( ) . Debugf ( " " , note . ID , note . Author . Username , isReply ) var b strings . Builder resolved := " " if note . Resolved { resolved = " " } position := " " if note . Position != nil && ! isReply { context := getContext ( note . Position . HeadSHA , note . Position . NewPath , note . Position . NewLine , cfg ) position = fmt . Sprintf ( " \n " , note . Position . NewPath , note . Position . NewLine , context ) } indent := " " if isReply { indent = strings . Repeat ( " " , 4 ) + " " } bodyWidth := cfg . lineLen - len ( indent ) if cfg . showURL { webURL := mrURL + " " + strconv . Itoa ( note . ID ) fmt . Fprintf ( & b , " \n " , indent , webURL ) } fmt . Fprintf ( & b , " \n " , indent , - 40 , note . Author . Username , note . CreatedAt , resolved , position , indent , strings . Repeat ( " " , 80 ) ) if cfg . nowrap { b . WriteString ( note . Body ) } else { lab . CmdLogger ( ) . Debugf ( " " , len ( note . Body ) ) for i , line := range strings . Split ( note . Body , " \n " ) { lab . CmdLogger ( ) . Debugf ( " " , i ) if len ( line ) == 0 { fmt . Fprintf ( & b , " \n " , indent ) continue } pos := 0 rs := [ ] rune ( line ) for { lab . CmdLogger ( ) . Debugf ( " " , pos ) lastPos := pos for pos > 0 && pos < len ( rs ) && unicode . IsSpace ( rs [ pos ] ) { pos ++ } if pos >= len ( rs ) { break } endPos := pos + bodyWidth if endPos >= len ( rs ) { endPos = len ( rs ) - 1 } for pos <= endPos && endPos + 1 < len ( rs ) && ! unicode . IsSpace ( rs [ endPos + 1 ] ) { endPos -- } fmt . Fprintf ( & b , " \n " , indent , string ( rs [ pos : endPos + 1 ] ) ) pos = endPos + 1 if pos == lastPos { fmt . Fprintf ( & b , " \n " , indent , string ( rs [ endPos + 1 : len ( rs ) - 1 ] ) ) break } } } } fmt . Fprintf ( & b , " \n \n " ) return b . String ( ) }
fix printing notes when the line-width is too small
fix printing notes when the line - width is too small