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) kill() {}
|
||||||
func (n nilRenderer) write(v string) {}
|
func (n nilRenderer) write(v string) {}
|
||||||
func (n nilRenderer) repaint() {}
|
func (n nilRenderer) repaint() {}
|
||||||
|
func (n nilRenderer) clearScreen() {}
|
||||||
func (n nilRenderer) altScreen() bool { return false }
|
func (n nilRenderer) altScreen() bool { return false }
|
||||||
func (n nilRenderer) enterAltScreen() {}
|
func (n nilRenderer) enterAltScreen() {}
|
||||||
func (n nilRenderer) exitAltScreen() {}
|
func (n nilRenderer) exitAltScreen() {}
|
||||||
|
|
|
@ -21,6 +21,9 @@ type renderer interface {
|
||||||
// in succession.
|
// in succession.
|
||||||
repaint()
|
repaint()
|
||||||
|
|
||||||
|
// Clears the terminal.
|
||||||
|
clearScreen()
|
||||||
|
|
||||||
// Whether or not the alternate screen buffer is enabled.
|
// Whether or not the alternate screen buffer is enabled.
|
||||||
altScreen() bool
|
altScreen() bool
|
||||||
// Enable the alternate screen buffer.
|
// Enable the alternate screen buffer.
|
||||||
|
|
14
screen.go
14
screen.go
|
@ -9,6 +9,20 @@ type WindowSizeMsg struct {
|
||||||
Height int
|
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
|
// EnterAltScreen is a special command that tells the Bubble Tea program to
|
||||||
// enter the alternate screen buffer.
|
// enter the alternate screen buffer.
|
||||||
//
|
//
|
||||||
|
|
|
@ -245,6 +245,14 @@ func (r *standardRenderer) repaint() {
|
||||||
r.lastRender = ""
|
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 {
|
func (r *standardRenderer) altScreen() bool {
|
||||||
return r.altScreenActive
|
return r.altScreenActive
|
||||||
}
|
}
|
||||||
|
|
3
tea.go
3
tea.go
|
@ -378,6 +378,9 @@ func (p *Program) StartReturningModel() (Model, error) {
|
||||||
p.shutdown(false)
|
p.shutdown(false)
|
||||||
return model, nil
|
return model, nil
|
||||||
|
|
||||||
|
case clearScreenMsg:
|
||||||
|
p.renderer.clearScreen()
|
||||||
|
|
||||||
case enterAltScreenMsg:
|
case enterAltScreenMsg:
|
||||||
p.renderer.enterAltScreen()
|
p.renderer.enterAltScreen()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue