Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When a large update is performed, it will cause a flash. #1032

Open
yorukot opened this issue Jun 1, 2024 · 1 comment
Open

When a large update is performed, it will cause a flash. #1032

yorukot opened this issue Jun 1, 2024 · 1 comment

Comments

@yorukot
Copy link
Contributor

yorukot commented Jun 1, 2024

Describe the bug
When a large update is performed, it will cause a flash.

Setup

  • OS: Fedora
  • Shell: zsh
  • Terminal Emulator: kitty
  • Terminal Multiplexer: zellij

To Reproduce
Steps to reproduce the behavior:

  1. go run main.go
  2. Press Tab to let tui update
  3. See error

Source Code

package main

import (
	tea "github.com/charmbracelet/bubbletea"
	"github.com/charmbracelet/lipgloss"
	"log"
	"math/rand"
	"strings"
)

type sessionState uint

const (
	timerView sessionState = iota
	spinnerView
)

var (
	modelStyle = lipgloss.NewStyle().
			Width(80).
			Height(35).
			Align(lipgloss.Center, lipgloss.Center).
			BorderStyle(lipgloss.HiddenBorder()).
			Background(lipgloss.Color("#4B4B4B"))

	focusedModelStyle = lipgloss.NewStyle().
				Width(80).
				Height(35).
				Align(lipgloss.Center, lipgloss.Center).
				BorderStyle(lipgloss.NormalBorder()).
				BorderForeground(lipgloss.Color("69")).
				Background(lipgloss.Color("#4B4B4B"))
)

type mainModel struct {
	state sessionState
}

func newModel() mainModel {
	m := mainModel{}
	return m
}

func (m mainModel) Init() tea.Cmd {
	return tea.Batch()
}

func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
	var cmds []tea.Cmd
	switch msg := msg.(type) {
	case tea.KeyMsg:
		switch msg.String() {
		case "ctrl+c", "q":
			return m, tea.Quit
		case "tab":
			if m.state == timerView {
				m.state = spinnerView
			} else {
				m.state = timerView
			}
		}
	}
	return m, tea.Batch(cmds...)
}

func (m mainModel) View() string {
	var s string
	example1 := strings.Repeat("AAAA", 760)
	example2 := strings.Repeat("Test", 760)
	example := []string{example1, example2}
	if m.state == timerView {
		s += lipgloss.JoinHorizontal(lipgloss.Top, focusedModelStyle.Render(example[rand.Intn(2)]), modelStyle.Render(example[rand.Intn(2)]))
	} else {
		s += lipgloss.JoinHorizontal(lipgloss.Top, modelStyle.Render(example[rand.Intn(2)]), focusedModelStyle.Render(example[rand.Intn(2)]))
	}
	return s
}

func main() {
	p := tea.NewProgram(newModel(), tea.WithAltScreen())

	if _, err := p.Run(); err != nil {
		log.Fatal(err)
	}
}

Expected behavior
Normal update without flash

Screenshots
https://github.com/charmbracelet/bubbletea/assets/107802416/4f6337cb-2d4b-44b4-ade1-c31b7866ceef

Additional context
yorukot/superfile#122

@meowgorithm
Copy link
Member

meowgorithm commented Jun 1, 2024

Hi! No ETA yet but we're actually working on a new renderer right now to addresses this very issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants