mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-30 06:37:14 +09:00
@@ -390,6 +390,12 @@ func main() {
|
|||||||
L.SetGlobal("IsWordChar", luar.New(L, IsWordChar))
|
L.SetGlobal("IsWordChar", luar.New(L, IsWordChar))
|
||||||
L.SetGlobal("HandleCommand", luar.New(L, HandleCommand))
|
L.SetGlobal("HandleCommand", luar.New(L, HandleCommand))
|
||||||
L.SetGlobal("HandleShellCommand", luar.New(L, HandleShellCommand))
|
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("GetLeadingWhitespace", luar.New(L, GetLeadingWhitespace))
|
||||||
L.SetGlobal("MakeCompletion", luar.New(L, MakeCompletion))
|
L.SetGlobal("MakeCompletion", luar.New(L, MakeCompletion))
|
||||||
L.SetGlobal("NewBuffer", luar.New(L, NewBufferFromString))
|
L.SetGlobal("NewBuffer", luar.New(L, NewBufferFromString))
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ import (
|
|||||||
|
|
||||||
const TermEmuSupported = true
|
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)
|
args, err := shellwords.Split(input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = CurView().StartTerminal(args, wait, false, "")
|
err = CurView().StartTerminal(args, wait, getOutput, callback)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
const TermEmuSupported = false
|
const TermEmuSupported = false
|
||||||
|
|
||||||
func RunTermEmulator(input string, wait bool, getOutput bool) string {
|
func RunTermEmulator(input string, wait bool, getOutput bool) error {
|
||||||
return "Unsupported"
|
return errors.New("Unsupported operating system")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@@ -29,6 +30,7 @@ type Terminal struct {
|
|||||||
selection [2]Loc
|
selection [2]Loc
|
||||||
wait bool
|
wait bool
|
||||||
getOutput bool
|
getOutput bool
|
||||||
|
output *bytes.Buffer
|
||||||
callback string
|
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
|
// 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 {
|
if len(execCmd) <= 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := exec.Command(execCmd[0], execCmd[1:]...)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
t.term = term
|
t.term = term
|
||||||
t.view = view
|
t.view = view
|
||||||
|
t.getOutput = getOutput
|
||||||
t.vtOld = view.Type
|
t.vtOld = view.Type
|
||||||
t.status = VTRunning
|
t.status = VTRunning
|
||||||
t.title = execCmd[0] + ":" + strconv.Itoa(cmd.Process.Pid)
|
t.title = execCmd[0] + ":" + strconv.Itoa(cmd.Process.Pid)
|
||||||
@@ -153,7 +160,7 @@ func (t *Terminal) Stop() {
|
|||||||
if t.wait {
|
if t.wait {
|
||||||
t.status = VTDone
|
t.status = VTDone
|
||||||
} else {
|
} else {
|
||||||
t.status = VTIdle
|
t.Close()
|
||||||
t.view.Type = t.vtOld
|
t.view.Type = t.vtOld
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,9 +170,11 @@ func (t *Terminal) Stop() {
|
|||||||
func (t *Terminal) Close() {
|
func (t *Terminal) Close() {
|
||||||
t.status = VTIdle
|
t.status = VTIdle
|
||||||
// call the lua function that the user has given as a callback
|
// call the lua function that the user has given as a callback
|
||||||
_, err := Call(t.callback)
|
if t.getOutput {
|
||||||
if err != nil && !strings.HasPrefix(err.Error(), "function does not exist") {
|
_, err := Call(t.callback, t.output.String())
|
||||||
TermMessage(err)
|
if err != nil && !strings.HasPrefix(err.Error(), "function does not exist") {
|
||||||
|
TermMessage(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
cmd/micro/vendor/github.com/zyedidia/pty
generated
vendored
2
cmd/micro/vendor/github.com/zyedidia/pty
generated
vendored
Submodule cmd/micro/vendor/github.com/zyedidia/pty updated: 282ce0e532...a41f924260
2
cmd/micro/vendor/github.com/zyedidia/terminal
generated
vendored
2
cmd/micro/vendor/github.com/zyedidia/terminal
generated
vendored
Submodule cmd/micro/vendor/github.com/zyedidia/terminal updated: 441ca94228...1195183a16
@@ -166,9 +166,8 @@ func (v *View) ToggleStatusLine() {
|
|||||||
|
|
||||||
// StartTerminal execs a command in this view
|
// StartTerminal execs a command in this view
|
||||||
func (v *View) StartTerminal(execCmd []string, wait bool, getOutput bool, luaCallback string) error {
|
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.wait = wait
|
||||||
v.term.getOutput = getOutput
|
|
||||||
v.term.callback = luaCallback
|
v.term.callback = luaCallback
|
||||||
if err == nil {
|
if err == nil {
|
||||||
v.term.Resize(v.Width, v.Height)
|
v.term.Resize(v.Width, v.Height)
|
||||||
|
|||||||
Reference in New Issue
Block a user