Skip to content

Commit

Permalink
Help message in the completion bar, for auto-discoverable bindings
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gasche committed Sep 28, 2015
1 parent 5d46116 commit caf8ee9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lTerm_read_line.ml
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,11 @@ object(self)

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

0 comments on commit caf8ee9

Please sign in to comment.