words

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package words produces target strings for typing tests. It embeds a common-English word list and a curated quote pack so that the binary has no runtime filesystem or network dependencies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForMode

func ForMode(g *Generator, mode config.Mode, length int, ql QuoteLen) string

ForMode returns the target string for a typing test given the active mode and user-selected length. It is the primary entry point for Phase 4.

  • ModeTime: length is the test duration in seconds (15/30/60/120); ForMode returns a large word buffer sized for the longest session. The length parameter is accepted for signature uniformity but does not affect buffer size — TimeBuffer always overshoots the maximum duration.
  • ModeWords: length is the word count (10/25/50/100); returns exactly that many space-separated words.
  • ModeQuote: ql selects the desired quote bucket; length is ignored.

Types

type Generator

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

Generator is a seedable random word/quote source. Construct one with NewGenerator; the zero value is not valid.

func NewGenerator

func NewGenerator(seed int64) *Generator

NewGenerator returns a Generator seeded with seed. If seed is 0 a unique time-based seed is chosen so each run differs.

func (*Generator) Quote

func (g *Generator) Quote(l QuoteLen) Quote

Quote returns a random quote from the requested bucket using g's RNG. If the requested bucket is empty it falls back to the nearest non-empty bucket (medium → short → long).

func (*Generator) TimeBuffer

func (g *Generator) TimeBuffer() string

TimeBuffer returns a large pool of space-separated words sized to outlast a 120-second test at high typing speed (timeBufferWords words). The caller (Phase 4 typing screen) may call TimeBuffer again to extend the pool if the user somehow exhausts it.

func (*Generator) Words

func (g *Generator) Words(n int) string

Words returns n space-separated words drawn at random from the embedded word list. When n <= 0 an empty string is returned.

type Quote

type Quote struct {
	Text   string
	Source string
	Bucket QuoteLen
}

Quote is a single curated quote with attribution.

type QuoteLen

type QuoteLen int

QuoteLen classifies a quote by its rune length.

const (
	// QuoteShort: text < 100 runes.
	QuoteShort QuoteLen = iota
	// QuoteMedium: 100 <= text < 250 runes.
	QuoteMedium
	// QuoteLong: text >= 250 runes.
	QuoteLong
)

Jump to

Keyboard shortcuts

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