Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
fzf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KMSCAKKSCFKA AKFACAMADCAS
fzf
Commits
7db53e64
Commit
7db53e64
authored
9 years ago
by
Junegunn Choi
Browse files
Options
Downloads
Patches
Plain Diff
Add synonyms for some keys to be used with --bind and --toggle-sort
enter (return), space, tab, btab, esc, up, down, left, right
parent
e287bd7f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/options.go
+43
-15
43 additions, 15 deletions
src/options.go
src/options_test.go
+21
-7
21 additions, 7 deletions
src/options_test.go
with
64 additions
and
22 deletions
src/options.go
+
43
−
15
View file @
7db53e64
...
...
@@ -262,7 +262,7 @@ func isAlphabet(char uint8) bool {
return
char
>=
'a'
&&
char
<=
'z'
}
func
parseKeyChords
(
str
string
,
message
string
)
[]
int
{
func
parseKeyChords
(
str
string
,
message
string
,
bind
bool
)
[]
int
{
if
len
(
str
)
==
0
{
errorExit
(
message
)
}
...
...
@@ -278,16 +278,44 @@ func parseKeyChords(str string, message string) []int {
continue
// ignore
}
lkey
:=
strings
.
ToLower
(
key
)
if
len
(
key
)
==
6
&&
strings
.
HasPrefix
(
lkey
,
"ctrl-"
)
&&
isAlphabet
(
lkey
[
5
])
{
chords
=
append
(
chords
,
curses
.
CtrlA
+
int
(
lkey
[
5
])
-
'a'
)
}
else
if
len
(
key
)
==
5
&&
strings
.
HasPrefix
(
lkey
,
"alt-"
)
&&
isAlphabet
(
lkey
[
4
])
{
chords
=
append
(
chords
,
curses
.
AltA
+
int
(
lkey
[
4
])
-
'a'
)
}
else
if
len
(
key
)
==
2
&&
strings
.
HasPrefix
(
lkey
,
"f"
)
&&
key
[
1
]
>=
'1'
&&
key
[
1
]
<=
'4'
{
chords
=
append
(
chords
,
curses
.
F1
+
int
(
key
[
1
])
-
'1'
)
}
else
if
utf8
.
RuneCountInString
(
key
)
==
1
{
chords
=
append
(
chords
,
curses
.
AltZ
+
int
([]
rune
(
key
)[
0
]))
}
else
{
errorExit
(
"unsupported key: "
+
key
)
chord
:=
0
if
bind
{
switch
lkey
{
case
"up"
:
chord
=
curses
.
Up
case
"down"
:
chord
=
curses
.
Down
case
"left"
:
chord
=
curses
.
Left
case
"right"
:
chord
=
curses
.
Right
case
"enter"
,
"return"
:
chord
=
curses
.
CtrlM
case
"space"
:
chord
=
curses
.
AltZ
+
int
(
' '
)
case
"tab"
:
chord
=
curses
.
Tab
case
"btab"
:
chord
=
curses
.
BTab
case
"esc"
:
chord
=
curses
.
ESC
}
}
if
chord
==
0
{
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'
{
chord
=
curses
.
F1
+
int
(
key
[
1
])
-
'1'
}
else
if
utf8
.
RuneCountInString
(
key
)
==
1
{
chord
=
curses
.
AltZ
+
int
([]
rune
(
key
)[
0
])
}
else
{
errorExit
(
"unsupported key: "
+
key
)
}
}
if
chord
>
0
{
chords
=
append
(
chords
,
chord
)
}
}
return
chords
...
...
@@ -402,7 +430,7 @@ func parseKeymap(keymap map[int]actionType, execmap map[int]string, toggleSort b
if
len
(
pair
)
!=
2
{
fail
()
}
keys
:=
parseKeyChords
(
pair
[
0
],
"key name required"
)
keys
:=
parseKeyChords
(
pair
[
0
],
"key name required"
,
true
)
if
len
(
keys
)
!=
1
{
fail
()
}
...
...
@@ -498,7 +526,7 @@ func isExecuteAction(str string) bool {
}
func
checkToggleSort
(
keymap
map
[
int
]
actionType
,
str
string
)
map
[
int
]
actionType
{
keys
:=
parseKeyChords
(
str
,
"key name required"
)
keys
:=
parseKeyChords
(
str
,
"key name required"
,
true
)
if
len
(
keys
)
!=
1
{
errorExit
(
"multiple keys specified"
)
}
...
...
@@ -547,7 +575,7 @@ func parseOptions(opts *Options, allArgs []string) {
filter
:=
nextString
(
allArgs
,
&
i
,
"query string required"
)
opts
.
Filter
=
&
filter
case
"--expect"
:
opts
.
Expect
=
parseKeyChords
(
nextString
(
allArgs
,
&
i
,
"key names required"
),
"key names required"
)
opts
.
Expect
=
parseKeyChords
(
nextString
(
allArgs
,
&
i
,
"key names required"
),
"key names required"
,
false
)
case
"--tiebreak"
:
opts
.
Tiebreak
=
parseTiebreak
(
nextString
(
allArgs
,
&
i
,
"sort criterion required"
))
case
"--bind"
:
...
...
@@ -660,7 +688,7 @@ func parseOptions(opts *Options, allArgs []string) {
keymap
=
checkToggleSort
(
keymap
,
value
)
opts
.
ToggleSort
=
true
}
else
if
match
,
value
:=
optString
(
arg
,
"--expect="
);
match
{
opts
.
Expect
=
parseKeyChords
(
value
,
"key names required"
)
opts
.
Expect
=
parseKeyChords
(
value
,
"key names required"
,
false
)
}
else
if
match
,
value
:=
optString
(
arg
,
"--tiebreak="
);
match
{
opts
.
Tiebreak
=
parseTiebreak
(
value
)
}
else
if
match
,
value
:=
optString
(
arg
,
"--color="
);
match
{
...
...
This diff is collapsed.
Click to expand it.
src/options_test.go
+
21
−
7
View file @
7db53e64
...
...
@@ -72,7 +72,7 @@ func TestIrrelevantNth(t *testing.T) {
}
func
TestParseKeys
(
t
*
testing
.
T
)
{
keys
:=
parseKeyChords
(
"ctrl-z,alt-z,f2,@,Alt-a,!,ctrl-G,J,g"
,
""
)
keys
:=
parseKeyChords
(
"ctrl-z,alt-z,f2,@,Alt-a,!,ctrl-G,J,g"
,
""
,
false
)
check
:=
func
(
key
int
,
expected
int
)
{
if
key
!=
expected
{
t
.
Errorf
(
"%d != %d"
,
key
,
expected
)
...
...
@@ -88,6 +88,20 @@ func TestParseKeys(t *testing.T) {
check
(
keys
[
6
],
curses
.
CtrlA
+
'g'
-
'a'
)
check
(
keys
[
7
],
curses
.
AltZ
+
'J'
)
check
(
keys
[
8
],
curses
.
AltZ
+
'g'
)
// Synonyms
keys
=
parseKeyChords
(
"enter,return,space,tab,btab,esc,up,down,left,right"
,
""
,
true
)
check
(
len
(
keys
),
10
)
check
(
keys
[
0
],
curses
.
CtrlM
)
check
(
keys
[
1
],
curses
.
CtrlM
)
check
(
keys
[
2
],
curses
.
AltZ
+
' '
)
check
(
keys
[
3
],
curses
.
Tab
)
check
(
keys
[
4
],
curses
.
BTab
)
check
(
keys
[
5
],
curses
.
ESC
)
check
(
keys
[
6
],
curses
.
Up
)
check
(
keys
[
7
],
curses
.
Down
)
check
(
keys
[
8
],
curses
.
Left
)
check
(
keys
[
9
],
curses
.
Right
)
}
func
TestParseKeysWithComma
(
t
*
testing
.
T
)
{
...
...
@@ -97,36 +111,36 @@ func TestParseKeysWithComma(t *testing.T) {
}
}
keys
:=
parseKeyChords
(
","
,
""
)
keys
:=
parseKeyChords
(
","
,
""
,
false
)
check
(
len
(
keys
),
1
)
check
(
keys
[
0
],
curses
.
AltZ
+
','
)
keys
=
parseKeyChords
(
",,a,b"
,
""
)
keys
=
parseKeyChords
(
",,a,b"
,
""
,
false
)
check
(
len
(
keys
),
3
)
check
(
keys
[
0
],
curses
.
AltZ
+
'a'
)
check
(
keys
[
1
],
curses
.
AltZ
+
'b'
)
check
(
keys
[
2
],
curses
.
AltZ
+
','
)
keys
=
parseKeyChords
(
"a,b,,"
,
""
)
keys
=
parseKeyChords
(
"a,b,,"
,
""
,
false
)
check
(
len
(
keys
),
3
)
check
(
keys
[
0
],
curses
.
AltZ
+
'a'
)
check
(
keys
[
1
],
curses
.
AltZ
+
'b'
)
check
(
keys
[
2
],
curses
.
AltZ
+
','
)
keys
=
parseKeyChords
(
"a,,,b"
,
""
)
keys
=
parseKeyChords
(
"a,,,b"
,
""
,
false
)
check
(
len
(
keys
),
3
)
check
(
keys
[
0
],
curses
.
AltZ
+
'a'
)
check
(
keys
[
1
],
curses
.
AltZ
+
'b'
)
check
(
keys
[
2
],
curses
.
AltZ
+
','
)
keys
=
parseKeyChords
(
"a,,,b,c"
,
""
)
keys
=
parseKeyChords
(
"a,,,b,c"
,
""
,
false
)
check
(
len
(
keys
),
4
)
check
(
keys
[
0
],
curses
.
AltZ
+
'a'
)
check
(
keys
[
1
],
curses
.
AltZ
+
'b'
)
check
(
keys
[
2
],
curses
.
AltZ
+
'c'
)
check
(
keys
[
3
],
curses
.
AltZ
+
','
)
keys
=
parseKeyChords
(
",,,"
,
""
)
keys
=
parseKeyChords
(
",,,"
,
""
,
false
)
check
(
len
(
keys
),
1
)
check
(
keys
[
0
],
curses
.
AltZ
+
','
)
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment