mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-07 11:45:31 -05:00
minor updates (new functions in CCPrint and PrintBox)
This commit is contained in:
parent
b01a302f07
commit
10a1a0643e
4 changed files with 50 additions and 2 deletions
|
|
@ -128,3 +128,17 @@ let fprintf oc format =
|
||||||
let printf format = fprintf stdout format
|
let printf format = fprintf stdout format
|
||||||
let eprintf format = fprintf stderr format
|
let eprintf format = fprintf stderr format
|
||||||
|
|
||||||
|
let _with_file_out filename f =
|
||||||
|
let oc = open_out filename in
|
||||||
|
begin try
|
||||||
|
let x = f oc in
|
||||||
|
flush oc;
|
||||||
|
close_out oc;
|
||||||
|
x
|
||||||
|
with e ->
|
||||||
|
close_out_noerr oc;
|
||||||
|
raise e
|
||||||
|
end
|
||||||
|
|
||||||
|
let to_file filename format =
|
||||||
|
_with_file_out filename (fun oc -> fprintf oc format)
|
||||||
|
|
|
||||||
|
|
@ -69,5 +69,8 @@ val sprintf : ('a, Buffer.t, unit, string) format4 -> 'a
|
||||||
val fprintf : out_channel -> ('a, Buffer.t, unit, unit) format4 -> 'a
|
val fprintf : out_channel -> ('a, Buffer.t, unit, unit) format4 -> 'a
|
||||||
(** Print on a channel *)
|
(** Print on a channel *)
|
||||||
|
|
||||||
|
val to_file : string -> ('a, Buffer.t, unit, unit) format4 -> 'a
|
||||||
|
(** Print to the given file *)
|
||||||
|
|
||||||
val printf : ('a, Buffer.t, unit, unit) format4 -> 'a
|
val printf : ('a, Buffer.t, unit, unit) format4 -> 'a
|
||||||
val eprintf : ('a, Buffer.t, unit, unit) format4 -> 'a
|
val eprintf : ('a, Buffer.t, unit, unit) format4 -> 'a
|
||||||
|
|
|
||||||
|
|
@ -359,6 +359,25 @@ let _write_hline ~out pos n =
|
||||||
Output.put_char out (_move_x pos i) '-'
|
Output.put_char out (_move_x pos i) '-'
|
||||||
done
|
done
|
||||||
|
|
||||||
|
type simple_box =
|
||||||
|
[ `Empty
|
||||||
|
| `Pad of simple_box
|
||||||
|
| `Text of string
|
||||||
|
| `Vlist of simple_box list
|
||||||
|
| `Hlist of simple_box list
|
||||||
|
| `Table of simple_box array array
|
||||||
|
| `Tree of simple_box * simple_box list
|
||||||
|
]
|
||||||
|
|
||||||
|
let rec of_simple = function
|
||||||
|
| `Empty -> empty
|
||||||
|
| `Pad b -> pad (of_simple b)
|
||||||
|
| `Text t -> pad (text t)
|
||||||
|
| `Vlist l -> vlist (List.map of_simple l)
|
||||||
|
| `Hlist l -> hlist (List.map of_simple l)
|
||||||
|
| `Table a -> grid (Box._map_matrix of_simple a)
|
||||||
|
| `Tree (b,l) -> tree (of_simple b) (List.map of_simple l)
|
||||||
|
|
||||||
(* render given box on the output, starting with upper left corner
|
(* render given box on the output, starting with upper left corner
|
||||||
at the given position. [expected_size] is the size of the
|
at the given position. [expected_size] is the size of the
|
||||||
available surrounding space. [offset] is the offset of the box
|
available surrounding space. [offset] is the offset of the box
|
||||||
|
|
|
||||||
|
|
@ -182,6 +182,18 @@ val mk_tree : ?indent:int -> ('a -> Box.t * 'a list) -> 'a -> Box.t
|
||||||
(** Definition of a tree with a local function that maps nodes to
|
(** Definition of a tree with a local function that maps nodes to
|
||||||
their content and children *)
|
their content and children *)
|
||||||
|
|
||||||
|
type simple_box =
|
||||||
|
[ `Empty
|
||||||
|
| `Pad of simple_box
|
||||||
|
| `Text of string
|
||||||
|
| `Vlist of simple_box list
|
||||||
|
| `Hlist of simple_box list
|
||||||
|
| `Table of simple_box array array
|
||||||
|
| `Tree of simple_box * simple_box list
|
||||||
|
]
|
||||||
|
|
||||||
|
val of_simple : simple_box -> Box.t
|
||||||
|
|
||||||
(** {2 Rendering} *)
|
(** {2 Rendering} *)
|
||||||
|
|
||||||
val render : Output.t -> Box.t -> unit
|
val render : Output.t -> Box.t -> unit
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue