diff options
author | Mateusz Czapliński <czapkofan@gmail.com> | 2018-10-25 17:28:26 +0200 |
---|---|---|
committer | Mateusz Czapliński <czapkofan@gmail.com> | 2018-10-25 17:28:26 +0200 |
commit | 5a1abb25282ed35499ab5b4897f36da49c0f9b5d (patch) | |
tree | e9e5c6475f8ac0ff83a2939317555460ef8482fe | |
parent | 5bb81d216865514df0f864d89edb04bb4906ebb5 (diff) |
initial sketch of Enter-driven execution
-rw-r--r-- | go.mod | 1 | ||||
-rw-r--r-- | go.sum | 2 | ||||
-rw-r--r-- | up.go | 15 |
3 files changed, 17 insertions, 1 deletions
@@ -6,5 +6,6 @@ require ( github.com/lucasb-eyer/go-colorful v0.0.0-20170903184257-231272389856 github.com/mattn/go-isatty v0.0.3 github.com/mattn/go-runewidth v0.0.2 + github.com/spf13/pflag v1.0.3 golang.org/x/text v0.0.0-20171214130843-f21a4dfb5e38 ) @@ -8,5 +8,7 @@ github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-runewidth v0.0.2 h1:UnlwIPBGaTZfPQ6T1IGzPI0EkYAQmT9fAEJ/poFC63o= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= +github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= golang.org/x/text v0.0.0-20171214130843-f21a4dfb5e38 h1:yr7ItWHARpqySNZjEh5mPMHrw3xPR9tMnomFZVcO1mQ= golang.org/x/text v0.0.0-20171214130843-f21a4dfb5e38/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -31,6 +31,7 @@ import ( "github.com/gdamore/tcell" "github.com/mattn/go-isatty" + "github.com/spf13/pflag" ) // TODO: some key shortcut to increase stdin capture buffer size (unless EOF already reached) @@ -61,7 +62,14 @@ import ( // TODO: [LATER] make it more friendly to infrequent Linux users by providing "descriptive" commands like "search" etc. // TODO: [LATER] advertise on: HN, r/programming, r/golang, r/commandline, r/linux, up-for-grabs.net; data exploration? data science? +var ( + // TODO: dangerous? immediate? raw? unsafe? ... + // FIXME(akavel): mark the unsafe mode vs. safe mode with some colour or status; also inform/mark what command's results are displayed... + unsafeMode = pflag.BoolP("unsafe", "U", false, "enable mode in which command is executed immediately after any change") +) + func main() { + pflag.Parse() // Handle command-line flags parseFlags() @@ -95,11 +103,12 @@ func main() { // Main loop lastCommand := "" + restart := false for { // If user edited the command, immediately run it in background, and // kill the previously running command. command := commandEditor.String() - if command != lastCommand { + if restart || (*unsafeMode && command != lastCommand) { commandSubprocess.Kill() if command != "" { commandSubprocess = StartSubprocess(command, stdinCapture, func() { triggerRefresh(tui) }) @@ -109,6 +118,7 @@ func main() { commandSubprocess = nil commandOutput.Buf = stdinCapture } + restart = false } lastCommand = command @@ -137,6 +147,9 @@ func main() { } // Some other global key combinations switch getKey(ev) { + case key(tcell.KeyEnter): + restart = true + case key(tcell.KeyCtrlS), ctrlKey(tcell.KeyCtrlS): stdinCapture.Pause(true) |