X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;ds=sidebyside;f=cmd%2Fmicro%2Fcommand.go;h=eb610e887f33c0a7964b35a6e9fa1ed7c04e2504;hb=838a932dd96a709c37fbee7c0117ad4b29356d28;hp=2c6f1ecfd1c059dde85ba4b181502f8f8fe12186;hpb=f3e9271cae5a2ab064645ff1395f4e0d9ae10d8c;p=micro.git diff --git a/cmd/micro/command.go b/cmd/micro/command.go index 2c6f1ecf..eb610e88 100644 --- a/cmd/micro/command.go +++ b/cmd/micro/command.go @@ -1,6 +1,7 @@ package main import ( + "bytes" "os" "os/exec" "regexp" @@ -9,21 +10,39 @@ import ( "github.com/gdamore/tcell" ) +// HandleShellCommand runs the shell command and outputs to DisplayBlock func HandleShellCommand(input string, view *View) { inputCmd := strings.Split(input, " ")[0] args := strings.Split(input, " ")[1:] - + if inputCmd == "exit" { + messenger.Message("Ctrl+Q to exit") + return + } + if inputCmd == "help" { + DisplayHelp() + return + } + cmd := exec.Command(inputCmd, args...) + var stdout bytes.Buffer + var stderr bytes.Buffer + cmd.Stdout = &stdout // send output to buffer + cmd.Stderr = &stderr // send error to a different buffer // Execute Command - cmdout := exec.Command(inputCmd, args...) - output, _ := cmdout.CombinedOutput() - outstring := string(output) + err := cmd.Run() + if err != nil { + messenger.Message(err.Error() + "... " + stderr.String()) + return + } + + outstring := stdout.String() totalLines := strings.Split(outstring, "\n") - if len(totalLines) == 2 { + + if len(totalLines) < 3 { messenger.Message(outstring) return } + if outstring != "" { - // Display nonblank output DisplayBlock(outstring) } } @@ -58,6 +77,16 @@ func DisplayBlock(text string) { _, height = e.Size() case *tcell.EventKey: switch e.Key() { + case tcell.KeyPgUp: + if topline > height { + topline = topline - height + } else { + topline = 0 + } + case tcell.KeyPgDn: + if topline < len(totalLines)-height { + topline = topline + height + } case tcell.KeyUp: if topline > 0 { topline-- @@ -68,6 +97,8 @@ func DisplayBlock(text string) { } case tcell.KeyCtrlQ, tcell.KeyCtrlW, tcell.KeyEscape, tcell.KeyCtrlC: return + default: + return } } } @@ -97,7 +128,7 @@ func HandleCommand(input string, view *View) { case "set": SetOption(view, args) case "quit": - if view.CanClose("Quit anyway? ") { + if view.CanClose("Quit anyway? (yes, no, save) ") { screen.Fini() os.Exit(0) }