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,27 +28,7 @@ func (e *editor) RefreshScreen() {
func (e *editor) drawRows(ab *buffer) { func (e *editor) drawRows(ab *buffer) {
for y :=0; y < e.screen.Rows; y++ { for y :=0; y < e.screen.Rows; y++ {
if y >= len(e.rows) { if y >= len(e.rows) {
if len(e.rows) == 0 && y == e.screen.Rows / 3 { e.drawPlaceholderRow(y, ab)
welcome := fmt.Sprintf("Gilo editor -- version %s", KiloVersion)
if len(welcome) > e.screen.Cols {
welcome = truncateString(welcome, e.screen.Cols)
}
padding := (e.screen.Cols - len(welcome)) / 2
if padding > 0 {
ab.appendRune('~')
padding--
}
for padding > 0 {
padding--
ab.appendRune(' ')
}
ab.append(welcome)
} else {
ab.appendRune('~')
}
} else { } else {
row := truncateString(string(e.rows[y].chars), e.screen.Cols) row := truncateString(string(e.rows[y].chars), e.screen.Cols)
ab.append(row) ab.append(row)
@ -62,6 +42,30 @@ func (e *editor) drawRows(ab *buffer) {
} }
} }
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 {
welcome = truncateString(welcome, e.screen.Cols)
}
padding := (e.screen.Cols - len(welcome)) / 2
if padding > 0 {
ab.appendRune('~')
padding--
}
for padding > 0 {
padding--
ab.appendRune(' ')
}
ab.append(welcome)
} else {
ab.appendRune('~')
}
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// !Output Buffer // !Output Buffer
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------