Added -w
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@ -1 +1,4 @@
|
||||
bin/
|
||||
*.swp
|
||||
*.swn
|
||||
*.swo
|
||||
|
@ -48,6 +48,8 @@ The default behaviour is equivalent to 'tt -n 50'
|
||||
Custom text can be supplied by piping aribirary text to the program. Each paragraph
|
||||
in the input is shown as a separate segment of the text.
|
||||
|
||||
See -help for additional options.
|
||||
|
||||
E.G
|
||||
|
||||
- `shuf -n 40 /etc/dictionaries-common/words|tt` produces a test consisting of 40 random words drawn from `/etc/dictionaries-common/words`.
|
||||
|
8
tt.go
8
tt.go
@ -77,12 +77,16 @@ func main() {
|
||||
var n int
|
||||
var contentFn func() []string
|
||||
var oneShotMode bool
|
||||
var wrapSz int
|
||||
var err error
|
||||
|
||||
flag.IntVar(&n, "n", 50, "The number of random words which constitute the test.")
|
||||
flag.IntVar(&wrapSz, "w", 80, "Wraps the input text at the given number of columns (ignored if -raw is present)")
|
||||
|
||||
flag.BoolVar(&csvMode, "csv", false, "Print the test results to stdout in the form <wpm>,<cpm>,<accuracy>.")
|
||||
flag.BoolVar(&rawMode, "raw", false, "Don't reflow text or show one paragraph at a time.")
|
||||
flag.BoolVar(&oneShotMode, "o", false, "Automatically exit after a single run.")
|
||||
|
||||
flag.Usage = func() {
|
||||
fmt.Println(`Usage: tt [options]
|
||||
|
||||
@ -121,13 +125,13 @@ Options:`)
|
||||
content := strings.Split(strings.Trim(s, "\n"), "\n\n")
|
||||
|
||||
for i, _ := range content {
|
||||
content[i] = strings.Replace(wordWrap(strings.Trim(content[i], " "), 80), "\n", " \n", -1)
|
||||
content[i] = strings.Replace(wordWrap(strings.Trim(content[i], " "), wrapSz), "\n", " \n", -1)
|
||||
}
|
||||
|
||||
contentFn = func() []string { return content }
|
||||
}
|
||||
} else {
|
||||
contentFn = func() []string { return []string{randomText(n)} }
|
||||
contentFn = func() []string { return []string{randomText(n, wrapSz)} }
|
||||
}
|
||||
|
||||
scr, err = tcell.NewScreen()
|
||||
|
4
util.go
4
util.go
@ -50,7 +50,7 @@ func init() {
|
||||
rand.Seed(time.Now().Unix())
|
||||
}
|
||||
|
||||
func randomText(n int) string {
|
||||
func randomText(n int, ncols int) string {
|
||||
r := ""
|
||||
|
||||
words := []string{
|
||||
@ -263,7 +263,7 @@ func randomText(n int) string {
|
||||
}
|
||||
}
|
||||
|
||||
return strings.Replace(wordWrap(r, 80), "\n", " \n", -1)
|
||||
return strings.Replace(wordWrap(r, ncols), "\n", " \n", -1)
|
||||
}
|
||||
|
||||
func stringToCells(s string) []cell {
|
||||
|
Reference in New Issue
Block a user