timer

package
v0.10.7 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package timer provides a simple timeout 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 until the timer expires.
	Timeout time.Duration

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

Model of the timer component.

func New

func New(timeout time.Duration) Model

New creates a new timer with the given timeout and default 1s interval.

func NewWithInterval

func NewWithInterval(timeout, interval time.Duration) Model

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

func (Model) ID added in v0.10.5

func (m Model) ID() int

ID returns the model's identifier. This can be used to determine if messages belong to this timer instance when there are multiple timers.

func (Model) Init

func (m Model) Init() tea.Cmd

Init starts the timer.

func (Model) Running added in v0.10.5

func (m Model) Running() bool

Running returns whether or not the timer is running. If the timer has timed out this will always return false.

func (*Model) Start added in v0.10.5

func (m *Model) Start() tea.Cmd

Start resumes the timer. Has no effect if the timer has timed out.

func (*Model) Stop added in v0.10.5

func (m *Model) Stop() tea.Cmd

Stop pauses the timer. Has no effect if the timer has timed out.

func (Model) Timedout added in v0.10.5

func (m Model) Timedout() bool

Timedout returns whether or not the timer has timed out.

func (*Model) Toggle added in v0.10.5

func (m *Model) Toggle() tea.Cmd

Toggle stops the timer if it's running and starts it if it's 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 StartStopMsg added in v0.10.5

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

StartStopMsg is used to start and stop the timer.

type TickMsg

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

	// Timeout returns whether or not this tick is a timeout tick. You can
	// alternatively listen for TimeoutMsg.
	Timeout bool
}

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

type TimeoutMsg

type TimeoutMsg struct {
	ID int
}

TimeoutMsg is a message that is sent once when the timer times out.

It's a convenience message sent alongside a TickMsg with the Timeout value set to true.

Jump to

Keyboard shortcuts

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