Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for bracketed paste #286

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions key.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ const (
KeyF62
KeyF63
KeyF64
KeyPasteBegin
KeyPasteEnd
)

// These are the control keys. Note that they overlap with other keys,
Expand Down
38 changes: 38 additions & 0 deletions paste.go
Original file line number Diff line number Diff line change
@@ -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()}
}
32 changes: 22 additions & 10 deletions tscreen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++ {
Expand Down Expand Up @@ -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()
}
Expand Down