1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-30 03:23:08 +03:00

Fix ForEachLineInFile to not lose the last line if it doesn't end with a LF

This commit is contained in:
Stefan Haller
2024-10-09 15:37:08 +02:00
parent b71aa5e23b
commit 696e78fcc8
3 changed files with 2 additions and 11 deletions

View File

@ -21,8 +21,8 @@ func ForEachLineInFile(path string, f func(string, int)) error {
func forEachLineInStream(reader io.Reader, f func(string, int)) {
bufferedReader := bufio.NewReader(reader)
for i := 0; true; i++ {
line, err := bufferedReader.ReadString('\n')
if err != nil {
line, _ := bufferedReader.ReadString('\n')
if len(line) == 0 {
break
}
f(line, i)