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

Starting stopwatch multiple times increases speed #661

Open
ipsavitsky opened this issue Nov 5, 2024 · 0 comments
Open

Starting stopwatch multiple times increases speed #661

ipsavitsky opened this issue Nov 5, 2024 · 0 comments

Comments

@ipsavitsky
Copy link

Describe the bug
When applying multiple stopwatch.Start commands, stopwatch starts ticking faster with each one.

Setup
Please complete the following information along with version numbers, if applicable.

  • OS Ubuntu
  • Shell bash
  • Terminal Emulator kitty
  • Terminal Multiplexer zellij
  • Locale en_US.UTF-8

To Reproduce
Steps to reproduce the behavior:

  1. Compile code
  2. Run program
  3. Press enter a couple times, sending a Start command with each one

Source Code

package main

import (
	"log"

	"github.com/charmbracelet/bubbles/stopwatch"
	tea "github.com/charmbracelet/bubbletea"
)

func main() {
	p := tea.NewProgram(initialModel())

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

type model struct {
	stopwatch stopwatch.Model
}

func initialModel() model {
	return model{
		stopwatch: stopwatch.New(),
	}
}

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

func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
	var cmds []tea.Cmd
	var cmd tea.Cmd

	switch msg := msg.(type) {
	case tea.KeyMsg:
		switch msg.Type {
		case tea.KeyEnter:
			cmds = append(cmds, m.stopwatch.Start())
		case tea.KeyCtrlC:
			return m, tea.Quit
		}
	}

	m.stopwatch, cmd = m.stopwatch.Update(msg)
	cmds = append(cmds, cmd)
	return m, tea.Batch(cmds...)
}

func (m model) View() string {
	return m.stopwatch.View()
}

Expected behavior
Stopwatch starts with the first press of enter and keeps running at expected speed with every subsequent Start message

Screenshots
demo

Additional context
The vhs tape for the above gif is

Output demo.gif

Show

Type ./bubbles_bugreport

Enter

Sleep 3s

Enter
Enter
Enter
Enter

Sleep 10

Somehow, the TickMsg get stacked with every Start() call

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

1 participant