package textutils

  1. Overview
  2. Docs

Source file ascii_table_kernel.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
open! Core
open! Import
include Ascii_table_kernel_intf
module Align = Column.Align
module Attr = Attr
module Column = Column
module Table_char = Table_char

module Display = struct
  type t = Grid.Display.t =
    | Short_box
    | Tall_box
    | Line
    | Blank
    | Column_titles
  [@@deriving compare, sexp_of]

  let short_box = Short_box
  let tall_box = Tall_box
  let line = Line
  let blank = Blank
  let column_titles = Column_titles
end

module Screen = struct
  (* [Screen] is mostly private stuff, so we explicitly export the public bits instead of
     saying [Private] everywhere. *)

  type t = Screen.t

  let render = Screen.render
  let to_string = Screen.to_string
end

let draw
  ?(display = Display.short_box)
  ?(spacing = 1)
  ?(limit_width_to = 90)
  ?(header_attr = [])
  ?(display_empty_rows = false)
  ~prefer_split_on_spaces
  cols
  data
  =
  match cols with
  | [] -> None
  | _ :: _ ->
    Some
      (Grid.create
         ~spacing
         ~display
         ~max_width:limit_width_to
         ~header_attr
         cols
         data
         ~display_empty_rows
         ~prefer_split_on_spaces
       |> Grid.to_screen ~prefer_split_on_spaces)
;;

let to_string_noattr
  ?display
  ?spacing
  ?limit_width_to
  ?display_empty_rows
  ?(prefer_split_on_spaces = false)
  cols
  data
  ~bars
  =
  draw
    ?display
    ?spacing
    ?limit_width_to
    ?display_empty_rows
    ~header_attr:[]
    cols
    data
    ~prefer_split_on_spaces
  |> Option.map ~f:(Screen.to_string ~bars ~string_with_attr:(fun _attr s -> s))
  |> Option.value ~default:""
;;

module Private = struct
  module Utf8_text_chunks = Utf8_text_chunks
end
OCaml

Innovation. Community. Security.