6 "github.com/zyedidia/clipboard"
7 "github.com/zyedidia/micro/cmd/micro/display"
8 "github.com/zyedidia/micro/cmd/micro/screen"
9 "github.com/zyedidia/micro/cmd/micro/shell"
10 "github.com/zyedidia/tcell"
11 "github.com/zyedidia/terminal"
14 type TermHandler struct {
22 func NewTermHandler(x, y, w, h int, t *shell.Terminal, id uint64) *TermHandler {
23 th := new(TermHandler)
26 th.mouseReleased = true
27 th.Window = display.NewTermWindow(x, y, w, h, t)
31 func (t *TermHandler) ID() uint64 {
35 func (t *TermHandler) Close() {}
37 func (t *TermHandler) Quit() {
39 if len(MainTab().Panes) > 1 {
41 } else if len(Tabs.List) > 1 {
50 func (t *TermHandler) Unsplit() {
51 n := MainTab().GetNode(t.id)
54 MainTab().RemovePane(MainTab().GetPane(t.id))
56 MainTab().SetActive(len(MainTab().Panes) - 1)
59 // HandleEvent handles a tcell event by forwarding it to the terminal emulator
60 // If the event is a mouse event and the program running in the emulator
61 // does not have mouse support, the emulator will support selections and
63 func (t *TermHandler) HandleEvent(event tcell.Event) {
64 if e, ok := event.(*tcell.EventKey); ok {
65 if t.Status == shell.TTDone {
67 case tcell.KeyEscape, tcell.KeyCtrlQ, tcell.KeyEnter:
73 if e.Key() == tcell.KeyCtrlC && t.HasSelection() {
74 clipboard.WriteAll(t.GetSelection(t.GetView().Width), "clipboard")
75 InfoBar.Message("Copied selection to clipboard")
76 } else if t.Status != shell.TTDone {
77 t.WriteString(event.EscSeq())
79 } else if e, ok := event.(*tcell.EventMouse); !ok || t.State.Mode(terminal.ModeMouseMask) {
80 t.WriteString(event.EscSeq())
87 if e.Buttons() == tcell.Button1 {
99 t.mouseReleased = false
100 } else if e.Buttons() == tcell.ButtonNone {
101 if !t.mouseReleased {
105 t.mouseReleased = true
110 func (t *TermHandler) HandleCommand(input string) {
111 InfoBar.Error("Commands are unsupported in term for now")