diff --git a/README.md b/README.md index 439ca6a..30e74f1 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ A terminal based typing test. ![](demo.gif) +By default, generated word lists now include random common punctuation (periods, commas, semicolons, etc.) after some words for a more natural typing experience. + # Installation ## Linux diff --git a/man.md b/man.md index aa593ad..a0d64b2 100644 --- a/man.md +++ b/man.md @@ -21,6 +21,8 @@ usage: tt \[OPTION\]... \[FILE\] test. Each paragraph of the input is treated as a segment unless '-multi' is supplied in which case each paragraph is treated as a separate test. + By default, generated word lists now include random common punctuation (periods, commas, semicolons, etc.) after some words for a more natural typing experience. + # OPTIONS ## Modes diff --git a/src/util.go b/src/util.go index 66f005b..75bc2f3 100644 --- a/src/util.go +++ b/src/util.go @@ -25,7 +25,7 @@ func init() { } type cell struct { - c rune + c rune style tcell.Style } @@ -84,13 +84,24 @@ func randomText(n int, words []string) string { r := "" var last string + punctuations := []string{"", ".", ",", ";", ":", "?", "!", ")", "]", "}", "(", "[", "{", `"`, "'"} + for i := 0; i < n; i++ { w := words[rand.Int()%len(words)] for last == w { w = words[rand.Int()%len(words)] } - r += w + punct := "" + + // Only add punctuation if: + // - it's the 6th word in a group (i+1 % 6 == 0) + // - and NOT the last word overall + if (i+1)%6 == 0 && i != n-1 { + punct = punctuations[rand.Int()%len(punctuations)] + } + + r += w + punct if i != n-1 { r += " " }