Skip to content

Commit

Permalink
fix: don't print extra newlines when printing with line numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
meowgorithm committed Feb 22, 2022
1 parent e267bc9 commit a43daef
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions server/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,16 @@ func withLineNumber(s string, color bool) string {
mll := len(fmt.Sprintf("%d", len(lines)))
for i, l := range lines {
digit := fmt.Sprintf("%*d", mll, i)
line := "│"
bar := "│"
if color {
digit = lineDigitStyle.Render(digit)
line = lineBarStyle.Render(line)
bar = lineBarStyle.Render(bar)
}
if i < len(lines)-1 || len(l) != 0 {
// If the final line was a newline we'll get an empty string for
// the final line, so drop the newline altogether.
lines[i] = fmt.Sprintf(" %s %s %s", digit, bar, l)
}
lines[i] = fmt.Sprintf(" %s %s %s", digit, line, l)
}
return strings.Join(lines, "\n")
}
Expand Down

0 comments on commit a43daef

Please sign in to comment.