charmbracelet / bubbletea

A powerful little TUI framework 🏗

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Toggling the altscreen results in an empty view if the return value of the view does not change

meowgorithm opened this issue · comments

This happens because we're only redrawing lines that have changed since the last render, but not checking whether or not the value of the altscreen has changed as well.

The following example illustrates the bug:

package main

import (
	"fmt"
	"os"

	tea "github.com/charmbracelet/bubbletea"
)

type model struct {}

func (m model) Init() tea.Cmd {
	return nil
}

func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
	switch msg := msg.(type) {
	case tea.KeyMsg:
		switch msg.String() {
		case "q", "ctrl+c", "esc":
			return m, tea.Quit
		case "a":
			return m, tea.EnterAltScreen
		case "i":
			return m, tea.ExitAltScreen
		}
	}
	return m, nil
}

func (m model) View() string {
	return "Hello World!"
}

func main() {
	if err := tea.NewProgram(model{}).Start(); err != nil {
		fmt.Println("Error running program:", err)
		os.Exit(1)
	}
}