micro/internal/action/rawpane.go

48 lines
959 B
Go
Raw Normal View History

2019-01-19 23:37:59 +03:00
package action
import (
2020-01-01 05:50:26 +03:00
"fmt"
2019-01-19 23:37:59 +03:00
"reflect"
2020-05-04 17:16:15 +03:00
"github.com/zyedidia/micro/v2/internal/buffer"
"github.com/zyedidia/micro/v2/internal/display"
2020-09-05 21:52:35 +03:00
"github.com/zyedidia/tcell/v2"
2019-01-19 23:37:59 +03:00
)
type RawPane struct {
*BufPane
}
2020-02-06 01:16:31 +03:00
func NewRawPaneFromWin(b *buffer.Buffer, win display.BWindow, tab *Tab) *RawPane {
2019-01-19 23:37:59 +03:00
rh := new(RawPane)
2020-02-06 01:16:31 +03:00
rh.BufPane = NewBufPane(b, win, tab)
2019-01-19 23:37:59 +03:00
return rh
}
2020-02-06 01:16:31 +03:00
func NewRawPane(tab *Tab) *RawPane {
2019-01-19 23:37:59 +03:00
b := buffer.NewBufferFromString("", "", buffer.BTRaw)
w := display.NewBufWindow(0, 0, 0, 0, b)
2020-02-06 01:16:31 +03:00
return NewRawPaneFromWin(b, w, tab)
2019-01-19 23:37:59 +03:00
}
func (h *RawPane) HandleEvent(event tcell.Event) {
switch e := event.(type) {
case *tcell.EventKey:
if e.Key() == tcell.KeyCtrlQ {
h.Quit()
}
}
h.Buf.Insert(h.Cursor.Loc, reflect.TypeOf(event).String()[7:])
2020-06-09 22:57:52 +03:00
2020-06-29 07:50:19 +03:00
e, err := ConstructEvent(event)
if err == nil {
h.Buf.Insert(h.Cursor.Loc, fmt.Sprintf(": %s", e.Name()))
2020-06-09 22:57:52 +03:00
}
2020-01-01 05:50:26 +03:00
h.Buf.Insert(h.Cursor.Loc, fmt.Sprintf(": %q\n", event.EscSeq()))
2020-06-09 22:57:52 +03:00
2019-01-19 23:37:59 +03:00
h.Relocate()
}