micro/internal/action/terminal_supported.go

46 lines
1.3 KiB
Go
Raw Normal View History

2019-08-26 21:47:27 +03:00
// +build linux darwin dragonfly openbsd_amd64 freebsd
package action
import (
2020-01-03 02:30:51 +03:00
shellquote "github.com/kballard/go-shellquote"
2020-05-04 17:16:15 +03:00
"github.com/zyedidia/micro/v2/internal/shell"
2019-08-26 21:47:27 +03:00
)
// TermEmuSupported is a constant that marks if the terminal emulator is supported
2019-08-26 21:47:27 +03:00
const TermEmuSupported = true
// RunTermEmulator starts a terminal emulator from a bufpane with the given input (command)
// if wait is true it will wait for the user to exit by pressing enter once the executable has terminated
// if getOutput is true it will redirect the stdout of the process to a pipe which will be passed to the
// callback which is a function that takes a string and a list of optional user arguments
func RunTermEmulator(h *BufPane, input string, wait bool, getOutput bool, callback func(out string, userargs []interface{}), userargs []interface{}) error {
2020-01-03 02:30:51 +03:00
args, err := shellquote.Split(input)
2019-08-26 21:47:27 +03:00
if err != nil {
return err
}
if len(args) == 0 {
return nil
}
2019-08-26 21:47:27 +03:00
t := new(shell.Terminal)
2020-07-28 00:43:55 +03:00
err = t.Start(args, getOutput, wait, callback, userargs)
if err != nil {
return err
}
2019-08-26 21:47:27 +03:00
h.AddTab()
2019-12-30 06:02:14 +03:00
id := MainTab().Panes[0].ID()
2019-08-26 21:47:27 +03:00
v := h.GetView()
tp, err := NewTermPane(v.X, v.Y, v.Width, v.Height, t, id, MainTab())
if err != nil {
return err
}
MainTab().Panes[0] = tp
2019-08-26 21:47:27 +03:00
MainTab().SetActive(0)
return nil
}