lambda-term
lambda-term copied to clipboard
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.
Also, we could discuss other "auto-discovery features" that would benefit utop and other lambda-term-using projects. For example right now when nothing is typed in the bar, utop proposes to complete module identifiers, and it is kind of noisy and not so useful in my opinion. I would rather use the space to provide some hints of useful key-bindings that users will not naturally try (I mean the basic history navigation is intuitive and familiar, but for example notifying users that search-in-history is available could be useful). We could have a fixed hint message, or rotate. What do you think?
I think it's a good idea to have this kind of contextual help.
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.
We can get the exact bindings by looking at the LTerm_read_line.bindings variable, and print them with LTerm_key.to_string_compact. To make the hint message configurable, the [engine] class could have a hint method in the same style as the message method:
method hint : LTerm_text.t option signal
Also, we could discuss other "auto-discovery features" that would benefit utop and other lambda-term-using projects. For example right now when nothing is typed in the bar, utop proposes to complete module identifiers, and it is kind of noisy and not so useful in my opinion. I would rather use the space to provide some hints of useful key-bindings that users will not naturally try (I mean the basic history navigation is intuitive and familiar, but for example notifying users that search-in-history is available could be useful). We could have a fixed hint message, or rotate. What do you think?
I think fixed for a given prompt: i.e. if you start typing and delete everything you get the same thing. But can change with new prompts. It could be connected to what happened: UTop waited on a Lwt.t thread, change with UTop.set_auto_run_lwt. We could also display longer hints on utop startup.
Is this still of interest? It's been in the queue for three years. If so, lets finish it up.