From 57453fa4ca7669da6ee062ac061f1adb5974ba91 Mon Sep 17 00:00:00 2001 From: Juan Monroy-Nieto Date: Fri, 23 Jun 2023 15:20:56 -0700 Subject: [PATCH 1/5] Teminate report w/t space and enter too --- src/tt.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tt.go b/src/tt.go index aba3ada..bd673e4 100644 --- a/src/tt.go +++ b/src/tt.go @@ -110,7 +110,9 @@ func showReport(scr tcell.Screen, cpm, wpm int, accuracy float64, attribution st scr.Show() for { - if key, ok := scr.PollEvent().(*tcell.EventKey); ok && key.Key() == tcell.KeyEscape { + key, ok := scr.PollEvent().(*tcell.EventKey) + + if ok && (key.Key() == tcell.KeyEscape || key.Key() == tcell.KeyEnter || key.Rune() == 32) { return } else if ok && key.Key() == tcell.KeyCtrlC { exit(1) From 661ab3046a2305479cf0c6699ffed4ff7e7986a1 Mon Sep 17 00:00:00 2001 From: Juan Monroy-Nieto Date: Fri, 23 Jun 2023 16:07:12 -0700 Subject: [PATCH 2/5] Adds explanation of keys in report --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 439ca6a..e3a106c 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ options. ## Keys - Pressing `escape` at any point restarts the test. +- In the report page `escape`, `enter`, and `space` will close the page and load the next test. If flag `-oneshot` is enabled, the program terminates. - `C-c` exits the test. - `right` moves to the next test. - `left` moves to the previous test. From 1decfad3228cdb8c37fbc16ca34484dd5c480a4b Mon Sep 17 00:00:00 2001 From: Juan Monroy-Nieto Date: Fri, 23 Jun 2023 16:55:58 -0700 Subject: [PATCH 3/5] clear instructions on report --- src/tt.go | 11 ++++++----- src/util.go | 10 ++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/tt.go b/src/tt.go index bd673e4..5f5f4dc 100644 --- a/src/tt.go +++ b/src/tt.go @@ -86,7 +86,7 @@ func exit(rc int) { os.Exit(rc) } -func showReport(scr tcell.Screen, cpm, wpm int, accuracy float64, attribution string, mistakes []mistake) { +func showReport(scr tcell.Screen, cpm, wpm int, accuracy float64, attribution string, mistakes []mistake, titleStyle tcell.Style) { mistakeStr := "" if attribution != "" { attribution = "\n\nAttribution: " + attribution @@ -106,12 +106,13 @@ func showReport(scr tcell.Screen, cpm, wpm int, accuracy float64, attribution st scr.Clear() drawStringAtCenter(scr, report, tcell.StyleDefault) + drawStringAsTitle(scr, "Press ESC, SPACE, or ENTER to continue.", titleStyle) scr.HideCursor() scr.Show() for { key, ok := scr.PollEvent().(*tcell.EventKey) - + if ok && (key.Key() == tcell.KeyEscape || key.Key() == tcell.KeyEnter || key.Rune() == 32) { return } else if ok && key.Key() == tcell.KeyCtrlC { @@ -385,7 +386,7 @@ func main() { typer.ShowWpm = showWpm if timeout != -1 { - timeout *= 1E9 + timeout *= 1e9 } var tests [][]segment @@ -417,7 +418,7 @@ func main() { idx-- } case TyperComplete: - cpm := int(float64(ncorrect) / (float64(t) / 60E9)) + cpm := int(float64(ncorrect) / (float64(t) / 60e9)) wpm := cpm / 5 accuracy := float64(ncorrect) / float64(nerrs+ncorrect) * 100 @@ -427,7 +428,7 @@ func main() { if len(tests[idx]) == 1 { attribution = tests[idx][0].Attribution } - showReport(scr, cpm, wpm, accuracy, attribution, mistakes) + showReport(scr, cpm, wpm, accuracy, attribution, mistakes, typer.nextWordStyle) } if oneShotMode { exit(0) diff --git a/src/util.go b/src/util.go index 66f005b..9bad02a 100644 --- a/src/util.go +++ b/src/util.go @@ -147,6 +147,16 @@ func drawStringAtCenter(scr tcell.Screen, s string, style tcell.Style) { drawString(scr, x, y, s, -1, style) } +func drawStringAsTitle(scr tcell.Screen, s string, style tcell.Style) { + nc, nr := calcStringDimensions(s) + sw, sh := scr.Size() + + x := (sw - nc) / 2 + y := sh - (sh - nr) + + drawString(scr, x, y, s, -1, style) +} + func calcStringDimensions(s string) (nc, nr int) { if s == "" { return 0, 0 From 02304818d8576c7d744288f8467af72f37e4cb33 Mon Sep 17 00:00:00 2001 From: Juan Monroy-Nieto Date: Fri, 23 Jun 2023 18:55:47 -0700 Subject: [PATCH 4/5] Fixes capturing spaces and newlines when test is finished --- src/tt.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/tt.go b/src/tt.go index 5f5f4dc..0fcdecb 100644 --- a/src/tt.go +++ b/src/tt.go @@ -87,6 +87,28 @@ func exit(rc int) { } func showReport(scr tcell.Screen, cpm, wpm int, accuracy float64, attribution string, mistakes []mistake, titleStyle tcell.Style) { + //consumes last key presses to avoid space press + + scr.Clear() + scr.Show() + hold := make(chan tcell.Event) + go func(hold chan tcell.Event) { + discard := make(chan<- tcell.Event) + for { + select { + case discard <- scr.PollEvent(): + { + + } + case <-time.After(300 * time.Millisecond): + close(discard) + close(hold) + return + + } + } + }(hold) + <-hold mistakeStr := "" if attribution != "" { attribution = "\n\nAttribution: " + attribution @@ -104,7 +126,6 @@ func showReport(scr tcell.Screen, cpm, wpm int, accuracy float64, attribution st report := fmt.Sprintf("WPM: %d\nCPM: %d\nAccuracy: %.2f%%%s%s", wpm, cpm, accuracy, mistakeStr, attribution) - scr.Clear() drawStringAtCenter(scr, report, tcell.StyleDefault) drawStringAsTitle(scr, "Press ESC, SPACE, or ENTER to continue.", titleStyle) scr.HideCursor() From 7dfd6b07b4c5dc648999c3512e6db4e7fb4759be Mon Sep 17 00:00:00 2001 From: Juan MONROY-NIETO <10119293+jmonroynieto@users.noreply.github.com> Date: Fri, 23 Jun 2023 19:09:49 -0700 Subject: [PATCH 5/5] Improves key instructions --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e3a106c..2e4ff58 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ options. ## Keys - Pressing `escape` at any point restarts the test. -- In the report page `escape`, `enter`, and `space` will close the page and load the next test. If flag `-oneshot` is enabled, the program terminates. +- `escape`, `enter`, or `space` will close the report page. If `-oneshot` is not set, the next test is loaded. - `C-c` exits the test. - `right` moves to the next test. - `left` moves to the previous test.