Extract method for drawing placeholder rows
All checks were successful
timw4mail/gilo/pipeline/head This commit looks good

This commit is contained in:
Timothy Warren 2021-03-31 09:28:39 -04:00
parent c0d5436c35
commit 2203e30b18

View File

@ -28,6 +28,21 @@ func (e *editor) RefreshScreen() {
func (e *editor) drawRows(ab *buffer) {
for y :=0; y < e.screen.Rows; y++ {
if y >= len(e.rows) {
e.drawPlaceholderRow(y, ab)
} else {
row := truncateString(string(e.rows[y].chars), e.screen.Cols)
ab.append(row)
}
ab.append(terminal.ClearLine)
if y < (e.screen.Rows - 1) {
ab.append("\r\n")
}
}
}
func (e *editor) drawPlaceholderRow(y int, ab *buffer) {
if len(e.rows) == 0 && y == e.screen.Rows / 3 {
welcome := fmt.Sprintf("Gilo editor -- version %s", KiloVersion)
if len(welcome) > e.screen.Cols {
@ -49,17 +64,6 @@ func (e *editor) drawRows(ab *buffer) {
} else {
ab.appendRune('~')
}
} else {
row := truncateString(string(e.rows[y].chars), e.screen.Cols)
ab.append(row)
}
ab.append(terminal.ClearLine)
if y < (e.screen.Rows - 1) {
ab.append("\r\n")
}
}
}
// ----------------------------------------------------------------------------