Skip to content
Merged
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
4 changes: 2 additions & 2 deletions internal/action/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func BindKey(k, v string, bind func(e Event, a string)) {
}

if strings.HasPrefix(k, "\x1b") {
screen.Screen.RegisterRawSeq(k)
screen.RegisterRawSeq(k)
}

bind(event, v)
Expand Down Expand Up @@ -342,7 +342,7 @@ func UnbindKey(k string) error {
}

if strings.HasPrefix(k, "\x1b") {
screen.Screen.UnregisterRawSeq(k)
screen.UnregisterRawSeq(k)
}

defaults := DefaultBindings("buffer")
Expand Down
38 changes: 38 additions & 0 deletions internal/screen/screen.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ var lock sync.Mutex
// written to even if no event user event has occurred
var drawChan chan bool

// rawSeq is the list of raw escape sequences that are bound to some actions
// via keybindings and thus should be parsed by tcell. We need to register
// them in tcell every time we reinitialize the screen, so we need to remember
// them in a list
var rawSeq = make([]string, 0)

// Lock locks the screen lock
func Lock() {
lock.Lock()
Expand Down Expand Up @@ -121,6 +127,34 @@ func SetContent(x, y int, mainc rune, combc []rune, style tcell.Style) {
}
}

// RegisterRawSeq registers a raw escape sequence that should be parsed by tcell
func RegisterRawSeq(r string) {
for _, seq := range rawSeq {
if seq == r {
return
}
}
rawSeq = append(rawSeq, r)

if Screen != nil {
Screen.RegisterRawSeq(r)
}
}

// UnregisterRawSeq unregisters a raw escape sequence that should be parsed by tcell
func UnregisterRawSeq(r string) {
for i, seq := range rawSeq {
if seq == r {
rawSeq[i] = rawSeq[len(rawSeq)-1]
rawSeq = rawSeq[:len(rawSeq)-1]
}
}

if Screen != nil {
Screen.UnregisterRawSeq(r)
}
}

// TempFini shuts the screen down temporarily
func TempFini() bool {
screenWasNil := Screen == nil
Expand Down Expand Up @@ -195,6 +229,10 @@ func Init() error {
Screen.EnableMouse()
}

for _, r := range rawSeq {
Screen.RegisterRawSeq(r)
}

return nil
}

Expand Down