ledger.Files.?etLastNLines trims empty lines

main
bel 2023-10-29 10:36:45 -06:00
parent f078a1e6a1
commit 566b3ad571
1 changed files with 5 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import (
"path"
"path/filepath"
"sort"
"strings"
"unicode"
)
@ -54,6 +55,9 @@ func (files Files) TempSetLastNLines(n int, lines []string) error {
return "", err
}
for i := range lines {
if len(strings.TrimSpace(lines[i])) == 0 {
continue
}
if _, err := fmt.Fprintln(w, lines[i]); err != nil {
return "", err
}
@ -87,7 +91,7 @@ func peekLastNLines(w io.Writer, r *bufio.Reader, n int) ([]string, error) {
lastNLines := make([]string, 0, n)
for {
line, err := r.ReadBytes('\n')
if len(line) > 0 {
if len(bytes.TrimSpace(line)) > 0 {
lastNLines = append(lastNLines, string(bytes.TrimRight(line, "\n")))
for i := 0; i < len(lastNLines)-n; i++ {
fmt.Fprintln(w, lastNLines[i])