]> git.lizzy.rs Git - micro.git/blob - internal/action/terminal_supported.go
Merge branch 'python-highlight-zero' of https://github.com/a11ce/micro into a11ce...
[micro.git] / internal / action / terminal_supported.go
1 // +build linux darwin dragonfly openbsd_amd64 freebsd
2
3 package action
4
5 import (
6         shellquote "github.com/kballard/go-shellquote"
7         "github.com/zyedidia/micro/v2/internal/shell"
8 )
9
10 // TermEmuSupported is a constant that marks if the terminal emulator is supported
11 const TermEmuSupported = true
12
13 // RunTermEmulator starts a terminal emulator from a bufpane with the given input (command)
14 // if wait is true it will wait for the user to exit by pressing enter once the executable has terminated
15 // if getOutput is true it will redirect the stdout of the process to a pipe which will be passed to the
16 // callback which is a function that takes a string and a list of optional user arguments
17 func RunTermEmulator(h *BufPane, input string, wait bool, getOutput bool, callback func(out string, userargs []interface{}), userargs []interface{}) error {
18         args, err := shellquote.Split(input)
19         if err != nil {
20                 return err
21         }
22         if len(args) == 0 {
23                 return nil
24         }
25
26         t := new(shell.Terminal)
27         err = t.Start(args, getOutput, wait, callback, userargs)
28         if err != nil {
29                 return err
30         }
31
32         h.AddTab()
33         id := MainTab().Panes[0].ID()
34
35         v := h.GetView()
36
37         tp, err := NewTermPane(v.X, v.Y, v.Width, v.Height, t, id, MainTab())
38         if err != nil {
39                 return err
40         }
41         MainTab().Panes[0] = tp
42         MainTab().SetActive(0)
43
44         return nil
45 }