diff --git a/internal/ansi/ansi.go b/internal/ansi/ansi.go index 37b66e9..83b8bbf 100644 --- a/internal/ansi/ansi.go +++ b/internal/ansi/ansi.go @@ -2,7 +2,11 @@ package ansi import "fmt" +const ClearLine = "\x1b[K" const ClearScreen = "\x1b[2J" + +const HideCursor = "\x1b[?25l" +const ShowCursor = "\x1b[?25h" const ResetCursor = "\x1b[H" func Code (s string) string { diff --git a/internal/editor/editor.go b/internal/editor/editor.go index 65d0b11..b22ebdc 100644 --- a/internal/editor/editor.go +++ b/internal/editor/editor.go @@ -26,12 +26,13 @@ func New() *editor { func (e *editor) RefreshScreen() { ab := newBuffer() - ab.append(ansi.ClearScreen) + ab.append(ansi.HideCursor) ab.append(ansi.ResetCursor) e.drawRows(ab) ab.append(ansi.ResetCursor) + ab.append(ansi.ShowCursor) terminal.Write(ab.toString()) } @@ -41,8 +42,7 @@ func (e *editor) ProcessKeypress() bool { // Clean up on exit if ch == char.Ctrl('q') { - terminal.Write(ansi.ClearScreen) - terminal.Write(ansi.ResetCursor) + terminal.Write(ansi.ClearScreen + ansi.ResetCursor) return false } @@ -53,6 +53,7 @@ func (e *editor) ProcessKeypress() bool { func (e *editor) drawRows(ab *buffer) { for y :=0; y < e.rows; y += 1 { ab.appendRune('~') + ab.append(ansi.ClearLine) if y < (e.rows - 1) { ab.append("\r\n")