Aligns the provided message so that all lines after the first line start at the same location as the first line. Assumes that the first line starts at the correct location (after carriage return, tab, label, spacer and tab). The longestLabelLen parameter specifies the length of the longest label in
(message string, longestLabelLen int)
| 323 | // The longestLabelLen parameter specifies the length of the longest label in the output (required because this is the |
| 324 | // basis on which the alignment occurs). |
| 325 | func indentMessageLines(message string, longestLabelLen int) string { |
| 326 | outBuf := new(bytes.Buffer) |
| 327 | |
| 328 | for i, scanner := 0, bufio.NewScanner(strings.NewReader(message)); scanner.Scan(); i++ { |
| 329 | // no need to align first line because it starts at the correct location (after the label) |
| 330 | if i != 0 { |
| 331 | // append alignLen+1 spaces to align with "{{longestLabel}}:" before adding tab |
| 332 | outBuf.WriteString("\n\t" + strings.Repeat(" ", longestLabelLen+1) + "\t") |
| 333 | } |
| 334 | outBuf.WriteString(scanner.Text()) |
| 335 | } |
| 336 | |
| 337 | return outBuf.String() |
| 338 | } |
| 339 | |
| 340 | type failNower interface { |
| 341 | FailNow() |