timer

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 37 Imported by: 0

Documentation

Overview

Package timer operates the Focus countdown timer and handles the recovery of interrupted timers

Index

Constants

View Source
const DefaultBufferSize = 10

DefaultBufferSize controls audio buffering.

Variables

This section is empty.

Functions

This section is empty.

Types

type Remainder

type Remainder struct {
	T int // total
	M int // minutes
	S int // seconds
}

Remainder is the time remaining in an active session.

type SessParams

type SessParams map[config.SessionType]struct {
	Message  string
	Duration time.Duration
}

type Session

type Session struct {
	StartTime time.Time          `json:"start_time"`
	EndTime   time.Time          `json:"end_time"`
	Name      config.SessionType `json:"name"`
	Tags      []string           `json:"tags"`
	Timeline  []Timeline         `json:"timeline"`
	Duration  time.Duration      `json:"duration"`
	Completed bool               `json:"completed"`
}

Session represents an active work or break session.

func (*Session) Adjust

func (s *Session) Adjust(since time.Time)

func (*Session) ElapsedTimeInSeconds

func (s *Session) ElapsedTimeInSeconds() float64

ElapsedTimeInSeconds returns the time elapsed for the current session in seconds using monotonic timings.

func (*Session) IsResuming

func (s *Session) IsResuming() bool

IsResuming determines if a session is being resumed or not.

func (*Session) Normalise

func (s *Session) Normalise()

Normalise ensures that the end time for the current session perfectly correlates with what is required to complete the session. It mostly helps with normalising the end time when the system is suspended with a session in progress, and resumed at a later time in the future that surpasses the normal end time.

func (*Session) RealElapsedTimeInSeconds

func (s *Session) RealElapsedTimeInSeconds() float64

RealElapsedTimeInSeconds returns the time elapsed for the current session in seconds using real timings.

func (*Session) Remaining

func (s *Session) Remaining() Remainder

Remaining calculates the time remaining for the session to end.

func (*Session) SetEndTime

func (s *Session) SetEndTime()

SetEndTime calculates the end time for the current session.

func (*Session) ToDBModel

func (s *Session) ToDBModel() *models.Session

ToDBModel converts an active session to a database model.

func (*Session) UpdateEndTime

func (s *Session) UpdateEndTime(isCompleted bool)

UpdateEndTime sets the session end time to the current time.

type Timeline

type Timeline struct {
	// StartTime is the start of the session including
	// the start of a paused session
	StartTime time.Time `json:"start_time"`
	// EndTime is the end of a session including
	// when a session is paused or stopped prematurely
	EndTime time.Time `json:"end_time"`
}

type Timer

type Timer struct {
	SoundStream beep.Streamer `json:"-"`

	Opts        *config.Config `json:"opts"`
	CurrentSess *Session

	SessParams SessParams

	WorkCycle int `json:"work_cycle"`
	// contains filtered or unexported fields
}

Timer represents a running timer.

func New

func New(dbClient store.DB, cfg *config.Config) *Timer

New creates a new timer.

func (*Timer) Init

func (t *Timer) Init() tea.Cmd

Init initializes the timer for an interactive session, setting up the current session and its clock. It handles the special case where a completed session was added via --since reporting the successful addition and then exiting the application. Otherwise, for a new interactive session, it returns a command to initialize the timer's internal clock.

func (*Timer) ReportStatus

func (t *Timer) ReportStatus() error

ReportStatus reports the status of the currently running timer.

func (*Timer) Update

func (t *Timer) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*Timer) View

func (t *Timer) View() string

Jump to

Keyboard shortcuts

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