Fullscreen mode via altscreen + fullscreen example

This commit is contained in:
Christian Rocha
2020-01-17 15:37:04 -05:00
parent c1b4d6a515
commit 4f42c502ed
4 changed files with 78 additions and 17 deletions

21
tea.go
View File

@@ -87,10 +87,9 @@ func (p *Program) Start() error {
hideCursor()
p.render(model)
// Subscribe to user input
// TODO: should we move this to the end-user program level or just keep this
// here, since it blocks nicely and user input will probably be something
// users typically need?
// Subscribe to user input. We could move this out of here and offer it
// as a subscription, but it blocks nicely and seems to be a common enough
// need that we're enabling it by default.
go func() {
for {
msg, _ := ReadKey(p.rw)
@@ -195,7 +194,19 @@ func clearLines(n int) {
}
}
// ClearScreen clears the visible portion of the terminal
// Fullscreen switches to the altscreen and clears the terminal. The former
// view can be restored with ExitFullscreen().
func Fullscreen() {
fmt.Print(esc + "?1049h" + esc + "H")
}
// ExitFullscreen exits the altscreen and returns the former terminal view
func ExitFullscreen() {
fmt.Print(esc + "?1049l")
}
// ClearScreen clears the visible portion of the terminal. Effectively, it
// fills the terminal with blank spaces.
func ClearScreen() {
fmt.Printf(esc + "2J" + esc + "3J" + esc + "1;1H")
}