stopwatch

package
v0.16.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 31, 2023 License: MIT Imports: 3 Imported by: 36

Documentation

Overview

Package stopwatch provides a simple stopwatch component.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Model

type Model struct {

	// How long to wait before every tick. Defaults to 1 second.
	Interval time.Duration
	// contains filtered or unexported fields
}

Model for the stopwatch component.

func New

func New() Model

New creates a new stopwatch with 1s interval.

func NewWithInterval

func NewWithInterval(interval time.Duration) Model

NewWithInterval creates a new stopwatch with the given timeout and tick interval.

func (Model) Elapsed

func (m Model) Elapsed() time.Duration

Elapsed returns the time elapsed.

func (Model) ID

func (m Model) ID() int

ID returns the unique ID of the model.

func (Model) Init

func (m Model) Init() tea.Cmd

Init starts the stopwatch.

func (Model) Reset

func (m Model) Reset() tea.Cmd

Reset resets the stopwatch to 0.

func (Model) Running

func (m Model) Running() bool

Running returns true if the stopwatch is running or false if it is stopped.

func (Model) Start

func (m Model) Start() tea.Cmd

Start starts the stopwatch.

func (Model) Stop

func (m Model) Stop() tea.Cmd

Stop stops the stopwatch.

func (Model) Toggle

func (m Model) Toggle() tea.Cmd

Toggle stops the stopwatch if it is running and starts it if it is stopped.

func (Model) Update

func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)

Update handles the timer tick.

func (Model) View

func (m Model) View() string

View of the timer component.

type ResetMsg

type ResetMsg struct {
	ID int
}

ResetMsg is sent when the stopwatch should reset.

type StartStopMsg

type StartStopMsg struct {
	ID int
	// contains filtered or unexported fields
}

StartStopMsg is sent when the stopwatch should start or stop.

type TickMsg

type TickMsg struct {
	// ID is the identifier of the stopwatch that sends the message. This makes
	// it possible to determine which stopwatch a tick belongs to when there
	// are multiple stopwatches running.
	//
	// Note, however, that a stopwatch will reject ticks from other
	// stopwatches, so it's safe to flow all TickMsgs through all stopwatches
	// and have them still behave appropriately.
	ID int
}

TickMsg is a message that is sent on every timer tick.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL