add UTop.smart_accept

Ignore-this: 77af81a81ba18fbc0c16f34873f0dd5a

darcs-hash:20110804143651-c41ad-307965f2bea7c3665165c968096404589a15968e
This commit is contained in:
Jeremie Dimino 2011-08-04 16:36:51 +02:00
parent e541018eac
commit 1e561069cf
3 changed files with 27 additions and 1 deletions

View File

@ -49,6 +49,8 @@ type profile = Dark | Light
let profile, set_profile = S.create Dark
let smart_accept = ref true
let size = UTop_private.size
let key_sequence = UTop_private.key_sequence

View File

@ -30,6 +30,11 @@ val profile : profile React.signal
val set_profile : profile -> unit
(** Sets the profile of the terminal. *)
val smart_accept : bool ref
(** If [true], then only lines terminated with ";;" will be sent to
ocaml, otherwise the input will always be sent to ocaml when the
user press Enter. It default to [true]. *)
val size : LTerm_geom.size React.signal
(** The current size of the terminal. *)

View File

@ -111,6 +111,11 @@ let rbrace = UChar.of_char '}'
let lbracket = UChar.of_char '['
let rbracket = UChar.of_char ']'
let rec last = function
| [] -> None
| [x] -> Some x
| _ :: l -> last l
class read_line ~term ~prompt =
let pending =
match !pending with
@ -120,7 +125,21 @@ class read_line ~term ~prompt =
let pending_length = Zed_utf8.length pending in
object(self)
inherit LTerm_read_line.read_line ~history:!history () as super
inherit [Zed_utf8.t] LTerm_read_line.term term
inherit [Zed_utf8.t] LTerm_read_line.term term as super_term
method exec = function
| LTerm_read_line.Accept :: actions -> begin
Zed_macro.add self#macro LTerm_read_line.Accept;
let tokens = UTop_lexer.lex_string (pending ^ Zed_rope.to_string (Zed_edit.text self#edit)) in
match last tokens with
| Some (Symbol, _, _, ";;") ->
return self#eval
| _ ->
self#insert (UChar.of_char '\n');
self#exec actions
end
| actions ->
super_term#exec actions
method stylise last =
let styled, position = super#stylise last in