Pass KeyShortcutHandler consumers a printable prefixmap represention. Close #154.

This commit is contained in:
2022-10-08 21:20:08 +00:00
parent b5c7b36e89
commit b93aa877e8
2 changed files with 11 additions and 3 deletions

View File

@@ -5,7 +5,7 @@ import kiss.Stream;
import kiss.List; import kiss.List;
typedef PrefixMap<T> = Map<String, ShortcutKey<T>>; typedef PrefixMap<T> = Map<String, ShortcutKey<T>>;
typedef PrefixMapHandler<T> = (Map<String, ShortcutKey<T>>) -> Void; typedef PrefixMapHandler<T> = (Map<String, ShortcutKey<T>>, Map<String,String>) -> Void;
typedef ItemHandler<T> = (T) -> Void; typedef ItemHandler<T> = (T) -> Void;
typedef FinishHandler = () -> Void; typedef FinishHandler = () -> Void;
typedef BadKeyHandler<T> = (String, PrefixMap<T>) -> Void; typedef BadKeyHandler<T> = (String, PrefixMap<T>) -> Void;

View File

@@ -21,7 +21,7 @@
(method _selectMap [m] (method _selectMap [m]
(set currentMap m) (set currentMap m)
(tryCall onSelectPrefixMap m)) (tryCall onSelectPrefixMap m (prefixMapToStrings m)))
(method start [] (method start []
(_selectMap rootMap)) (_selectMap rootMap))
@@ -99,4 +99,12 @@
(method :Void registerItem [description :T item] (method :Void registerItem [description :T item]
(whenLet [keyboardShortcut (extractKeyboardShortcuts description)] (whenLet [keyboardShortcut (extractKeyboardShortcuts description)]
(registerShortcut keyboardShortcut description item))) (registerShortcut keyboardShortcut description item)))
(method :Map<String,String> prefixMapToStrings [:PrefixMap<T> map]
(for =>key mapping map
=>key (case mapping
((Cancel _) "cancel")
((Final thing) (Std.string thing))
((Prefix map) (.join (collect (map.keys)) ", "))
(never null))))