Skip to content

Commit 8bca3f2

Browse files
committed
Updated to allow q/Esc to exit the watch sub-command.
1 parent a5063aa commit 8bca3f2

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

Diff for: cmd_watch.go

+20-10
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import (
1616
// Structure for our options and state.
1717
type watchCommand struct {
1818

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.
2020
delay int
2121

22-
// count increments once every second
22+
// count increments once every second.
2323
count int
2424
}
2525

@@ -35,20 +35,17 @@ func (w *watchCommand) Info() (string, string) {
3535
Details:
3636
3737
This command allows you execute a command every five seconds,
38-
and see the output.
38+
and see the most recent output.
3939
4040
It is included because Mac OS does not include a watch-command
4141
by default.
4242
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.
4446
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.
4848
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.
5249
`
5350
}
5451

@@ -97,6 +94,19 @@ func (w *watchCommand) Execute(args []string) int {
9794
viewer.SetScrollable(true)
9895
viewer.SetBackgroundColor(tcell.ColorDefault)
9996

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+
100110
// Create an elapsed time record
101111
elapsed := tview.NewTextView()
102112
elapsed.SetTextColor(tcell.ColorBlack)

0 commit comments

Comments
 (0)