ui

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

WARN:NOTES in this files are important! otehrwise it'll re-render exponentially on type!

Index

Constants

View Source
const (
	GameModeNormal = "normal"
	GameModeSimple = "simple"

	TextLengthShort    = "short"     // 1
	TextLengthMedium   = "medium"    // 2
	TextLengthLong     = "long"      // 3
	TextLengthVeryLong = "very long" // 5
)
View Source
const (
	MenuMain int = iota
	MenuSettings
)
View Source
const (
	Padding  = 2
	MaxWidth = 80
)
View Source
const (
	SampleTextNormal = "" /* 261-byte string literal not displayed */

	SampleTextNormalWithNumbers = "The quick brown fox jumps over the 5 lazy dogs. In 2023, "

	SampleTextSimple = "" /* 263-byte string literal not displayed */

	SampleTextSimpleWithNumbers = "" /* 307-byte string literal not displayed */
)
View Source
const (
	ThemeDefault    = "default"
	ThemeDark       = "dark"
	ThemeMonochrome = "monochrome"
)

Variables

View Source
var BlockCursorStyle lipgloss.Style
View Source
var CenterStyle lipgloss.Style
View Source
var (
	DebugEnabled = false
)
View Source
var DefaultSettings = UserSettings{
	ThemeName:      "default",
	CursorType:     "block",
	GameMode:       GameModeNormal,
	UseNumbers:     true,
	TextLength:     TextLengthShort,
	HasSeenWelcome: false,
	RefreshRate:    10,
}
View Source
var DefaultTheme = ThemeColors{

	HelpText: "#626262",
	Timer:    "#FFDB58",
	Border:   "#7F9ABE",

	TextDim:          "#555555",
	TextPreview:      "#7F9ABE",
	TextCorrect:      "#00FF00",
	TextError:        "#FF0000",
	TextPartialError: "#FF8C00",

	CursorFg:        "#FFFFFF",
	CursorBg:        "#00AAFF",
	CursorUnderline: "#00AAFF",

	Padding: "#888888",
}
View Source
var DimStyle lipgloss.Style
View Source
var EndGameAccuracyStyle lipgloss.Style
View Source
var EndGameCorrectStyle lipgloss.Style
View Source
var EndGameErrorsStyle lipgloss.Style
View Source
var EndGameOptionStyle lipgloss.Style
View Source
var EndGameSelectedOptionStyle lipgloss.Style
View Source
var EndGameStatsBoxStyle lipgloss.Style
View Source
var EndGameTitleStyle lipgloss.Style
View Source
var EndGameWordsStyle lipgloss.Style
View Source
var EndGameWpmStyle lipgloss.Style
View Source
var ErrorStyle lipgloss.Style
View Source
var GradientColors = []string{
	"#00ADD8",
	"#15B5DB",
	"#2ABEDE",
	"#3FC6E1",
	"#54CFE4",
	"#69D7E7",
	"#7EE0EA",
	"#93E8ED",
	"#A8F1F0",
	"#BDF9F3",
	"#D2FFF6",
	"#E7FFF9",
	"#FCFFFC",
	"#E7FFF9",
	"#D2FFF6",
	"#BDF9F3",
	"#A8F1F0",
	"#93E8ED",
	"#7EE0EA",
	"#69D7E7",
	"#54CFE4",
	"#3FC6E1",
	"#2ABEDE",
	"#15B5DB",
}
View Source
var HelpStyle func(...string) string
View Source
var HintStyle func(...string) string
View Source
var InputStyle lipgloss.Style
View Source
var PadStyle lipgloss.Style
View Source
var PartialErrorStyle lipgloss.Style
View Source
var PreviewStyle lipgloss.Style
View Source
var SettingsDetailsStyle lipgloss.Style
View Source
var SettingsHelpStyle lipgloss.Style
View Source
var SettingsListStyle lipgloss.Style
View Source
var SettingsStyle func(...string) string
View Source
var SettingsTitleStyle lipgloss.Style
View Source
var TextContainerStyle lipgloss.Style
View Source
var TextToTypeStyle lipgloss.Style
View Source
var TimerStyle lipgloss.Style
View Source
var UnderlineCursorStyle lipgloss.Style

Functions

func ApplySettings

func ApplySettings()

func CloseDebugLog

