utils

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: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendLineEOF

func AppendLineEOF(fname, line string) error

AppendLineEOF appends a given line to end of a file

func CalculateAccuracy

func CalculateAccuracy(chars int, mistypes int) (float64, error)

CalculateAccuracy calculates accuracy in a race based on chars typed so far and mistyped chars

func CalculateWpm

func CalculateWpm(countCh int, secs float64) int

CalculateWpm calculates words per minute based on words typed so far and time elapsed

func CreateDirIfNotExists

func CreateDirIfNotExists(dpath string) error

CreateDirIfNotExists creates directory path if not exists

func CreateFileIfNotExists

func CreateFileIfNotExists(fpath string) error

CreateFileIfNotExists creates file if not exists

func FormatDate

func FormatDate(t time.Time) string

FormatDate formats time into DD-MM-YYYY format

func GetHomeDir

func GetHomeDir() (string, error)

GetHomeDir returns absolute path to Home directory

func Tick

func Tick(t *Timer, forceUpdateChan chan bool, g *gocui.Gui)

Tick starts the ticker

func UpdateUI

func UpdateUI(g *gocui.Gui)

UpdateUI updates the UI used when we want to manually/force update the UI

func WriteToFile

func WriteToFile(fpath string, data []byte) error

WriteToFile writes to a file at a given path

Types

type TimeFormatted

type TimeFormatted struct {
	Mins, Secs int
}

TimeFormatted wraps time.Duration converted to mins:seconds format

type Timer

type Timer struct {

	// used in ticker.go to tick update gocui
	Ticking bool
	// contains filtered or unexported fields
}

Timer is a stopwatch like functionality Doesn't use ticking mechanism, but keeps tracks of start time to figure the elapsed time

func NewTimer

func NewTimer() *Timer

NewTimer creates and returns new timer instance

func (*Timer) ElapsedTime

func (t *Timer) ElapsedTime() (*TimeFormatted, error)

ElapsedTime is time the timer has been active for returns error if timer is not active

func (*Timer) ElapsedTimeInSecs

func (t *Timer) ElapsedTimeInSecs() (float64, error)

ElapsedTimeInSecs gives elapsed seconds float64 because we could have 1.5sec

func (*Timer) IsActive

func (t *Timer) IsActive() bool

IsActive returns true if timer is active

func (*Timer) Start

func (t *Timer) Start() error

Start starts the timer

func (*Timer) Stop

func (t *Timer) Stop() error

Stop stops the timer

Jump to

Keyboard shortcuts

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