7 "github.com/zyedidia/micro/v2/internal/clipboard"
8 "github.com/zyedidia/micro/v2/internal/display"
9 "github.com/zyedidia/micro/v2/internal/screen"
10 "github.com/zyedidia/micro/v2/internal/shell"
11 "github.com/zyedidia/tcell"
12 "github.com/zyedidia/terminal"
15 type TermPane struct {
24 func NewTermPane(x, y, w, h int, t *shell.Terminal, id uint64, tab *Tab) (*TermPane, error) {
25 if !TermEmuSupported {
26 return nil, errors.New("Terminal emulator is not supported on this system")
32 th.mouseReleased = true
33 th.Window = display.NewTermWindow(x, y, w, h, t)
38 func (t *TermPane) ID() uint64 {
42 func (t *TermPane) SetID(i uint64) {
46 func (t *TermPane) SetTab(tab *Tab) {
50 func (t *TermPane) Tab() *Tab {
54 func (t *TermPane) Close() {}
56 func (t *TermPane) Quit() {
58 if len(MainTab().Panes) > 1 {
60 } else if len(Tabs.List) > 1 {
69 func (t *TermPane) Unsplit() {
70 n := MainTab().GetNode(t.id)
73 MainTab().RemovePane(MainTab().GetPane(t.id))
75 MainTab().SetActive(len(MainTab().Panes) - 1)
78 // HandleEvent handles a tcell event by forwarding it to the terminal emulator
79 // If the event is a mouse event and the program running in the emulator
80 // does not have mouse support, the emulator will support selections and
82 func (t *TermPane) HandleEvent(event tcell.Event) {
83 if e, ok := event.(*tcell.EventKey); ok {
84 if t.Status == shell.TTDone {
86 case tcell.KeyEscape, tcell.KeyCtrlQ, tcell.KeyEnter:
92 if e.Key() == tcell.KeyCtrlC && t.HasSelection() {
93 clipboard.Write(t.GetSelection(t.GetView().Width), clipboard.ClipboardReg)
94 InfoBar.Message("Copied selection to clipboard")
95 } else if t.Status != shell.TTDone {
96 t.WriteString(event.EscSeq())
98 } else if _, ok := event.(*tcell.EventPaste); ok {
99 if t.Status != shell.TTDone {
100 t.WriteString(event.EscSeq())
102 } else if e, ok := event.(*tcell.EventMouse); e != nil && (!ok || t.State.Mode(terminal.ModeMouseMask)) {
103 // t.WriteString(event.EscSeq())
110 if e.Buttons() == tcell.Button1 {
111 if !t.mouseReleased {
122 t.mouseReleased = false
123 } else if e.Buttons() == tcell.ButtonNone {
124 if !t.mouseReleased {
128 t.mouseReleased = true
132 if t.Status == shell.TTClose {
137 func (t *TermPane) HandleCommand(input string) {
138 InfoBar.Error("Commands are unsupported in term for now")