Skip to content

Commit

Permalink
add punctuation
Browse files Browse the repository at this point in the history
  • Loading branch information
dustin-ward committed Mar 5, 2024
1 parent a1bbcee commit f9061d5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ 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 := ""
line_len := 0
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 {
Expand Down
13 changes: 11 additions & 2 deletions internal/data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@ 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)
}
}

// 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
}

0 comments on commit f9061d5

Please sign in to comment.