Terminal plugin callback support

This commit is contained in:
Zachary Yedidia
2019-08-26 14:47:27 -04:00
parent 199d65017f
commit b68461cf72
10 changed files with 115 additions and 11 deletions

View File

@@ -30,8 +30,14 @@ func init() {
func LuaAction(fn string) func(*BufPane) bool {
luaFn := strings.Split(fn, ".")
if len(luaFn) <= 1 {
return nil
}
plName, plFn := luaFn[0], luaFn[1]
pl := config.FindPlugin(plName)
if pl == nil {
return nil
}
return func(h *BufPane) bool {
val, err := pl.Call(plFn, luar.New(ulua.L, h))
if err != nil {

View File

@@ -78,8 +78,14 @@ func LuaMakeCommand(name, function string, completer buffer.Completer) {
// so that a command can be bound to a lua function
func LuaFunctionCommand(fn string) func(*BufPane, []string) {
luaFn := strings.Split(fn, ".")
if len(luaFn) <= 1 {
return nil
}
plName, plFn := luaFn[0], luaFn[1]
pl := config.FindPlugin(plName)
if pl == nil {
return nil
}
return func(bp *BufPane, args []string) {
var luaArgs []lua.LValue
luaArgs = append(luaArgs, luar.New(ulua.L, bp))
@@ -872,9 +878,8 @@ func (h *BufPane) TermCmd(args []string) {
}
term := func(i int, newtab bool) {
t := new(shell.Terminal)
t.Start(args, false, true)
t.Start(args, false, true, "", nil)
id := h.ID()
if newtab {

View File

@@ -0,0 +1,30 @@
// +build linux darwin dragonfly openbsd_amd64 freebsd
package action
import (
"github.com/zyedidia/micro/internal/shell"
"github.com/zyedidia/micro/pkg/shellwords"
)
const TermEmuSupported = true
func RunTermEmulator(h *BufPane, input string, wait bool, getOutput bool, callback string, userargs []interface{}) error {
args, err := shellwords.Split(input)
if err != nil {
return err
}
t := new(shell.Terminal)
t.Start(args, getOutput, wait, callback, userargs)
id := h.ID()
h.AddTab()
id = MainTab().Panes[0].ID()
v := h.GetView()
MainTab().Panes[0] = NewTermPane(v.X, v.Y, v.Width, v.Height, t, id)
MainTab().SetActive(0)
return nil
}

View File

@@ -0,0 +1,11 @@
// +build !linux,!darwin,!freebsd,!dragonfly,!openbsd_amd64
package action
import "errors"
const TermEmuSupported = false
func RunTermEmulator(input string, wait bool, getOutput bool, callback string, userargs []interface{}) error {
return errors.New("Unsupported operating system")
}

View File

@@ -80,9 +80,9 @@ func (t *TermPane) HandleEvent(event tcell.Event) {
} else if t.Status != shell.TTDone {
t.WriteString(event.EscSeq())
}
} else if e, ok := event.(*tcell.EventMouse); !ok || t.State.Mode(terminal.ModeMouseMask) {
} else if e, ok := event.(*tcell.EventMouse); e != nil && (!ok || t.State.Mode(terminal.ModeMouseMask)) {
t.WriteString(event.EscSeq())
} else {
} else if e != nil {
x, y := e.Position()
v := t.GetView()
x -= v.X
@@ -109,6 +109,10 @@ func (t *TermPane) HandleEvent(event tcell.Event) {
t.mouseReleased = true
}
}
if t.Status == shell.TTClose {
t.Quit()
}
}
func (t *TermPane) HandleCommand(input string) {