From d831bd4f834e0b7552c92c043887e2b917c7c9d2 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 1 Apr 2021 09:41:16 -0400 Subject: [PATCH] Draw empty status bar --- editor/draw.go | 16 ++++++++++++---- editor/editor.go | 4 ++++ terminal/ansi.go | 6 ++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/editor/draw.go b/editor/draw.go index 270cad6..e385d0a 100644 --- a/editor/draw.go +++ b/editor/draw.go @@ -20,6 +20,8 @@ func (e *editor) RefreshScreen() { ab.append(terminal.ResetCursor) e.drawRows(ab) + e.drawStatusBar(ab) + ab.append(terminal.MoveCursor(e.renderX - e.offset.x, e.cursor.y - e.offset.y)) ab.append(terminal.ShowCursor) @@ -74,10 +76,7 @@ func (e *editor) drawRows(ab *buffer) { } ab.append(terminal.ClearLine) - - if y < (e.screen.Rows - 1) { - ab.append("\r\n") - } + ab.append("\r\n") } } @@ -105,6 +104,15 @@ func (e *editor) drawPlaceholderRow(y int, ab *buffer) { } } +func (e *editor) drawStatusBar(ab *buffer) { + ab.append(terminal.InvertColor) + + str := strings.Repeat(" ", e.screen.Cols) + ab.append(str) + + ab.append(terminal.ResetColor) +} + // ---------------------------------------------------------------------------- // !Output Buffer // ---------------------------------------------------------------------------- diff --git a/editor/editor.go b/editor/editor.go index 735acd7..871fc47 100644 --- a/editor/editor.go +++ b/editor/editor.go @@ -26,6 +26,10 @@ type editor struct { func New() *editor { screen := terminal.Size() + + // Subtract rows for status bar and prompt + screen.Rows -= 1 + cursor := &point { 0, 0 } offset := &point { 0, 0 } var rows []*row diff --git a/terminal/ansi.go b/terminal/ansi.go index 5f88f70..8f40b75 100644 --- a/terminal/ansi.go +++ b/terminal/ansi.go @@ -30,6 +30,12 @@ const ( ResetCursor = EscPrefix + "H" ) +// Color sequences +const ( + InvertColor = EscPrefix + "7m" + ResetColor = EscPrefix + "m" +) + // ---------------------------------------------------------------------------- // !Helpers // ----------------------------------------------------------------------------