From 6e5e287bb32e236dac90651bff4e5ec839098626 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Thu, 1 Apr 2021 12:37:28 -0400 Subject: [PATCH] Show filename and row count in status bar --- editor/draw.go | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/editor/draw.go b/editor/draw.go index 09669a3..2e5b505 100644 --- a/editor/draw.go +++ b/editor/draw.go @@ -105,10 +105,32 @@ func (e *editor) drawPlaceholderRow(y int, ab *buffer) { } func (e *editor) drawStatusBar(ab *buffer) { + cols := e.screen.Cols + ab.append(terminal.InvertColor) - str := strings.Repeat(" ", e.screen.Cols) - ab.append(str) + fileName := "[No Name]" + if e.document.filename != "" { + fileName = e.document.filename + } + + statusLine := fmt.Sprintf("%.20s - %d lines", fileName, e.document.rowCount()) + length := len(statusLine) + if length > cols{ + statusLine = truncateString(statusLine, cols) + + ab.append(statusLine) + ab.append(terminal.ResetColor) + + return + } + + ab.append(statusLine) + + // Pad the rest of the status line + padding := strings.Repeat(" ", cols - length) + ab.append(padding) + ab.append(terminal.ResetColor) }