From c62fc5e75c09262a384e703800fefa6850afa2e8 Mon Sep 17 00:00:00 2001
From: Junegunn Choi <junegunn.c@gmail.com>
Date: Wed, 18 May 2016 22:25:09 +0900
Subject: [PATCH] More named keys: F5 ~ F10, ALT-/

---
 src/curses/curses.go | 33 +++++++++++++++++++++++++++++++++
 src/options.go       |  6 +++++-
 test/test_go.rb      |  4 ++++
 3 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/src/curses/curses.go b/src/curses/curses.go
index 0ad382bd..a0240da9 100644
--- a/src/curses/curses.go
+++ b/src/curses/curses.go
@@ -80,9 +80,16 @@ const (
 	F2
 	F3
 	F4
+	F5
+	F6
+	F7
+	F8
+	F9
+	F10
 
 	AltEnter
 	AltSpace
+	AltSlash
 	AltBS
 	AltA
 	AltB
@@ -423,6 +430,8 @@ func escSequence(sz *int) Event {
 		return Event{AltEnter, 0, nil}
 	case 32:
 		return Event{AltSpace, 0, nil}
+	case 47:
+		return Event{AltSlash, 0, nil}
 	case 98:
 		return Event{AltB, 0, nil}
 	case 100:
@@ -468,6 +477,15 @@ func escSequence(sz *int) Event {
 			*sz = 4
 			switch _buf[2] {
 			case 50:
+				if len(_buf) == 5 && _buf[4] == 126 {
+					*sz = 5
+					switch _buf[3] {
+					case 48:
+						return Event{F9, 0, nil}
+					case 49:
+						return Event{F10, 0, nil}
+					}
+				}
 				return Event{Invalid, 0, nil} // INS
 			case 51:
 				return Event{Del, 0, nil}
@@ -481,6 +499,21 @@ func escSequence(sz *int) Event {
 				switch _buf[3] {
 				case 126:
 					return Event{Home, 0, nil}
+				case 53, 55, 56, 57:
+					if len(_buf) == 5 && _buf[4] == 126 {
+						*sz = 5
+						switch _buf[3] {
+						case 53:
+							return Event{F5, 0, nil}
+						case 55:
+							return Event{F6, 0, nil}
+						case 56:
+							return Event{F7, 0, nil}
+						case 57:
+							return Event{F8, 0, nil}
+						}
+					}
+					return Event{Invalid, 0, nil}
 				case 59:
 					if len(_buf) != 6 {
 						return Event{Invalid, 0, nil}
diff --git a/src/options.go b/src/options.go
index 089b4c2f..10a22287 100644
--- a/src/options.go
+++ b/src/options.go
@@ -322,6 +322,8 @@ func parseKeyChords(str string, message string) map[int]string {
 			chord = curses.AltEnter
 		case "alt-space":
 			chord = curses.AltSpace
+		case "alt-/":
+			chord = curses.AltSlash
 		case "alt-bs", "alt-bspace":
 			chord = curses.AltBS
 		case "tab":
@@ -346,12 +348,14 @@ func parseKeyChords(str string, message string) map[int]string {
 			chord = curses.SRight
 		case "double-click":
 			chord = curses.DoubleClick
+		case "f10":
+			chord = curses.F10
 		default:
 			if len(key) == 6 && strings.HasPrefix(lkey, "ctrl-") && isAlphabet(lkey[5]) {
 				chord = curses.CtrlA + int(lkey[5]) - 'a'
 			} else if len(key) == 5 && strings.HasPrefix(lkey, "alt-") && isAlphabet(lkey[4]) {
 				chord = curses.AltA + int(lkey[4]) - 'a'
-			} else if len(key) == 2 && strings.HasPrefix(lkey, "f") && key[1] >= '1' && key[1] <= '4' {
+			} else if len(key) == 2 && strings.HasPrefix(lkey, "f") && key[1] >= '1' && key[1] <= '9' {
 				chord = curses.F1 + int(key[1]) - '1'
 			} else if utf8.RuneCountInString(key) == 1 {
 				chord = curses.AltZ + int([]rune(key)[0])
diff --git a/test/test_go.rb b/test/test_go.rb
index 8f336932..d886c323 100644
--- a/test/test_go.rb
+++ b/test/test_go.rb
@@ -430,6 +430,10 @@ class TestGoFZF < TestBase
     test.call 'f3', 'f3'
     test.call 'f2,f4', 'f2', 'f2'
     test.call 'f2,f4', 'f4', 'f4'
+    test.call 'alt-/', [:Escape, :/]
+    %w[f5 f6 f7 f8 f9 f10].each do |key|
+      test.call 'f5,f6,f7,f8,f9,f10', key, key
+    end
     test.call '@', '@'
   end
 
-- 
GitLab