From: Michael D. Lowis Date: Wed, 25 Oct 2017 20:13:49 +0000 (-0400) Subject: Added skeleton logic for building the scrollmap X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=67b9c2cec3333b931163b9f97c18ff3a10d0c6e6;p=archive%2Ftide-ocaml.git Added skeleton logic for building the scrollmap --- diff --git a/edit.ml b/edit.ml index 3f6ee0f..b51ed48 100644 --- a/edit.ml +++ b/edit.ml @@ -18,7 +18,8 @@ let onupdate width height = Draw.status csr "UNSI> *scratch*"; Draw.tags csr !tags_buf; Draw.scroll csr; - Draw.edit csr !edit_buf + Draw.edit csr !edit_buf; + let _ = Scrollmap.make !edit_buf width height 0 in () let onshutdown () = () diff --git a/lib/buf.ml b/lib/buf.ml index ee81c8f..10ca997 100644 --- a/lib/buf.ml +++ b/lib/buf.ml @@ -19,6 +19,9 @@ let start buf = let iter_from fn buf i = Rope.iter_from fn buf.rope i +let iteri_from fn buf i = + Rope.iteri_from fn buf.rope i + (* Unit Tests *****************************************************************) let run_unit_tests () = diff --git a/lib/buf.mli b/lib/buf.mli index 5705ee6..37720f1 100644 --- a/lib/buf.mli +++ b/lib/buf.mli @@ -4,3 +4,4 @@ val load : string -> t val rope : t -> Rope.t val start : t -> int val iter_from : (int -> bool) -> t -> int -> unit +val iteri_from : (int -> int -> bool) -> t -> int -> unit diff --git a/lib/scrollmap.ml b/lib/scrollmap.ml index 7c8c7ed..d1a0e2b 100644 --- a/lib/scrollmap.ml +++ b/lib/scrollmap.ml @@ -3,10 +3,22 @@ type t = { map : int array } -let make buf = - let bol = (Rope.to_bol (Buf.rope buf) (Buf.start buf)) in +let make buf width height off = + let bol = (Rope.to_bol (Buf.rope buf) off) in + let lines = ref [bol] in + let csr = Draw.Cursor.make (width, 0) 0 0 in + let process_glyph i c = + let open Draw.Cursor in + next_glyph csr c false; + (*if csr.startx == csr.x then + lines := i :: !lines;*) + ((Rope.is_eol (Buf.rope buf) i) == false) + in + Buf.iteri_from process_glyph buf off; + List.iter (fun n -> Printf.printf "%d " n) !lines; + print_endline ""; { index = 0; map = [||] } -(* Unit Tests** ***************************************************************) +(* Unit Tests *****************************************************************) let run_unit_tests () = () diff --git a/lib/scrollmap.mli b/lib/scrollmap.mli index 52ab685..2e8723e 100644 --- a/lib/scrollmap.mli +++ b/lib/scrollmap.mli @@ -1,3 +1,3 @@ type t -val make : Buf.t -> t +val make : Buf.t -> int -> int -> int -> t val run_unit_tests : unit -> unit