53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
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)
|
|
}
|
|
}
|