Make dashboard updateable
This commit is contained in:
52
terminal_cursor_test.go
Normal file
52
terminal_cursor_test.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
)
|
||||
|
||||
func TestTerminalCursorOutputPositionsHardwareBarAfterFrame(t *testing.T) {
|
||||
file, err := os.CreateTemp(t.TempDir(), "cursor-output")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
output := newTerminalCursorOutput(file)
|
||||
output.SetCursor(true, 7, 4)
|
||||
if _, err := output.Write([]byte("frame")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
content, err := os.ReadFile(file.Name())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
wantSuffix := ansi.SetCursorStyle(5) + ansi.CursorPosition(7, 4) + ansi.ShowCursor
|
||||
if !strings.HasSuffix(string(content), wantSuffix) {
|
||||
t.Fatalf("cursor output = %q, want suffix %q", content, wantSuffix)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTerminalCursorOutputHidesCursorOutsideInsertMode(t *testing.T) {
|
||||
file, err := os.CreateTemp(t.TempDir(), "cursor-output")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
output := newTerminalCursorOutput(file)
|
||||
output.SetCursor(false, 0, 0)
|
||||
if _, err := output.Write([]byte("frame")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
content, err := os.ReadFile(file.Name())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.HasSuffix(string(content), ansi.HideCursor) {
|
||||
t.Fatalf("cursor output did not hide cursor: %q", content)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user