Add line number indication to status bar
All checks were successful
timw4mail/gilo/pipeline/head This commit looks good

This commit is contained in:
Timothy Warren 2021-04-01 12:49:55 -04:00
parent 6e5e287bb3
commit 587dfc686a

View File

@ -114,18 +114,35 @@ func (e *editor) drawStatusBar(ab *buffer) {
fileName = e.document.filename fileName = e.document.filename
} }
statusLine := fmt.Sprintf("%.20s - %d lines", fileName, e.document.rowCount()) leftStatus := fmt.Sprintf("%.20s - %d lines", fileName, e.document.rowCount())
length := len(statusLine) length := len(leftStatus)
if length > cols{ if length > cols {
statusLine = truncateString(statusLine, cols) leftStatus = truncateString(leftStatus, cols)
ab.append(leftStatus)
ab.append(terminal.ResetColor)
return
}
rightStatus := fmt.Sprintf("%d/%d", e.cursor.y, e.document.rowCount())
rlength := len(rightStatus)
statusLength := length + rlength
if statusLength <= cols {
paddingLength := cols - statusLength
padding := strings.Repeat(" ", paddingLength)
ab.append(leftStatus)
ab.append(padding)
ab.append(rightStatus)
ab.append(statusLine)
ab.append(terminal.ResetColor) ab.append(terminal.ResetColor)
return return
} }
ab.append(statusLine) ab.append(leftStatus)
// Pad the rest of the status line // Pad the rest of the status line
padding := strings.Repeat(" ", cols - length) padding := strings.Repeat(" ", cols - length)