func CloseDebugLog()

func DebugLog

func DebugLog(format string, args ...interface{})

func GetColor

func GetColor(colorName string) lipgloss.Color

func GetConfigDir

func GetConfigDir() (string, error)

func GetGradientIndex

func GetGradientIndex(tickTime time.Time) int

func GetRandomText

func GetRandomText() string

func GetRefreshInterval

func GetRefreshInterval() time.Duration

func GetSampleText

func GetSampleText() string

func GetSettingsFilePath

func GetSettingsFilePath() (string, error)

func GetThemePath

func GetThemePath(themeName string) string

func GlobalTickCmd

func GlobalTickCmd(interval time.Duration) tea.Cmd

func HandleGlobalTick

func HandleGlobalTick(lastTick time.Time, msg GlobalTickMsg) (time.Time, bool, tea.Cmd)

func InitDebugLog

func InitDebugLog()

func InitGlobalTick

func InitGlobalTick() tea.Cmd

func InitSettings

func InitSettings()

func InitTheme

func InitTheme()

func ListAvailableThemes

func ListAvailableThemes() []string

func LoadSettings

func LoadSettings() error

func LoadTheme

func LoadTheme(themeNameOrPath string) error

func ReloadTheme

func ReloadTheme(filePath string) error

func RenderGradientOverlay

func RenderGradientOverlay(text string, baseStyle lipgloss.Style, tickTime time.Time) string

func RenderGradientText

func RenderGradientText(text string, tickTime time.Time) string

func RunStartScreen

func RunStartScreen()

func RunTypingGame

func RunTypingGame()

func SaveSettings

func SaveSettings() error

func ShowSettings added in v1.0.3

func ShowSettings() error

func ShowWelcomeScreen

func ShowWelcomeScreen() bool

func StartLoading

func StartLoading(cmd *cobra.Command, args []string)

func StartLoadingWithOptions

func StartLoadingWithOptions(cursorTypeStr string)

func StartTypingGame

func StartTypingGame(width, height int, text string) tea.Model

func UpdateSettings

func UpdateSettings(settings UserSettings) error

func UpdateStyles

func UpdateStyles()

Types

type BibleSource

type BibleSource struct {
	URL string
}

func NewBibleSource

func NewBibleSource() *BibleSource

func (*BibleSource) FetchText

func (s *BibleSource) FetchText() (string, error)

func (*BibleSource) FormatText

func (s *BibleSource) FormatText(text string) string

type Cursor

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

func NewCursor

func NewCursor(style CursorType) *Cursor

func (*Cursor) Render

func (c *Cursor) Render(char rune) string

type CursorType

type CursorType int
const (
	BlockCursor CursorType = iota
	UnderlineCursor
)
var DefaultCursorType CursorType = BlockCursor

type EndGameModel

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

func NewEndGameModel

func NewEndGameModel(wpm, accuracy float64, words, correct, errors int, text string) *EndGameModel

func (*EndGameModel) Init

func (m *EndGameModel) Init() tea.Cmd

func (*EndGameModel) Update

func (m *EndGameModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*EndGameModel) View

func (m *EndGameModel) View() string

type GlobalTickMsg

type GlobalTickMsg time.Time

type LoadingModel

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

func NewLoadingModel

func NewLoadingModel() *LoadingModel

func (*LoadingModel) Init

func (m *LoadingModel) Init() tea.Cmd

func (*LoadingModel) Update

func (m *LoadingModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*LoadingModel) View

func (m *LoadingModel) View() string

type SettingsItem added in v1.0.3

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

func (SettingsItem) Description added in v1.0.3

func (i SettingsItem) Description() string

func (SettingsItem) FilterValue added in v1.0.3

func (i SettingsItem) FilterValue() string

func (SettingsItem) Title added in v1.0.3

func (i SettingsItem) Title() string

type SettingsModel added in v1.0.3

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

func (SettingsModel) Init added in v1.0.3

func (m SettingsModel) Init() tea.Cmd

func (SettingsModel) Update added in v1.0.3

