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.Window = display.NewTermWindow(x, y, w, h, t)
30 func (t *TermHandler) ID() uint64 {
34 func (t *TermHandler) Close() {}
36 func (t *TermHandler) Quit() {
38 if len(MainTab().Panes) > 1 {
40 } else if len(Tabs.List) > 1 {
49 func (t *TermHandler) Unsplit() {
50 n := MainTab().GetNode(t.id)
53 MainTab().RemovePane(MainTab().GetPane(t.id))
55 MainTab().SetActive(len(MainTab().Panes) - 1)
58 // HandleEvent handles a tcell event by forwarding it to the terminal emulator
59 // If the event is a mouse event and the program running in the emulator
60 // does not have mouse support, the emulator will support selections and
62 func (t *TermHandler) HandleEvent(event tcell.Event) {
63 if e, ok := event.(*tcell.EventKey); ok {
64 if t.Status == shell.TTDone {
66 case tcell.KeyEscape, tcell.KeyCtrlQ, tcell.KeyEnter:
72 if e.Key() == tcell.KeyCtrlC && t.HasSelection() {
73 clipboard.WriteAll(t.GetSelection(t.GetView().Width), "clipboard")
74 InfoBar.Message("Copied selection to clipboard")
75 } else if t.Status != shell.TTDone {
76 t.WriteString(event.EscSeq())
78 } else if e, ok := event.(*tcell.EventMouse); !ok || t.State.Mode(terminal.ModeMouseMask) {
79 t.WriteString(event.EscSeq())
86 if e.Buttons() == tcell.Button1 {
98 t.mouseReleased = false
99 } else if e.Buttons() == tcell.ButtonNone {
100 if !t.mouseReleased {
104 t.mouseReleased = true
109 func (t *TermHandler) HandleCommand(input string) {
110 InfoBar.Error("Commands are unsupported in term for now")