From 08e90070acd6b00ad970caf5c0a2f36c9ea07a5c Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 10 Aug 2021 21:23:58 +0530 Subject: add connector customization --- src/chart.ml | 5 ++--- src/connector.ml | 6 ++++++ src/options.ml | 17 +++++++++++++++-- 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 src/connector.ml diff --git a/src/chart.ml b/src/chart.ml index 194e3ba..39f97f9 100644 --- a/src/chart.ml +++ b/src/chart.ml @@ -29,9 +29,8 @@ let pp formatter { vals : int list; opts : Options.t } = match Stdlib.compare s e with | 0 -> make_marker axis_spc s (height - s) "-" | x -> - let ltr_chr, rtl_chr = - match x with 1 -> ("└", "┐") | _ -> ("┘", "┌") - in + let dr, rd, ru, ur = Connector.of_kind opts.connector in + let ltr_chr, rtl_chr = match x with 1 -> (dr, rd) | _ -> (ru, ur) in let st, en = Stdlib.(min s e, max s e) in let l = en - st |> saturating_sub 1 in let left, right = (repeat st space, repeat (height - l - st) space) in diff --git a/src/connector.ml b/src/connector.ml new file mode 100644 index 0000000..d00d036 --- /dev/null +++ b/src/connector.ml @@ -0,0 +1,6 @@ +type t = Squared | Rounded + +let of_kind (k : t) = + match k with + | Squared -> ("└", "┐", "┘", "┌") + | Rounded -> ("╰", "╮", "╯", "╭") diff --git a/src/options.ml b/src/options.ml index 341c0bb..fa49ef1 100644 --- a/src/options.ml +++ b/src/options.ml @@ -1,7 +1,20 @@ -type t = { height : int; ascii : bool; marker : Marker.t } +type t = { + height : int; + ascii : bool; + marker : Marker.t; + connector : Connector.t; +} -let default = { height = 14; ascii = false; marker = Marker.Circle } +let default = + { + height = 14; + ascii = false; + marker = Marker.Circle; + connector = Connector.Rounded; + } let with_height v c = { c with height = v } let with_marker v c = { c with marker = v } + +let with_connector v c = { c with connector = v } -- cgit v1.2.3