From 0e4414ad277c41fe64c92da07b16d9f7628bdfab Mon Sep 17 00:00:00 2001 From: Aetnaeus Date: Thu, 24 Dec 2020 19:53:47 -0500 Subject: [PATCH] Added -w --- .gitignore | 3 +++ README.md | 2 ++ tt.go | 8 ++++++-- util.go | 4 ++-- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index e660fd9..a8a19c4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ bin/ +*.swp +*.swn +*.swo diff --git a/README.md b/README.md index 247b320..fc2dba8 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/tt.go b/tt.go index 10c7214..dc32fd0 100644 --- a/tt.go +++ b/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 ,,.") 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() diff --git a/util.go b/util.go index c56ff13..84a6d56 100644 --- a/util.go +++ b/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 {