Skip to content

Commit caf8ee9

Browse files
committed
Help message in the completion bar, for auto-discoverable bindings
Having #utop_help;; is great, but the best help is a feature that user can discover during their normal interaction with the tool. (utop is already strong on this point thanks to the fact that, for example, typing `#` allows to discover toplevel directives.) This patch makes the key-bindings useful to navigate the completion bar auto-discoverable by printing them (right-justified) inside the bar whenever there is enough space to do so. Before: ``` utop # Ar ┌───┬────────────┬─────┬───────────┬─────────────────────────────────────────────────────────┐ │Arg│Arith_status│Array│ArrayLabels│ │ └───┴────────────┴─────┴───────────┴─────────────────────────────────────────────────────────┘ ``` After: ``` utop # Ar ┌───┬────────────┬─────┬───────────┬─────────────────────────────────────────────────────────┐ │Arg│Arith_status│Array│ArrayLabels│ (M-left, M-right, M-enter)│ └───┴────────────┴─────┴───────────┴─────────────────────────────────────────────────────────┘ ``` This patch is only a very first attempt to get this feature (in limited time). Hard-coding the precise key-bindings at the lambda-term level is certainly the wrong design choice. I suppose the help message should be configurable, and I would welcome advice on what a better interface would be.
1 parent 5d46116 commit caf8ee9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/lTerm_read_line.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,11 @@ object(self)
942942

943943
let rec loop idx col = function
944944
| [] ->
945-
()
945+
let help_message = "(M-left, M-right, M-enter)" in
946+
let right_col = size.cols - 2 - Zed_utf8.length help_message in
947+
(* do we have enough space to draw the message right-justified? *)
948+
if right_col >= col then
949+
LTerm_draw.draw_string ctx 0 right_col help_message;
946950
| (word, suffix) :: words ->
947951
let len = Zed_utf8.length word in
948952
LTerm_draw.draw_string ctx 0 col word;

0 commit comments

Comments
 (0)