controller

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrExistintgControllerError = errors.New("must remove existing controller")
View Source
var ErrNoControllerError = errors.New("must create a controller first")
View Source
var ErrPausedTimer = errors.New("cannot execute action on paused timer")
View Source
var ErrRunningTimer = errors.New("cannot execute action on running timer")
View Source
var ErrStoppedTimer = errors.New("cannot execute action on stopped timer")

Functions

This section is empty.

Types

type PomoController

type PomoController struct {
	// contains filtered or unexported fields
}

Main business logic component. Includes session for sequential state management, timer for background state change. It also sends events. pausedAt and end-of-state are for pause and status data.

func ControllerFactory

func ControllerFactory(
	options ...PomoControllerOption,
) (*PomoController, error)

Aggregator of Pomodoro Controller options and initializes pointer.

func (*PomoController) Pause

func (c *PomoController) Pause(now time.Time) error

Freeze timer in time

func (*PomoController) Play

func (c *PomoController) Play(now time.Time) error

Start paused timer or resume paused timer

func (*PomoController) Skip

func (c *PomoController) Skip(now time.Time) error

Jump to the next status inmediately

func (*PomoController) Status

Return a status report of the controller

func (*PomoController) Stop

func (c *PomoController) Stop(now time.Time) error

Reset controller to initial status

type PomoControllerContainerIface

type PomoControllerContainerIface interface {
	GetController() PomoControllerIface
	RemoveController()
}

Manages lifecycle of controller object.

type PomoControllerEventArgsNextState

type PomoControllerEventArgsNextState struct {
	At           time.Time
	CurrentState PomoControllerState
	NextState    PomoControllerState
	TimeLeft     time.Duration
}

type PomoControllerEventArgsPause

type PomoControllerEventArgsPause struct {
	At           time.Time
	CurrentState PomoControllerState
	TimeSpent    time.Duration
	TimeLeft     time.Duration
}

type PomoControllerEventArgsPlay

type PomoControllerEventArgsPlay struct {
	At                   time.Time
	CurrentState         PomoControllerState
	NextState            PomoControllerState
	CurrentStateDuration time.Duration
}

type PomoControllerEventArgsStop

type PomoControllerEventArgsStop struct {
	At           time.Time
	CurrentState PomoControllerState
	TimeSpent    time.Duration
	TimeLeft     time.Duration
}

type PomoControllerEventType

type PomoControllerEventType int
const (
	PomoControllerEventTypePlay PomoControllerEventType = iota
	PomoControllerEventTypeStop
	PomoControllerEventTypePause
	PomoControllerEventTypeNextState
)

func (PomoControllerEventType) String

func (s PomoControllerEventType) String() string

type PomoControllerIface

type PomoControllerIface interface {
	Status() PomoControllerStatus
	Pause(now time.Time) error
	Play(now time.Time) error
	Skip(now time.Time) error
	Stop(now time.Time) error
}

type PomoControllerOption

type PomoControllerOption func(*PomoController) (PomoControllerOption, error)

func PomoControllerDurationF

func PomoControllerDurationF(
	durationF func() pomoSession.SessionStateDurationFactory,
) PomoControllerOption

Sets controller duration factory from factory

func PomoControllerOptionErrorSink

func PomoControllerOptionErrorSink(errorSink func(err error)) PomoControllerOption

Sets error sinks

func PomoControllerOptionNextStateSink

func PomoControllerOptionNextStateSink(
	nextStateEventSink func(event PomoControllerEventArgsNextState),
) PomoControllerOption

Sets next state sinks

func PomoControllerOptionPauseSink

func PomoControllerOptionPauseSink(
	pauseEventSink func(event PomoControllerEventArgsPause),
) PomoControllerOption

Sets pause sinks

func PomoControllerOptionPlaySink

func PomoControllerOptionPlaySink(
	playEventSink func(event PomoControllerEventArgsPlay),
) PomoControllerOption

Sets play sinks

func PomoControllerOptionStopSink

func PomoControllerOptionStopSink(
	stopEventSink func(event PomoControllerEventArgsStop),
) PomoControllerOption

Sets stop sinks

func PomoControllerSessionOpt

func PomoControllerSessionOpt(sessionF func() pomoSession.PomoSessionIface) PomoControllerOption

Sets controller session from factory

func PomoControllerTimerOpt

func PomoControllerTimerOpt(timerF func() pomoTimer.PomoTimerIface) PomoControllerOption

Sets controller timer from factory

type PomoControllerState

type PomoControllerState int
const (
	PomoControllerWork PomoControllerState = iota
	PomoControllerShortBreak
	PomoControllerLongBreak
	PomoControllerPause
	PomoControllerStopped
)

func (*PomoControllerState) MarshalJSON

func (s *PomoControllerState) MarshalJSON() ([]byte, error)

func (PomoControllerState) String

func (s PomoControllerState) String() string

func (*PomoControllerState) UnmarshalJSON

func (s *PomoControllerState) UnmarshalJSON(b []byte) error

type PomoControllerStatus

type PomoControllerStatus struct {
	State          PomoControllerState
	TimeLeft       *StatusDuration
	PausedAt       *time.Time
	WorkedSessions int
}

type SingleControllerContainer

type SingleControllerContainer struct {
	ControllerFactory func() PomoControllerIface
	// contains filtered or unexported fields
}

Single reference instance of controller container. Creates instance of controller on first request or after delete. Typically you should call Stop() method on controller to avoid having goroutines open.

func (*SingleControllerContainer) CreateController

func (c *SingleControllerContainer) CreateController() PomoControllerIface

Create new controlle instance. Return error if one already exists

func (*SingleControllerContainer) GetController

Return existing controller. Return error if none exist

func (*SingleControllerContainer) RemoveController

func (c *SingleControllerContainer) RemoveController() error

Remove reference to instance. Return error if none exist.

type StatusDuration

type StatusDuration time.Duration

func (*StatusDuration) MarshalJSON

func (s *StatusDuration) MarshalJSON() ([]byte, error)

func (*StatusDuration) UnmarshalJSON

func (d *StatusDuration) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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