Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsValidLanguage ¶
IsValidLanguage checks if a language key is supported. Uses O(1) map lookup for performance.
Types ¶
type Category ¶
type Category struct {
ID string `json:"id"` // unique identifier (UUID)
Name string `json:"name"` // display name in library
ParentID string `json:"parentId,omitempty"` // parent for nesting (empty if root)
Icon string `json:"icon,omitempty"` // emoji for visual representation
}
Category groups texts into hierarchical collections for browsing.
type LanguageInfo ¶
type LanguageInfo struct {
Key string `json:"key"` // identifier used in Text.Language
Icon string `json:"icon"` // emoji for UI display
Label string `json:"label"` // human-readable name
}
LanguageInfo describes a supported programming language.
func SupportedLanguages ¶
func SupportedLanguages() []LanguageInfo
SupportedLanguages returns the list of supported programming languages.
type SessionPayload ¶
type SessionPayload struct {
*SessionTextMeta
Mistakes map[string]int `json:"mistakes"` // key → mistake count
WPM float64 `json:"wpm"`
CPM float64 `json:"cpm"`
Accuracy float64 `json:"accuracy"`
Duration float64 `json:"duration"` // seconds (approximation)
StartTime int64 `json:"startTime"` // milliseconds since epoch
EndTime int64 `json:"endTime"` // milliseconds since epoch
TotalErrors int `json:"totalErrors"`
TotalKeystrokes int `json:"totalKeystrokes"`
}
SessionPayload mirrors the structure sent from the GUI when a session completes.
func (*SessionPayload) ToTypingSession ¶
func (p *SessionPayload) ToTypingSession(fallback time.Time) TypingSession
ToTypingSession converts the payload to a normalized TypingSession. Any missing temporal information falls back to the provided fallback time. Metrics are clamped to valid ranges (WPM >= 0, Accuracy 0-100, etc.).
type SessionRepository ¶
type SessionRepository interface {
Record(payload *SessionPayload) (TypingSession, error)
List(limit int) ([]TypingSession, error)
}
SessionRepository defines operations for typing session history.
type SessionTextMeta ¶
type SessionTextMeta struct {
Text string `json:"text"`
TextTitle string `json:"textTitle"`
CategoryID string `json:"categoryId"`
TextID string `json:"textId"`
}
SessionTextMeta aggregates textual metadata provided by the GUI payload.
type Settings ¶
type Settings struct {
Theme string `json:"theme"` // "dark" | "light"
ShowKeyboard bool `json:"showKeyboard"` // keyboard section visibility
ShowStatsBar bool `json:"showStatsBar"` // stats bar visibility
ZenMode bool `json:"zenMode"` // focus mode (hides both keyboard and stats)
StrictMode bool `json:"strictMode"` // require backspace to fix errors (true) or allow direct correction (false)
}
Settings holds user preferences persisted in settings.json.
func DefaultSettings ¶
func DefaultSettings() Settings
DefaultSettings returns factory defaults for new installations.
type SettingsRepository ¶
type SettingsRepository interface {
Load() (Settings, error)
Save(s Settings) error
Update(key string, value any) error
}
SettingsRepository defines operations for user preferences.
type Text ¶
type Text struct {
CreatedAt time.Time `json:"createdAt"` // when the text was added
ID string `json:"id"` // unique identifier (UUID)
Title string `json:"title"` // display name in library
Content string `json:"content"` // the actual text to type
CategoryID string `json:"categoryId"` // parent category (empty if root)
Language string `json:"language"` // tokenization rules: go, js, py, plain
IsFavorite bool `json:"isFavorite"` // user-pinned for quick access
}
Text represents a single training entry available to the typing engine.
type TextLibrary ¶
type TextLibrary struct {
DefaultTextID string `json:"defaultTextId"` // text loaded on startup
Categories []Category `json:"categories"` // flat list with ParentID refs
Texts []Text `json:"texts"` // metadata; content lazy-loaded
}
TextLibrary aggregates available texts and their categories.
type TextRepository ¶
type TextRepository interface {
Library() (TextLibrary, error)
DefaultText() (Text, error)
Text(id string) (Text, error)
SaveText(text *Text) error
UpdateText(text *Text) error
DeleteText(id string) error
SaveCategory(cat *Category) error
DeleteCategory(id string) error
}
TextRepository defines operations for managing typing texts.
type TypingSession ¶
type TypingSession struct {
StartedAt time.Time `json:"startedAt"` // session start time (UTC)
CompletedAt time.Time `json:"completedAt"` // session end time (UTC)
Mistakes map[string]int `json:"mistakes,omitempty"`
TextPreview string `json:"textPreview"` // excerpt from the source text
TextTitle string `json:"textTitle"` // human readable label
CategoryID string `json:"categoryId,omitempty"`
TextID string `json:"textId,omitempty"` // optional reference to text catalog
ID string `json:"id"` // stable identifier (UUID)
WPM float64 `json:"wpm"`
CPM float64 `json:"cpm"`
Accuracy float64 `json:"accuracy"`
DurationSeconds int `json:"durationSeconds"` // whole seconds spent typing
TotalKeystrokes int `json:"totalKeystrokes"`
TotalErrors int `json:"totalErrors"`
CharacterCount int `json:"characterCount"`
}
TypingSession captures a completed typing attempt for historical analytics.