From f9061d565864f849e361e48599e4764eb0e6c85f Mon Sep 17 00:00:00 2001 From: dustin-ward Date: Mon, 4 Mar 2024 19:53:00 -0500 Subject: [PATCH] add punctuation --- internal/app/app.go | 3 ++- internal/data/data.go | 13 +++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/internal/app/app.go b/internal/app/app.go index dd6f4b6..59e20e0 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -32,6 +32,7 @@ type AppModel struct { // Number of words to use per each test const NUM_WORDS = 20 +const PUNC_CHANCE = 0.2 func NewAppModel(init_state AppState) tea.Model { text := "" @@ -39,7 +40,7 @@ func NewAppModel(init_state AppState) tea.Model { lines := 0 for i := 0; i < NUM_WORDS; i++ { // Pull random word from data - word := data.GetWord() + " " + word := data.GetWord(PUNC_CHANCE) + " " // Manually insert newlines if line_len+len(word) >= styles.APP_WIDTH-4 { diff --git a/internal/data/data.go b/internal/data/data.go index 0277968..6db7b46 100644 --- a/internal/data/data.go +++ b/internal/data/data.go @@ -11,6 +11,8 @@ import ( var words_english_json []byte var words_english []string +var punctuation string = ".,?!;:" + func init() { if err := json.Unmarshal(words_english_json, &words_english); err != nil { log.Fatal("data/init:", err) @@ -18,6 +20,13 @@ func init() { } // Return random word from dataset -func GetWord() string { - return words_english[rand.Intn(len(words_english))] +func GetWord(punctuation_chance float64) string { + word := words_english[rand.Intn(len(words_english))] + + if rand.Float64() < punctuation_chance { + p := punctuation[rand.Intn(len(punctuation))] + word += string(p) + } + + return word }