func (m SettingsModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (SettingsModel) View added in v1.0.3

func (m SettingsModel) View() string

type Spinner

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

func NewSpinner

func NewSpinner() *Spinner

func (*Spinner) Update

func (s *Spinner) Update()

func (*Spinner) View

func (s *Spinner) View() string

type StartGameMsg

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

type StartScreenModel

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

func NewStartScreenModel

func NewStartScreenModel() *StartScreenModel

func (*StartScreenModel) Init

func (m *StartScreenModel) Init() tea.Cmd

func (*StartScreenModel) Update

func (m *StartScreenModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*StartScreenModel) View

func (m *StartScreenModel) View() string

type Text

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

func NewText

func NewText(text string) *Text

func (*Text) Backspace

func (t *Text) Backspace()

func (*Text) CurrentWord

func (t *Text) CurrentWord() *Word

func (*Text) GetCursorPos

func (t *Text) GetCursorPos() int

func (*Text) GetText

func (t *Text) GetText() string

func (*Text) IsComplete

func (t *Text) IsComplete() bool

func (*Text) Render

func (t *Text) Render() string

func (*Text) SetCursorType

func (t *Text) SetCursorType(cursorType CursorType)

func (*Text) Stats

func (t *Text) Stats() (total, correct, errors int)

func (*Text) Type

func (t *Text) Type(r rune)

func (*Text) Update

func (t *Text) Update()

type TextSource

type TextSource interface {
	FetchText() (string, error)
	FormatText(text string) string
}

type ThemeColors

type ThemeColors struct {
	HelpText string `yaml:"help_text"`
	Timer    string `yaml:"timer"`
	Border   string `yaml:"border"`

	TextDim          string `yaml:"text_dim"`
	TextPreview      string `yaml:"text_preview"`
	TextCorrect      string `yaml:"text_correct"`
	TextError        string `yaml:"text_error"`
	TextPartialError string `yaml:"text_partial_error"`

	CursorFg        string `yaml:"cursor_fg"`
	CursorBg        string `yaml:"cursor_bg"`
	CursorUnderline string `yaml:"cursor_underline"`

	Padding string `yaml:"padding"`
}
var CurrentTheme ThemeColors

type TypingModel

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

func NewTypingModel

func NewTypingModel(width, height int, text string) *TypingModel

func (*TypingModel) Init

func (m *TypingModel) Init() tea.Cmd

func (*TypingModel) Update

func (m *TypingModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*TypingModel) View

func (m *TypingModel) View() string

type UserSettings

type UserSettings struct {
	ThemeName      string `json:"theme"`
	CursorType     string `json:"cursor_type"`
	GameMode       string `json:"game_mode"`
	UseNumbers     bool   `json:"use_numbers"`
	TextLength     string `json:"text_length"`
	HasSeenWelcome bool   `json:"has_seen_welcome"`
	RefreshRate    int    `json:"refresh_rate"` // NOTE:in frames per second not tick
}
var CurrentSettings UserSettings

type WelcomeModel

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

func NewWelcomeModel

func NewWelcomeModel() *WelcomeModel

func (*WelcomeModel) Init

func (m *WelcomeModel) Init() tea.Cmd

func (*WelcomeModel) Update

func (m *WelcomeModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*WelcomeModel) View

func (m *WelcomeModel) View() string

type Word

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

func NewWord

func NewWord(target []rune) *Word

func (*Word) Backspace

func (w *Word) Backspace() bool

func (*Word) HasStarted

func (w *Word) HasStarted() bool

func (*Word) IsComplete

func (w *Word) IsComplete() bool

func (*Word) IsSpace

func (w *Word) IsSpace() bool

func (*Word) Render

func (w *Word) Render(showCursor bool) string

func (*Word) SetActive

func (w *Word) SetActive(active bool)

func (*Word) SetCursorType

func (w *Word) SetCursorType(cursorType CursorType)

func (*Word) Skip

func (w *Word) Skip()

func (*Word) Type

func (w *Word) Type(r rune)

type WordState

type WordState int
const (
	Untyped WordState = iota
	Perfect
	Imperfect
	Error
)

type ZenQuotesSource

type ZenQuotesSource struct {
	URL string
}

func NewZenQuotesSource

func NewZenQuotesSource() *ZenQuotesSource

func (*ZenQuotesSource) FetchText

func (s *ZenQuotesSource) FetchText() (string, error)

func (*ZenQuotesSource) FormatText

func (s *ZenQuotesSource) FormatText(text string) string

Jump to

Keyboard shortcuts

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