aboutsummaryrefslogtreecommitdiff
path: root/screen.ml
diff options
context:
space:
mode:
Diffstat (limited to 'screen.ml')
-rwxr-xr-xscreen.ml67
1 files changed, 32 insertions, 35 deletions
diff --git a/screen.ml b/screen.ml
index 69290d7..d48381a 100755
--- a/screen.ml
+++ b/screen.ml
@@ -162,9 +162,8 @@ let init () = begin
&& Curses.init_pair 3 Color.black Color.white (* Selected cell *)
&& Curses.init_pair 4 Color.black Color.red (* referenced cell *)
&& Curses.init_pair 5 Color.black Color.green (* sink cell *)
- && Curses.curs_set 0
+ && Curses.curs_set 0 in
- in
if not init then
raise (Failure "Initialisation")
else
@@ -186,31 +185,30 @@ end
let draw_input t screen = begin
- let height, width = screen.size in
+ let height, width = screen.size in
- let expr = Sheet.Raw.get_expr (Selection.extract t.Sheet.selected) t.Sheet.data
- |> Expression.show in
+ let expr = Sheet.Raw.get_expr (Selection.extract t.Sheet.selected) t.Sheet.data
+ |> Expression.show in
- (* Compute the difference between number of bytes in the string, and the
- number of character printed : Printf.sprintf format use the bytes number
- in the string, while Curses print the characters in the user encoding *)
- let result = Sheet.Raw.get_value (Selection.extract t.Sheet.selected) t.Sheet.data
- |> ScTypes.Result.show in
- let encoded_result = UTF8.encode result in
- let result_length_delta = (UTF8.length result) - (String.length encoded_result) in
+ (* Compute the difference between number of bytes in the string, and the
+ number of character printed : Printf.sprintf format use the bytes number
+ in the string, while Curses print the characters in the user encoding *)
+ let result = Sheet.Raw.get_value (Selection.extract t.Sheet.selected) t.Sheet.data
+ |> ScTypes.Result.show in
+ let encoded_result = UTF8.encode result in
+ let result_length_delta = (UTF8.length result) - (String.length encoded_result) in
- ignore (
- encoded_result
- |> Printf.sprintf "%-*s" (width - 11 - result_length_delta)
- |> Curses.mvwaddstr screen.input 0 10
+ ignore (
+ encoded_result
+ |> Printf.sprintf "%-*s" (width - 11 - result_length_delta)
+ |> Curses.mvwaddstr screen.input 0 10
- && Curses.wrefresh screen.input);
- status screen expr;
- screen
+ && Curses.wrefresh screen.input);
+ status screen expr;
+ screen
end
(** Wait for an event and return the key pressed
- The signal is always followed by NULL character (0x00)
If the key code contains more than one char, they are both returned
*)
let read_key {window} = begin
@@ -227,8 +225,7 @@ let read_key {window} = begin
| x -> Buffer.add_char buff @@ char_of_int x;
end;
ignore @@ Curses.nodelay window false;
- let content = Buffer.contents buff in
- content
+ Buffer.contents buff
end
let resize data t = begin
@@ -279,10 +276,12 @@ let editor ?position ?(prefix=UTF8.empty) ?(init=UTF8.empty) t = begin
done;
end in
- let rec _edit (before:UTF8.t list) after = begin function
- (* [before] contains all the caracters inserted before the cursor (reverse
- ordered), while [after] contains all the caracters after the cursor.
+ (* Text edition, handle the keycode.
+
+ [before] contains all the caracters inserted before the cursor (reverse
+ ordered), and [after] contains all the caracters after the cursor.
*)
+ let rec _edit before after = begin function
| "\027" -> (* Escape, cancel the modifications *)
None
| "\010" -> (* Enter, validate the input *)
@@ -422,15 +421,12 @@ let editor ?position ?(prefix=UTF8.empty) ?(init=UTF8.empty) t = begin
end
in
- ignore @@ Curses.curs_set 1;
- let mode = if with_refs then
- select_content position (UTF8.empty)
- else
- _edit in
- let res = mode (UTF8.rev_explode init) [] @@ read_key t in
- ignore @@ Curses.curs_set 0;
- res
-
+ Tools.try_finally
+ (fun () ->
+ ignore @@ Curses.curs_set 1;
+ try _edit (UTF8.rev_explode init) [] @@ read_key t
+ with _ -> None)
+ (fun () -> ignore @@ Curses.curs_set 0)
end
@@ -442,6 +438,7 @@ let search screen = begin
end
end
+(*
let read_input position screen = begin
let result = editor ~position ~init:(u"=") screen in
begin match result with
@@ -449,4 +446,4 @@ let read_input position screen = begin
| None -> UTF8.empty
end
end
-
+*)