forked from Mirrors/bubbletea
feat: support a Clear command
This commit is contained in:
parent
37b79f55f1
commit
6e1065830a
|
@ -7,6 +7,7 @@ func (n nilRenderer) stop() {}
|
|||
func (n nilRenderer) kill() {}
|
||||
func (n nilRenderer) write(v string) {}
|
||||
func (n nilRenderer) repaint() {}
|
||||
func (n nilRenderer) clearScreen() {}
|
||||
func (n nilRenderer) altScreen() bool { return false }
|
||||
func (n nilRenderer) enterAltScreen() {}
|
||||
func (n nilRenderer) exitAltScreen() {}
|
||||
|
|
|
@ -21,6 +21,9 @@ type renderer interface {
|
|||
// in succession.
|
||||
repaint()
|
||||
|
||||
// Clears the terminal.
|
||||
clearScreen()
|
||||
|
||||
// Whether or not the alternate screen buffer is enabled.
|
||||
altScreen() bool
|
||||
// Enable the alternate screen buffer.
|
||||
|
|
14
screen.go
14
screen.go
|
@ -9,6 +9,20 @@ type WindowSizeMsg struct {
|
|||
Height int
|
||||
}
|
||||
|
||||
// ClearScreen is a special command that tells the program to clear the screen
|
||||
// before the next update. This can be used to move the cursor to the top left
|
||||
// of the screen and clear visual clutter when the alt screen is not in use.
|
||||
//
|
||||
// Note that it should never be necessary to call ClearScreen() for regular
|
||||
// redraws.
|
||||
func ClearScreen() Msg {
|
||||
return clearScreenMsg{}
|
||||
}
|
||||
|
||||
// clearScreenMsg is an internal message that signals to clear the screen.
|
||||
// You can send a clearScreenMsg with ClearScreen.
|
||||
type clearScreenMsg struct{}
|
||||
|
||||
// EnterAltScreen is a special command that tells the Bubble Tea program to
|
||||
// enter the alternate screen buffer.
|
||||
//
|
||||
|
|
|
@ -245,6 +245,14 @@ func (r *standardRenderer) repaint() {
|
|||
r.lastRender = ""
|
||||
}
|
||||
|
||||
func (r *standardRenderer) clearScreen() {
|
||||
r.mtx.Lock()
|
||||
defer r.mtx.Unlock()
|
||||
|
||||
r.out.ClearScreen()
|
||||
r.out.MoveCursor(1, 1)
|
||||
}
|
||||
|
||||
func (r *standardRenderer) altScreen() bool {
|
||||
return r.altScreenActive
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue