From 587dfc686a3004107125f0f88ab5998ae27352c1 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Thu, 1 Apr 2021 12:49:55 -0400 Subject: [PATCH] Add line number indication to status bar --- editor/draw.go | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/editor/draw.go b/editor/draw.go index 2e5b505..34adcb3 100644 --- a/editor/draw.go +++ b/editor/draw.go @@ -114,18 +114,35 @@ func (e *editor) drawStatusBar(ab *buffer) { fileName = e.document.filename } - statusLine := fmt.Sprintf("%.20s - %d lines", fileName, e.document.rowCount()) - length := len(statusLine) - if length > cols{ - statusLine = truncateString(statusLine, cols) + leftStatus := fmt.Sprintf("%.20s - %d lines", fileName, e.document.rowCount()) + length := len(leftStatus) + if length > 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) return } - ab.append(statusLine) + ab.append(leftStatus) // Pad the rest of the status line padding := strings.Repeat(" ", cols - length)