forked from Mirrors/bubbletea
When showing/hiding the cursor operate on the program's io.Writer
Previously we were operating on io.Stdout.
This commit is contained in:
parent
f5fde56af0
commit
6d70abd7d5
|
@ -7,6 +7,14 @@ import (
|
|||
te "github.com/muesli/termenv"
|
||||
)
|
||||
|
||||
func hideCursor(w io.Writer) {
|
||||
fmt.Fprintf(w, te.CSI+te.HideCursorSeq)
|
||||
}
|
||||
|
||||
func showCursor(w io.Writer) {
|
||||
fmt.Fprintf(w, te.CSI+te.ShowCursorSeq)
|
||||
}
|
||||
|
||||
func clearLine(w io.Writer) {
|
||||
fmt.Fprintf(w, te.CSI+te.EraseLineSeq, 2)
|
||||
}
|
||||
|
|
4
tea.go
4
tea.go
|
@ -124,11 +124,11 @@ func (p *Program) Start() error {
|
|||
|
||||
p.renderer = newRenderer(p.output, &p.mtx)
|
||||
|
||||
err := initTerminal()
|
||||
err := initTerminal(p.output)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer restoreTerminal()
|
||||
defer restoreTerminal(p.output)
|
||||
|
||||
// Initialize program
|
||||
model := p.initialModel
|
||||
|
|
11
tty.go
11
tty.go
|
@ -1,13 +1,14 @@
|
|||
package tea
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/containerd/console"
|
||||
"github.com/muesli/termenv"
|
||||
)
|
||||
|
||||
var tty console.Console
|
||||
|
||||
func initTerminal() error {
|
||||
func initTerminal(w io.Writer) error {
|
||||
tty = console.Current()
|
||||
err := tty.SetRaw()
|
||||
if err != nil {
|
||||
|
@ -15,11 +16,11 @@ func initTerminal() error {
|
|||
}
|
||||
|
||||
enableAnsiColors()
|
||||
termenv.HideCursor()
|
||||
hideCursor(w)
|
||||
return nil
|
||||
}
|
||||
|
||||
func restoreTerminal() error {
|
||||
termenv.ShowCursor()
|
||||
func restoreTerminal(w io.Writer) error {
|
||||
showCursor(w)
|
||||
return tty.Reset()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue