ValidateKeyBindings checks if all key specifications are valid.
(kb KeyBindings)
| 292 | |
| 293 | // ValidateKeyBindings checks if all key specifications are valid. |
| 294 | func ValidateKeyBindings(kb KeyBindings) error { |
| 295 | bindings := keyBindingsToMap(kb) |
| 296 | defaultMap := keyBindingsToMap(DefaultKeyBindings()) |
| 297 | |
| 298 | seen := make(map[string]string) |
| 299 | |
| 300 | for name, spec := range bindings { |
| 301 | if spec == "" { |
| 302 | continue |
| 303 | } |
| 304 | |
| 305 | key, r, mod, err := keys.Parse(spec) |
| 306 | if err != nil { |
| 307 | return fmt.Errorf("invalid key binding %s: %w", name, err) |
| 308 | } |
| 309 | |
| 310 | if keys.IsReserved(key, r, mod) && spec != defaultMap[name] { |
| 311 | return fmt.Errorf("key binding %s uses reserved key %s", name, spec) |
| 312 | } |
| 313 | |
| 314 | id := keys.CanonicalID(key, r, mod) |
| 315 | if other, ok := seen[id]; ok { |
| 316 | return fmt.Errorf("key binding %s duplicates %s", name, other) |
| 317 | } |
| 318 | |
| 319 | seen[id] = name |
| 320 | } |
| 321 | |
| 322 | return nil |
| 323 | } |
| 324 | |
| 325 | // NewConfig creates a new Config instance populated with values from environment variables. |
| 326 | // |