data

package
v0.2.0-alpha Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2019 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ControlsData

type ControlsData struct {
	Content string
}

ControlsData wraps content for controls view

func NewControlsData

func NewControlsData() *ControlsData

NewControlsData creates new instance of ControlsData

func (*ControlsData) DefaultControls

func (c *ControlsData) DefaultControls()

DefaultControls sets content for default controls view

func (*ControlsData) StartRace

func (c *ControlsData) StartRace()

StartRace sets content for controls for race in progresse

type LiveStats

type LiveStats struct {
	IsActive bool // whether this data is active to show in stats view - for current race
	// contains filtered or unexported fields
}

LiveStats represents contents show during a race in stats view

func NewLiveStats

func NewLiveStats() *LiveStats

NewLiveStats creates new instance of LiveStats

func (*LiveStats) Accuracy

func (ls *LiveStats) Accuracy() (float64, error)

Accuracy of typing during a race

func (*LiveStats) ElapsedTime

func (ls *LiveStats) ElapsedTime() (*utils.TimeFormatted, error)

ElapsedTime during a race

func (*LiveStats) FinishRace

func (ls *LiveStats) FinishRace() error

FinishRace finishes a ongoing race

func (*LiveStats) SetChannels

func (ls *LiveStats) SetChannels(preceiver chan StatMsg, updateCh chan bool, finishCh chan OneStat)

SetChannels sets channels for communication

func (*LiveStats) StartRace

func (ls *LiveStats) StartRace() error

StartRace starts a new race

func (*LiveStats) TryStartTicker

func (ls *LiveStats) TryStartTicker(g *gocui.Gui)

TryStartTicker starts the ticker, so timer in stats view gets updated FIXME: anyway we can keep away from passing gocui instance?

func (*LiveStats) Wpm

func (ls *LiveStats) Wpm() (int, error)

Wpm is words per minute stat from beginning of a race

type OneStat

type OneStat struct {
	// words per minute
	Wpm int
	// accuracy. e.g., 95.6%
	Accuracy float64
	// time of race
	When time.Time
}

OneStat represents information about completed race

type ParagraphData

type ParagraphData struct {
	// words in paragraph
	Words []string

	// whether target word is mistyped
	Mistyped bool

	// true if a race is in progress
	RaceInProgress bool
	// if set the wordeditor will be cleared for next target word
	ShouldClearEditor bool

	// Dimensions of the view
	// FIXME: this shouldn't be available in viewdata
	H int
	W int
	// For highlighted word; Line, Word number both start at 0
	Line int
	Word int
	// Y position of View origin
	Oy int
	// contains filtered or unexported fields
}

ParagraphData keeps track of state, data required for view's content

func NewParagraphData

func NewParagraphData() *ParagraphData

NewParagraphData creates instance of ParagraphData

func (*ParagraphData) DebugAdvance

func (pd *ParagraphData) DebugAdvance()

DebugAdvance advances by a word to debug stuff

func (*ParagraphData) DoneCh

func (pd *ParagraphData) DoneCh() chan struct{}

DoneCh returns reference to done channel

func (*ParagraphData) FinishRace

func (pd *ParagraphData) FinishRace() error

FinishRace is called to finish a race

func (*ParagraphData) GetCurrentIdx

func (pd *ParagraphData) GetCurrentIdx() int

GetCurrentIdx tells index of target word

func (*ParagraphData) GetLineCount

func (pd *ParagraphData) GetLineCount() int

GetLineCount returns number of lines displayed in paragraph view

func (*ParagraphData) OnEditorChange

func (pd *ParagraphData) OnEditorChange(w string)

OnEditorChange is called on every change event to woreditor

func (*ParagraphData) SetChannels

func (pd *ParagraphData) SetChannels(statsCh chan StatMsg, updateCh chan bool)

SetChannels sets channels for UI, stats updates

func (*ParagraphData) StartRace

func (pd *ParagraphData) StartRace(g *gocui.Gui)

StartRace is called when a race starts

type StatMsg

type StatMsg struct {
	IsMistyped bool
	FinishRace bool
}

StatMsg is used to communicate with wordeditor

type Stats

type Stats struct {
	List     []*OneStat
	Selected int // To keep track of highlighted stat in history

	IsActive bool // whether this data is active to show in stats view - for race history
}

Stats is a datastructure to store stats for past races

func NewStatsHistory

func NewStatsHistory() (*Stats, error)

NewStatsHistory creates new Stats instance to keep track of race history

func (*Stats) LoadHistory

func (s *Stats) LoadHistory() error

LoadHistory loads history data from local FS

func (*Stats) SaveNewStat

func (s *Stats) SaveNewStat(stat *OneStat) error

SaveNewStat saves current race's stat to history of stats

func (*Stats) ScrollDown

func (s *Stats) ScrollDown(_ *gocui.Gui, _ *gocui.View) error

ScrollDown is a keybinding to scroll in race history list increments selected race index

func (*Stats) ScrollUp

func (s *Stats) ScrollUp(_ *gocui.Gui, _ *gocui.View) error

ScrollUp is a keybinding decrements selected stat index

Jump to

Keyboard shortcuts

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