diff --git a/key.go b/key.go index 3545215a..8f50ad7a 100644 --- a/key.go +++ b/key.go @@ -373,6 +373,8 @@ const ( KeyF62 KeyF63 KeyF64 + KeyPasteBegin + KeyPasteEnd ) // These are the control keys. Note that they overlap with other keys, diff --git a/paste.go b/paste.go new file mode 100644 index 00000000..1f9b24c2 --- /dev/null +++ b/paste.go @@ -0,0 +1,38 @@ +package tcell + +import "time" + +const ( + PasteBegin = "\x1b[200~" + PasteEnd = "\x1b[201~" +) + +type EventKeyPasteBegin struct { + t time.Time +} + +var _ Event = (*EventKeyPasteBegin)(nil) + +// When returns the time when this EventKeyPasteBegin was created. +func (ev *EventKeyPasteBegin) When() time.Time { + return ev.t +} + +func NewEventKeyPasteBegin() *EventKeyPasteBegin { + return &EventKeyPasteBegin{t: time.Now()} +} + +type EventKeyPasteEnd struct { + t time.Time +} + +var _ Event = (*EventKeyPasteEnd)(nil) + +// When returns the time when this EventKeyPasteEnd was created. +func (ev *EventKeyPasteEnd) When() time.Time { + return ev.t +} + +func NewEventKeyPasteEnd() *EventKeyPasteEnd { + return &EventKeyPasteEnd{t: time.Now()} +} diff --git a/tscreen.go b/tscreen.go index 93a696af..77f4e4a7 100644 --- a/tscreen.go +++ b/tscreen.go @@ -358,6 +358,9 @@ func (t *tScreen) prepareKeys() { t.prepareKey(KeyHome, "\x1bOH") } + t.prepareKey(KeyPasteBegin, PasteBegin) + t.prepareKey(KeyPasteEnd, PasteEnd) + outer: // Add key mappings for control keys. for i := 0; i < ' '; i++ { @@ -1130,17 +1133,26 @@ func (t *tScreen) parseFunctionKey(buf *bytes.Buffer, evs *[]Event) (bool, bool) continue } if bytes.HasPrefix(b, esc) { - // matched - var r rune - if len(esc) == 1 { - r = rune(b[0]) - } - mod := k.mod - if t.escaped { - mod |= ModAlt - t.escaped = false + var ev Event + switch e { + case PasteBegin: + ev = NewEventKeyPasteBegin() + case PasteEnd: + ev = NewEventKeyPasteEnd() + default: + // matched + var r rune + if len(esc) == 1 { + r = rune(b[0]) + } + mod := k.mod + if t.escaped { + mod |= ModAlt + } + ev = NewEventKey(k.key, r, mod) } - *evs = append(*evs, NewEventKey(k.key, r, mod)) + t.escaped = false + *evs = append(*evs, ev) for i := 0; i < len(esc); i++ { buf.ReadByte() }