]> git.lizzy.rs Git - micro.git/commitdiff
Expose emulator functions and support output
authorZachary Yedidia <zyedidia@gmail.com>
Sun, 21 Jan 2018 04:34:16 +0000 (23:34 -0500)
committerZachary Yedidia <zyedidia@gmail.com>
Sun, 21 Jan 2018 04:34:16 +0000 (23:34 -0500)
Ref #979

cmd/micro/micro.go
cmd/micro/shell_posix.go
cmd/micro/shell_windows.go
cmd/micro/terminal.go
cmd/micro/vendor/github.com/zyedidia/pty
cmd/micro/vendor/github.com/zyedidia/terminal
cmd/micro/view.go

index 6d955edd5ff46a5d73de8a473d40396c87296fa0..b097392ee507edc7adf6c417798baf2a1c6abf76 100644 (file)
@@ -390,6 +390,12 @@ func main() {
        L.SetGlobal("IsWordChar", luar.New(L, IsWordChar))
        L.SetGlobal("HandleCommand", luar.New(L, HandleCommand))
        L.SetGlobal("HandleShellCommand", luar.New(L, HandleShellCommand))
+       L.SetGlobal("ExecCommand", luar.New(L, ExecCommand))
+       L.SetGlobal("RunShellCommand", luar.New(L, RunShellCommand))
+       L.SetGlobal("RunBackgroundShell", luar.New(L, RunBackgroundShell))
+       L.SetGlobal("RunInteractiveShell", luar.New(L, RunInteractiveShell))
+       L.SetGlobal("TermEmuSupported", luar.New(L, TermEmuSupported))
+       L.SetGlobal("RunTermEmulator", luar.New(L, RunTermEmulator))
        L.SetGlobal("GetLeadingWhitespace", luar.New(L, GetLeadingWhitespace))
        L.SetGlobal("MakeCompletion", luar.New(L, MakeCompletion))
        L.SetGlobal("NewBuffer", luar.New(L, NewBufferFromString))
index 6c19bf40b4f8d0c6572590cffb533ff331b493f1..b2176150cda74fdbba3ac9b1fd8b74a035884459 100644 (file)
@@ -8,11 +8,11 @@ import (
 
 const TermEmuSupported = true
 
-func RunTermEmulator(input string, wait bool, getOutput bool) error {
+func RunTermEmulator(input string, wait bool, getOutput bool, callback string) error {
        args, err := shellwords.Split(input)
        if err != nil {
                return err
        }
-       err = CurView().StartTerminal(args, wait, false, "")
+       err = CurView().StartTerminal(args, wait, getOutput, callback)
        return err
 }
index 4ad4c415f3cb90f1cd154fcad814cd859f19285c..4db86873bbaabf0a86b3670a55e3044d4c9797e8 100644 (file)
@@ -2,8 +2,10 @@
 
 package main
 
+import "errors"
+
 const TermEmuSupported = false
 
-func RunTermEmulator(input string, wait bool, getOutput bool) string {
-       return "Unsupported"
+func RunTermEmulator(input string, wait bool, getOutput bool) error {
+       return errors.New("Unsupported operating system")
 }
index 1defa61ff3a37126cdddf874e6addb185d8c960d..04ca1242576216dd5632bc8516542798f53720d4 100644 (file)
@@ -1,6 +1,7 @@
 package main
 
 import (
+       "bytes"
        "fmt"
        "os"
        "os/exec"
@@ -29,6 +30,7 @@ type Terminal struct {
        selection [2]Loc
        wait      bool
        getOutput bool
+       output    *bytes.Buffer
        callback  string
 }
 
@@ -59,18 +61,23 @@ func (t *Terminal) GetSelection(width int) string {
 }
 
 // Start begins a new command in this terminal with a given view
-func (t *Terminal) Start(execCmd []string, view *View) error {
+func (t *Terminal) Start(execCmd []string, view *View, getOutput bool) error {
        if len(execCmd) <= 0 {
                return nil
        }
 
        cmd := exec.Command(execCmd[0], execCmd[1:]...)
-       term, _, err := terminal.Start(&t.state, cmd)
+       t.output = nil
+       if getOutput {
+               t.output = bytes.NewBuffer([]byte{})
+       }
+       term, _, err := terminal.Start(&t.state, cmd, t.output)
        if err != nil {
                return err
        }
        t.term = term
        t.view = view
+       t.getOutput = getOutput
        t.vtOld = view.Type
        t.status = VTRunning
        t.title = execCmd[0] + ":" + strconv.Itoa(cmd.Process.Pid)
@@ -153,7 +160,7 @@ func (t *Terminal) Stop() {
        if t.wait {
                t.status = VTDone
        } else {
-               t.status = VTIdle
+               t.Close()
                t.view.Type = t.vtOld
        }
 }
@@ -163,9 +170,11 @@ func (t *Terminal) Stop() {
 func (t *Terminal) Close() {
        t.status = VTIdle
        // call the lua function that the user has given as a callback
-       _, err := Call(t.callback)
-       if err != nil && !strings.HasPrefix(err.Error(), "function does not exist") {
-               TermMessage(err)
+       if t.getOutput {
+               _, err := Call(t.callback, t.output.String())
+               if err != nil && !strings.HasPrefix(err.Error(), "function does not exist") {
+                       TermMessage(err)
+               }
        }
 }
 
index 282ce0e5322c82529687d609ee670fac7c7d917c..a41f924260f4464b040619f1dd9797f17320d83e 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 282ce0e5322c82529687d609ee670fac7c7d917c
+Subproject commit a41f924260f4464b040619f1dd9797f17320d83e
index 441ca94228d630ad17c739751abc3e23cb422c6e..1195183a16e63a2b0b98b64b2f76c0603387adb3 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 441ca94228d630ad17c739751abc3e23cb422c6e
+Subproject commit 1195183a16e63a2b0b98b64b2f76c0603387adb3
index 7969c27441cd57366a4996482bad1988ee373934..70c4af378143abb74a3b529a2e4fe4bfa5f5037a 100644 (file)
@@ -166,9 +166,8 @@ func (v *View) ToggleStatusLine() {
 
 // StartTerminal execs a command in this view
 func (v *View) StartTerminal(execCmd []string, wait bool, getOutput bool, luaCallback string) error {
-       err := v.term.Start(execCmd, v)
+       err := v.term.Start(execCmd, v, getOutput)
        v.term.wait = wait
-       v.term.getOutput = getOutput
        v.term.callback = luaCallback
        if err == nil {
                v.term.Resize(v.Width, v.Height)