... | ... |
@@ -95,8 +95,24 @@ |
95 | 95 |
:selected-history {:orig orig |
96 | 96 |
:index (next idx)}}))) |
97 | 97 |
|
98 |
+(defn cycle-suggestions [cmd direction] |
|
99 |
+ (let [{:keys [options selected]} (cmd :suggestions) |
|
100 |
+ next (case direction :backward dec :forward inc) |
|
101 |
+ nopts (count options) |
|
102 |
+ next-selected (cond |
|
103 |
+ (nil? selected) 0 |
|
104 |
+ (>= (next selected) nopts) 0 |
|
105 |
+ (< (next selected) 0) (- nopts 1) |
|
106 |
+ :else (next selected))] |
|
107 |
+ (when (not-empty options) |
|
108 |
+ {:suggestions {:options options :selected next-selected}}))) |
|
109 |
+ |
|
98 | 110 |
(def null-suggestions {:options nil :selected nil}) |
99 | 111 |
|
112 |
+(defn complete-suggestion [{:keys [suggestions]}] |
|
113 |
+ (let [{:keys [options selected]} suggestions] |
|
114 |
+ {:current (nth options selected) :suggestions null-suggestions})) |
|
115 |
+ |
|
100 | 116 |
(re-frame/reg-event-db |
101 | 117 |
::prompt-keypress |
102 | 118 |
(re-frame/path :cmdline) |