MCPcopy
hub / github.com/peco/peco / KeyEventToString

Function KeyEventToString

internal/keyseq/keys.go:215–244  ·  view source on GitHub ↗

KeyEventToString returns a human-readable name for a key event described by the given key type, character, and modifier.

(key KeyType, ch rune, mod ModifierKey)

Source from the content-addressed store, hash-verified

213// KeyEventToString returns a human-readable name for a key event described
214// by the given key type, character, and modifier.
215func KeyEventToString(key KeyType, ch rune, mod ModifierKey) (string, error) {
216 var s string
217 if key == 0 {
218 s = string([]rune{ch})
219 } else {
220 var ok bool
221 s, ok = keyToString[key]
222 if !ok {
223 return "", fmt.Errorf("no such key %d (ch=%c)", key, ch)
224 }
225
226 // Special case for ArrowUp/Down/Left/Right
227 switch s {
228 case "ArrowUp":
229 s = "^"
230 case "ArrowDown":
231 s = "v"
232 case "ArrowLeft":
233 s = "<"
234 case "ArrowRight":
235 s = ">"
236 }
237 }
238
239 if m := mod.String(); m != "" {
240 return m + "-" + s, nil
241 }
242
243 return s, nil
244}
245
246// ToKey parses a single key name string into its KeyType, modifier, and rune components.
247func ToKey(key string) (KeyType, ModifierKey, rune, error) {

Callers 3

wrapRememberSequenceFunction · 0.92
wrapClearSequenceFunction · 0.92

Calls 1

StringMethod · 0.65

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…