From: Michael D. Lowis Date: Tue, 24 Oct 2017 17:01:08 +0000 (-0400) Subject: tweaked interfaces and added a scrollmap hook for unit tests X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=c599e3b6b73d033d5045f6ddf0813654488b19e8;p=archive%2Ftide-ocaml.git tweaked interfaces and added a scrollmap hook for unit tests --- diff --git a/edit.ml b/edit.ml index 84dae0b..3403e0c 100644 --- a/edit.ml +++ b/edit.ml @@ -19,9 +19,9 @@ let draw_bkg color width height pos = draw_rect { x = pos.x; y = pos.y; w = width; h = height; c = color } (* curried helpers *) -let draw_dark_bkg = draw_bkg Cfg.Color.palette.(0) +let draw_dark_bkg = draw_bkg Cfg.Color.palette.(0) let draw_light_bkg = draw_bkg Cfg.Color.palette.(1) -let draw_gray_bkg = draw_bkg Cfg.Color.palette.(3) +let draw_gray_bkg = draw_bkg Cfg.Color.palette.(3) let draw_text text pos = draw_string font Cfg.Color.palette.(5) text (pos.x + 2, pos.y + 2); @@ -63,7 +63,6 @@ let draw_buffer pos width height = | 0x0D -> () | 0x09 -> let tabsz = ((X11.get_glyph font tabglyph).xoff * tabwidth) in - let ntabs = (width - pos.x) / tabsz in x := pos.x + (((!x - pos.x) + tabsz) / tabsz * tabsz) | _ -> begin if (!x + glyph.xoff) > width then (newline ()); @@ -72,7 +71,7 @@ let draw_buffer pos width height = end); ((!y + font.height) < height) in - Buf.iter_from draw_char !edit_buf !edit_buf.start; + Buf.iter_from draw_char !edit_buf (Buf.start !edit_buf); pos let draw_edit pos width height = @@ -86,11 +85,10 @@ let onfocus focused = () (*print_endline "onfocus"*) let onkeypress mods rune = - print_endline "scroll up" + () let onmousebtn mods btn x y pressed = - print_endline "scroll down"; - edit_buf := { !edit_buf with start = !edit_buf.start + 1} + () let onmousemove mods x y = () (*print_endline "onmousemove"*) diff --git a/lib/buf.ml b/lib/buf.ml index 737e951..ee81c8f 100644 --- a/lib/buf.ml +++ b/lib/buf.ml @@ -1,13 +1,9 @@ -type cursor = { start : int; stop : int } - type t = { start : int; path : string; rope : Rope.t } -let font = X11.font_load "Verdana:size=11:antialias=true:autohint=true" - let empty = { start = 0; path = ""; rope = Rope.empty } @@ -17,29 +13,12 @@ let load path = let rope buf = buf.rope +let start buf = + buf.start + let iter_from fn buf i = Rope.iter_from fn buf.rope i - - -(* - -let make_cursor buf start stop = - { start = (Rope.limit_index buf.rope start); - stop = (Rope.limit_index buf.rope stop) } - -let move_rune count csr buf ext = - let newstop = csr.stop + count in - let newstart = if ext then csr.start else newstop in - make_cursor buf newstart newstop - -let move_word count csr buf ext = - () - -let move_line count csr buf ext = - () - -*) (* Unit Tests *****************************************************************) let run_unit_tests () = diff --git a/lib/buf.mli b/lib/buf.mli new file mode 100644 index 0000000..5705ee6 --- /dev/null +++ b/lib/buf.mli @@ -0,0 +1,6 @@ +type t +val empty : t +val load : string -> t +val rope : t -> Rope.t +val start : t -> int +val iter_from : (int -> bool) -> t -> int -> unit diff --git a/lib/scrollmap.ml b/lib/scrollmap.ml index 404b000..7c8c7ed 100644 --- a/lib/scrollmap.ml +++ b/lib/scrollmap.ml @@ -3,6 +3,10 @@ type t = { map : int array } -let make buf off = - let bol = (Rope.to_bol (Buf.rope buf) off) in +let make buf = + let bol = (Rope.to_bol (Buf.rope buf) (Buf.start buf)) in { index = 0; map = [||] } + +(* Unit Tests** ***************************************************************) + +let run_unit_tests () = () diff --git a/lib/scrollmap.mli b/lib/scrollmap.mli index 1d37c0a..52ab685 100644 --- a/lib/scrollmap.mli +++ b/lib/scrollmap.mli @@ -1,2 +1,3 @@ type t -val make : Buf.t -> int -> t +val make : Buf.t -> t +val run_unit_tests : unit -> unit