@@ -16,10 +16,10 @@ import (
16
16
// Structure for our options and state.
17
17
type watchCommand struct {
18
18
19
- // delay contains the number of seconds to sleep before updating our command
19
+ // delay contains the number of seconds to sleep before updating our command.
20
20
delay int
21
21
22
- // count increments once every second
22
+ // count increments once every second.
23
23
count int
24
24
}
25
25
@@ -35,20 +35,17 @@ func (w *watchCommand) Info() (string, string) {
35
35
Details:
36
36
37
37
This command allows you execute a command every five seconds,
38
- and see the output.
38
+ and see the most recent output.
39
39
40
40
It is included because Mac OS does not include a watch-command
41
41
by default.
42
42
43
- Notes:
43
+ The display uses the tview text-based user interface package, to
44
+ present a somewhat graphical display - complete with an updating
45
+ run-timer.
44
46
45
- Between executing the specified command the utility will
46
- clear thes creen by executing 'cls' or 'clear', which is
47
- a terrible approach.
47
+ To exit the application you may press 'q', 'Escape', or Ctrl-c.
48
48
49
- In the future this command might be reimplemented using
50
- a TUI instead, to avoid this, but for the moment it is a quick
51
- hack.
52
49
`
53
50
}
54
51
@@ -97,6 +94,19 @@ func (w *watchCommand) Execute(args []string) int {
97
94
viewer .SetScrollable (true )
98
95
viewer .SetBackgroundColor (tcell .ColorDefault )
99
96
97
+ //
98
+ // If the user presses 'q' or Esc in the viewer then exit
99
+ //
100
+ viewer .SetInputCapture (func (event * tcell.EventKey ) * tcell.EventKey {
101
+ if event .Key () == tcell .KeyEscape {
102
+ app .Stop ()
103
+ }
104
+ if event .Rune () == 'q' {
105
+ app .Stop ()
106
+ }
107
+ return event
108
+ })
109
+
100
110
// Create an elapsed time record
101
111
elapsed := tview .NewTextView ()
102
112
elapsed .SetTextColor (tcell .ColorBlack )
0 commit comments