From 05b2b2cf3080eed81c231dc1fd9b3f14c288f606 Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Thu, 4 Aug 2011 09:35:22 +0200 Subject: [PATCH] dislpay the current key sequence Ignore-this: 603951c76e406e726eaf6e00bfadba27 darcs-hash:20110804073522-c41ad-2420851c7dbcbb13b4952113ebec3a31565e6ead --- src/uTop.ml | 45 +++++++++++++++++++++++++++++++-------------- src/uTop.mli | 3 +++ src/uTop_console.ml | 2 ++ src/uTop_private.ml | 4 ++++ 4 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/uTop.ml b/src/uTop.ml index a556ec9..2320445 100644 --- a/src/uTop.ml +++ b/src/uTop.ml @@ -42,9 +42,11 @@ let profile, set_profile = S.create Dark let size = UTop_private.size +let key_sequence = UTop_private.key_sequence + let count = UTop_private.count -let make_prompt profile count size recording macro_count macro_counter = +let make_prompt profile count size key_sequence (recording, macro_count, macro_counter) = let tm = Unix.localtime (Unix.time ()) in let color dark light = match profile with @@ -53,15 +55,28 @@ let make_prompt profile count size recording macro_count macro_counter = in let bold = profile = Dark in let txta = - eval [ - B_bold bold; - B_fg (color lcyan blue); - S "─( "; - B_fg (color lmagenta magenta); S (Printf.sprintf "%02d:%02d:%02d" tm.Unix.tm_hour tm.Unix.tm_min tm.Unix.tm_sec); E_fg; - S " )─< "; - B_fg (color lyellow yellow); S (Printf.sprintf "command %d" count); E_fg; - S " >─"; - ] + if key_sequence = [] then + eval [ + B_bold bold; + B_fg (color lcyan blue); + S "─( "; + B_fg (color lmagenta magenta); S (Printf.sprintf "%02d:%02d:%02d" tm.Unix.tm_hour tm.Unix.tm_min tm.Unix.tm_sec); E_fg; + S " )─< "; + B_fg (color lyellow yellow); S (Printf.sprintf "command %d" count); E_fg; + S " >─"; + ] + else + eval [ + B_bold bold; + B_fg (color lcyan blue); + S "─( "; + B_fg (color lmagenta magenta); S (Printf.sprintf "%02d:%02d:%02d" tm.Unix.tm_hour tm.Unix.tm_min tm.Unix.tm_sec); E_fg; + S " )─< "; + B_fg (color lyellow yellow); S (Printf.sprintf "command %d" count); E_fg; + S " >─[ "; + B_fg (color lgreen green); S (String.concat " " (List.map LTerm_key.to_string_compact key_sequence)); E_fg; + S " ]─"; + ] in let txtb = if recording then @@ -97,13 +112,15 @@ let make_prompt profile count size recording macro_count macro_counter = ) [|(UChar.of_char '#', { none with foreground = Some (color lgreen green) }); (UChar.of_char ' ', none)|] let prompt = ref ( - S.l6 make_prompt + S.l5 make_prompt profile count size - (Zed_macro.recording LTerm_read_line.macro) - (Zed_macro.count LTerm_read_line.macro) - (Zed_macro.counter LTerm_read_line.macro) + key_sequence + (S.l3 (fun x y z -> (x, y, z)) + (Zed_macro.recording LTerm_read_line.macro) + (Zed_macro.count LTerm_read_line.macro) + (Zed_macro.counter LTerm_read_line.macro)) ) let prompt_continue = ref (S.map (fun profile -> [|(UChar.of_char '>', { none with foreground = Some (if profile = Dark then lgreen else green) }); (UChar.of_char ' ', LTerm_style.none)|]) profile) diff --git a/src/uTop.mli b/src/uTop.mli index 958c02b..67b2995 100644 --- a/src/uTop.mli +++ b/src/uTop.mli @@ -33,6 +33,9 @@ val set_profile : profile -> unit val size : LTerm_geom.size React.signal (** The current size of the terminal. *) +val key_sequence : LTerm_key.t list React.signal + (** The current key sequence entered by the user. *) + val prompt : LTerm_text.t React.signal ref (** The current prompt. diff --git a/src/uTop_console.ml b/src/uTop_console.ml index fe9e92a..b21ec1b 100644 --- a/src/uTop_console.ml +++ b/src/uTop_console.ml @@ -435,6 +435,8 @@ object(self) initializer (* Set the source signal for the size of the terminal. *) UTop_private.set_size self#size; + (* Set the source signal for the key sequence. *) + UTop_private.set_key_sequence self#key_sequence; (* Set the prompt. *) self#set_prompt prompt end diff --git a/src/uTop_private.ml b/src/uTop_private.ml index 65c0b08..9bb71a4 100644 --- a/src/uTop_private.ml +++ b/src/uTop_private.ml @@ -13,4 +13,8 @@ let size, set_size = let ev, set_size = E.create () in (S.switch (S.const { LTerm_geom.rows = 0; LTerm_geom.cols = 0 }) ev, set_size) +let key_sequence, set_key_sequence = + let ev, set_key_sequence = E.create () in + (S.switch (S.const ([] : LTerm_key.t list)) ev, set_key_sequence) + let count, set_count = S.create(-1)