From a042418162edc4d8ad30f930249a7e1a67937e16 Mon Sep 17 00:00:00 2001 From: Gabriel Scherer Date: Mon, 28 Sep 2015 10:30:33 +0200 Subject: [PATCH] Help message in the completion bar, for auto-discoverable bindings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/lTerm_read_line.ml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lTerm_read_line.ml b/src/lTerm_read_line.ml index 030b956f..8943e91e 100644 --- a/src/lTerm_read_line.ml +++ b/src/lTerm_read_line.ml @@ -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;