summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMateusz Czapliński <czapkofan@gmail.com>2018-10-20 00:00:19 +0200
committerMateusz Czapliński <czapkofan@gmail.com>2018-10-20 00:00:19 +0200
commitc9f327ff959e47b121ae18674f499867070d2068 (patch)
treee90244b5b3958b987b306596a7a75da187328d4f
parent52fd4d6b65862c81fb83f3b25ef61c0f2c659342 (diff)
add helper func triggerRefresh
-rw-r--r--up.go19
1 files changed, 10 insertions, 9 deletions
diff --git a/up.go b/up.go
index ea594bd..9283642 100644
--- a/up.go
+++ b/up.go
@@ -82,11 +82,11 @@ func main() {
// Initialize main data flow
var (
- stdinCapture = NewBuf().StartCapturing(os.Stdin, func() {
- // When some new data shows up on stdin, we raise a custom signal,
- // so further down we will know to refresh commandOutput
- tui.PostEvent(tcell.NewEventInterrupt(nil))
- })
+ // We capture data piped to 'up' on standard input into an internal buffer
+ // When some new data shows up on stdin, we raise a custom signal,
+ // so that main loop will refresh the buffers and the output.
+ stdinCapture = NewBuf().StartCapturing(os.Stdin, func() { triggerRefresh(tui) })
+ // Then, we pass this data as input to a subprocess.
// Initially, no subprocess is running, as no command is entered yet
commandSubprocess *Subprocess = nil
)
@@ -102,10 +102,7 @@ func main() {
if command != lastCommand {
commandSubprocess.Kill()
if command != "" {
- // TODO: wrap the PostEvent in some helper named func
- commandSubprocess = StartSubprocess(command, stdinCapture, func() {
- tui.PostEvent(tcell.NewEventInterrupt(nil))
- })
+ commandSubprocess = StartSubprocess(command, stdinCapture, func() { triggerRefresh(tui) })
commandOutput.Buf = commandSubprocess.Buf
} else {
// If command is empty, show original input data again (~ equivalent of typing `cat`)
@@ -180,6 +177,10 @@ func initTUI() tcell.Screen {
return tui
}
+func triggerRefresh(tui tcell.Screen) {
+ tui.PostEvent(tcell.NewEventInterrupt(nil))
+}
+
func die(message string) {
os.Stderr.WriteString("error: " + message + "\n")
os.Exit(1)