Skip to content

Commit

Permalink
Added common CTRL key sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
masmu committed Sep 18, 2024
1 parent a97e6d4 commit 162686a
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 90 deletions.
21 changes: 21 additions & 0 deletions man/man1/fzf.1
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,24 @@ e.g.
.br
\fIpage\-down\fR (\fIpgdn\fR)
.br
\fIctrl\-up\fR
.br
\fIctrl\-down\fR
.br
\fIctrl\-left\fR
.br
\fIctrl\-right\fR
.br
\fIctrl\-home\fR
.br
\fIctrl\-end\fR
.br
\fIctrl\-delete\fR
.br
\fIctrl\-page\-up\fR
.br
\fIctrl\-page\-down\fR
.br
\fIshift\-up\fR
.br
\fIshift\-down\fR
Expand Down Expand Up @@ -1329,6 +1347,9 @@ e.g.
.br
or any single character

Note that some terminal emulators (such as \fIkitty\fR, \fIiterm2\fR, etc) do not distinguish between
CTRL-* and those without CTRL and therefore these bindings may not work.

.SS AVAILABLE EVENTS:
\fIstart\fR
.RS
Expand Down
20 changes: 18 additions & 2 deletions src/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -807,8 +807,6 @@ func parseKeyChordsImpl(str string, message string) (map[tui.Event]string, error
add(tui.Backspace)
case "ctrl-space":
add(tui.CtrlSpace)
case "ctrl-delete":
add(tui.CtrlDelete)
case "ctrl-^", "ctrl-6":
add(tui.CtrlCaret)
case "ctrl-/", "ctrl-_":
Expand Down Expand Up @@ -901,6 +899,24 @@ func parseKeyChordsImpl(str string, message string) (map[tui.Event]string, error
add(tui.AltShiftPageUp)
case "alt-shift-page-down", "shift-alt-page-down":
add(tui.AltShiftPageDown)
case "ctrl-up":
add(tui.CtrlUp)
case "ctrl-down":
add(tui.CtrlDown)
case "ctrl-right":
add(tui.CtrlRight)
case "ctrl-left":
add(tui.CtrlLeft)
case "ctrl-home":
add(tui.CtrlHome)
case "ctrl-end":
add(tui.CtrlEnd)
case "ctrl-delete":
add(tui.CtrlDelete)
case "ctrl-page-up":
add(tui.CtrlPageUp)
case "ctrl-page-down":
add(tui.CtrlPageDown)
case "shift-up":
add(tui.ShiftUp)
case "shift-down":
Expand Down
183 changes: 96 additions & 87 deletions src/tui/eventtype_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions src/tui/light.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,8 @@ func (r *LightRenderer) escSequence(sz *int) Event {
return Event{AltPageUp, 0, nil}
case '4':
return Event{AltShiftPageUp, 0, nil}
case '5':
return Event{CtrlPageUp, 0, nil}
}
}
return Event{Invalid, 0, nil}
Expand All @@ -508,6 +510,8 @@ func (r *LightRenderer) escSequence(sz *int) Event {
return Event{AltPageDown, 0, nil}
case '4':
return Event{AltShiftPageDown, 0, nil}
case '5':
return Event{CtrlPageDown, 0, nil}
}
}
return Event{Invalid, 0, nil}
Expand Down Expand Up @@ -554,10 +558,12 @@ func (r *LightRenderer) escSequence(sz *int) Event {
// ALT-SHIFT-ARROW "\e[1;4D" "\e[1;10D" "\e[1;4D"
// CTRL-SHIFT-ARROW "\e[1;6D" N/A
// CMD-SHIFT-ARROW "\e[1;10D" N/A N/A ("\e[1;2D")
ctrl := r.buffer[4] == '5' || r.buffer[4] == '6' || r.buffer[4] == '7' || r.buffer[4] == '8'
alt := r.buffer[4] == '3' || r.buffer[4] == '4' || r.buffer[4] == '7' || r.buffer[4] == '8'
shift := r.buffer[4] == '2' || r.buffer[4] == '4' || r.buffer[4] == '6' || r.buffer[4] == '8'
char := r.buffer[5]
if r.buffer[4] == '1' && r.buffer[5] == '0' {
ctrl = false
shift = true
alt = true // treat META as ALT here
if len(r.buffer) < 7 {
Expand All @@ -572,6 +578,9 @@ func (r *LightRenderer) escSequence(sz *int) Event {
if altShift {
return Event{AltShiftUp, 0, nil}
}
if ctrl {
return Event{CtrlUp, 0, nil}
}
if alt {
return Event{AltUp, 0, nil}
}
Expand All @@ -582,6 +591,9 @@ func (r *LightRenderer) escSequence(sz *int) Event {
if altShift {
return Event{AltShiftDown, 0, nil}
}
if ctrl {
return Event{CtrlDown, 0, nil}
}
if alt {
return Event{AltDown, 0, nil}
}
Expand All @@ -592,6 +604,9 @@ func (r *LightRenderer) escSequence(sz *int) Event {
if altShift {
return Event{AltShiftRight, 0, nil}
}
if ctrl {
return Event{CtrlRight, 0, nil}
}
if shift {
return Event{ShiftRight, 0, nil}
}
Expand All @@ -602,6 +617,9 @@ func (r *LightRenderer) escSequence(sz *int) Event {
if altShift {
return Event{AltShiftLeft, 0, nil}
}
if ctrl {
return Event{CtrlLeft, 0, nil}
}
if alt {
return Event{AltLeft, 0, nil}
}
Expand All @@ -612,6 +630,9 @@ func (r *LightRenderer) escSequence(sz *int) Event {
if altShift {
return Event{AltShiftHome, 0, nil}
}
if ctrl {
return Event{CtrlHome, 0, nil}
}
if alt {
return Event{AltHome, 0, nil}
}
Expand All @@ -622,6 +643,9 @@ func (r *LightRenderer) escSequence(sz *int) Event {
if altShift {
return Event{AltShiftEnd, 0, nil}
}
if ctrl {
return Event{CtrlEnd, 0, nil}
}
if alt {
return Event{AltEnd, 0, nil}
}
Expand Down
8 changes: 8 additions & 0 deletions src/tui/light_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,15 @@ func TestLightRenderer(t *testing.T) {
assertEscSequence("\x1b[5;4~", "alt-shift-page-up")
assertEscSequence("\x1b[6;4~", "alt-shift-page-down")

assertEscSequence("\x1b[1;5A", "ctrl-up")
assertEscSequence("\x1b[1;5B", "ctrl-down")
assertEscSequence("\x1b[1;5C", "ctrl-right")
assertEscSequence("\x1b[1;5D", "ctrl-left")
assertEscSequence("\x1b[1;5H", "ctrl-home")
assertEscSequence("\x1b[1;5F", "ctrl-end")
assertEscSequence("\x1b[3;5~", "ctrl-delete")
assertEscSequence("\x1b[5;5~", "ctrl-page-up")
assertEscSequence("\x1b[6;5~", "ctrl-page-down")

// mac
assertEscSequence("\x1b[1;10A", "alt-shift-up")
Expand Down
Loading

0 comments on commit 162686a

Please sign in to comment.