Properly handle files that don't end with newlines

Closes #603
This commit is contained in:
Zachary Yedidia
2017-03-27 13:15:00 -04:00
parent 790ccd429c
commit 73ab25d008
4 changed files with 23 additions and 5 deletions

View File

@@ -78,12 +78,19 @@ func NewLineArray(reader io.Reader) *LineArray {
br := bufio.NewReader(&buf)
for i := 0; i < numlines; i++ {
i := 0
for {
data, err := br.ReadBytes('\n')
if err != nil {
if err == io.EOF {
// la.lines[i] = Line{data[:len(data)], nil, nil, false}
la.lines[i].data = data
if i >= len(la.lines) {
if len(data) != 0 {
la.lines = append(la.lines, Line{data, nil, nil, false})
}
} else {
la.lines[i].data = data
}
}
// Last line was read
break
@@ -91,6 +98,9 @@ func NewLineArray(reader io.Reader) *LineArray {
la.lines[i].data = data[:len(data)-1]
// la.lines[i] = Line{data[:len(data)-1], nil, nil, false}
}
i++
}
for i := 0; i < numlines; i++ {
}
return la

View File

@@ -201,7 +201,14 @@ func InitScreen() {
// RedrawAll redraws everything -- all the views and the messenger
func RedrawAll() {
messenger.Clear()
screen.Clear()
w, h := screen.Size()
for x := 0; x < w; x++ {
for y := 0; y < h; y++ {
screen.SetContent(x, y, ' ', nil, defStyle)
}
}
for _, v := range tabs[curTab].views {
v.Display()
}

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,6 @@
color-link comment "bold brightgreen"
color-link constant "cyan"
color-link constant.specialChar "red"
color-link identifier "blue"
color-link statement "green"
color-link symbol "green"