1
0
Fork 0

Clear screen line by line

This commit is contained in:
Timothy Warren 2021-03-24 15:20:57 -04:00
parent bb6f7764a1
commit ca6e38fc51
2 changed files with 8 additions and 3 deletions

View File

@ -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 {

View File

@ -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")