diff --git a/go.mod b/go.mod index 3f848d5..ebbf619 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,10 @@ go 1.25.0 require ( github.com/creack/pty v1.1.24 - golang.org/x/term v0.41.0 + tea.kareha.org/lab/termi v0.0.0-20260326135653-28299eeba224 ) -require golang.org/x/sys v0.42.0 // indirect +require ( + golang.org/x/sys v0.42.0 // indirect + golang.org/x/term v0.41.0 // indirect +) diff --git a/go.sum b/go.sum index f4245ea..2ddd7ce 100644 --- a/go.sum +++ b/go.sum @@ -4,3 +4,5 @@ golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo= golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= golang.org/x/term v0.41.0 h1:QCgPso/Q3RTJx2Th4bDLqML4W6iJiaXFq2/ftQF13YU= golang.org/x/term v0.41.0/go.mod h1:3pfBgksrReYfZ5lvYM0kSO0LIkAl4Yl2bXOkKP7Ec2A= +tea.kareha.org/lab/termi v0.0.0-20260326135653-28299eeba224 h1:nf3D+GjzIP9ab7fXIZmaFloRFD478SV4+bPhB9Wa1U0= +tea.kareha.org/lab/termi v0.0.0-20260326135653-28299eeba224/go.mod h1:+ticjUt1pyuink8Qip4QHN3GGz1QaNPRuJrM+jWRLgU= diff --git a/internal/console/console.go b/internal/console/console.go deleted file mode 100644 index e6287e1..0000000 --- a/internal/console/console.go +++ /dev/null @@ -1,82 +0,0 @@ -package console - -import ( - "fmt" - "os" - - "golang.org/x/term" -) - -var state *term.State - -func Raw() { - if state != nil { - term.Restore(int(os.Stdin.Fd()), state) - state = nil - } - s, err := term.MakeRaw(int(os.Stdin.Fd())) - if err != nil { - panic(err) - } - state = s -} - -func Cooked() { - if state == nil { - panic("invalid state") - } - term.Restore(int(os.Stdin.Fd()), state) - state = nil -} - -func Clear() { - fmt.Print("\x1b[2J") -} - -func HomeCursor() { - fmt.Print("\x1b[H") -} - -func MoveCursor(x, y int) { - fmt.Printf("\x1b[%d;%dH", y+1, x+1) -} - -func HideCursor() { - fmt.Print("\x1b[?25l") -} - -func ShowCursor() { - fmt.Print("\x1b[?25h") -} - -func Size() (int, int) { - w, h, err := term.GetSize(int(os.Stdout.Fd())) - if err != nil { - return 80, 24 - } - return w, h -} - -func EnableInvert() { - fmt.Print("\x1b[7m") -} - -func DisableInvert() { - fmt.Print("\x1b[0m") -} - -func SaveCursor() { - fmt.Print("\x1b[s") -} - -func LoadCursor() { - fmt.Print("\x1b[u") -} - -func ScrollRange(top, bottom int) { - fmt.Printf("\x1b[%d;%dr", top+1, bottom) -} - -func ClearLine() { - fmt.Print("\x1b[K") -} diff --git a/internal/console/output.go b/internal/console/output.go deleted file mode 100644 index 5899bd1..0000000 --- a/internal/console/output.go +++ /dev/null @@ -1,15 +0,0 @@ -package console - -import ( - "fmt" -) - -func Print(s string) { - fmt.Print(s) -} - -func Printf(format string, a ...any) (n int, err error) { - s := fmt.Sprintf(format, a...) - Print(s) - return len(s), nil -} diff --git a/internal/fep/fep.go b/internal/fep/fep.go index 31f6497..521db7e 100644 --- a/internal/fep/fep.go +++ b/internal/fep/fep.go @@ -8,7 +8,7 @@ import ( "github.com/creack/pty" - "tea.kareha.org/lab/kakiko/internal/console" + "tea.kareha.org/lab/termi" ) type Process func(b []byte) []byte @@ -64,12 +64,12 @@ func Init(args []string, process Process, status Status) *FEP { } }() - _, h := console.Size() - console.ScrollRange(0, h-1) + _, h := termi.Size() + termi.ScrollRange(0, h-1) - console.Clear() - console.HomeCursor() - console.Raw() + termi.Clear() + termi.HomeCursor() + termi.Raw() go func() { for { @@ -100,27 +100,27 @@ func Init(args []string, process Process, status Status) *FEP { } func (f *FEP) Finish() { - _, h := console.Size() - console.ScrollRange(0, h) + _, h := termi.Size() + termi.ScrollRange(0, h) - console.Clear() - console.HomeCursor() - console.Cooked() - console.ShowCursor() + termi.Clear() + termi.HomeCursor() + termi.Cooked() + termi.ShowCursor() } func (f *FEP) drawStatus() { - _, h := console.Size() - console.SaveCursor() - console.HideCursor() - console.MoveCursor(0, h-1) + _, h := termi.Size() + termi.SaveCursor() + termi.HideCursor() + termi.MoveCursor(0, h-1) status := f.status() - console.Print(status) - console.ClearLine() + termi.Print(status) + termi.ClearTail() - console.ShowCursor() - console.LoadCursor() + termi.ShowCursor() + termi.LoadCursor() } func (f *FEP) Main() {