···
14
-
(** Scale factor for text rendering (1-7).
14
+
(** Vertical alignment for fractionally scaled text. *)
15
+
type vertical = [ `Bottom | `Center | `Top ]
16
-
Controls the overall size of the text block. A scale of [s] will render text
17
-
in a block of [s * w] by [s] cells (where [w] is the width parameter). *)
18
-
type scale = private int
17
+
(** Horizontal alignment for fractionally scaled text. *)
18
+
type horizontal = [ `Left | `Center | `Right ]
20
-
(** Width in cells for text rendering (0-7).
20
+
(** Abstract metadata for text sizing. *)
22
-
When set to 0, width is auto-calculated based on text length. *)
23
-
type width = private int
23
+
(** {1 Constructor} *)
25
-
(** Fractional scaling numerator (0-15).
25
+
(** [v ?scale ?width ?fraction ?vertical ?horizontal ()] creates text sizing metadata.
27
-
Used together with denominator for precise fractional scaling. *)
28
-
type numerator = private int
27
+
@param scale Scale factor (1-7)
28
+
@param width Width in cells (0-7)
29
+
@param fraction Fractional scaling as (numerator, denominator) where both are 0-15
30
+
@param vertical Vertical alignment
31
+
@param horizontal Horizontal alignment
32
+
@raise Invalid_argument if any parameter is out of range *)
36
+
?fraction:(int * int) ->
37
+
?vertical:vertical ->
38
+
?horizontal:horizontal ->
30
-
(** Fractional scaling denominator (0-15).
41
+
(** Empty metadata (all fields set to [None]). Equivalent to [v ()]. *)
32
-
Used together with numerator for precise fractional scaling. *)
33
-
type denominator = private int
44
+
(** {1 Escape Sequence Generation} *)
35
-
(** Vertical alignment for fractionally scaled text.
36
-
- [Bottom]: Align to bottom (0)
37
-
- [Center]: Align to center (1)
38
-
- [Top]: Align to top (2) *)
39
-
type vertical_align =
46
+
(** [render t text] generates the complete escape sequence for sized text.
44
-
(** Horizontal alignment for fractionally scaled text.
45
-
- [Left]: Align to left (0)
46
-
- [Center]: Align to center (1)
47
-
- [Right]: Align to right (2) *)
48
-
type horizontal_align =
48
+
@param t The sizing metadata
49
+
@param text The text to render (max 4096 bytes of UTF-8)
50
+
@return The escape sequence string
51
+
@raise Invalid_argument if text exceeds 4096 bytes *)
52
+
val render : t -> string -> string
53
-
(** Metadata for text sizing. *)
55
-
scale : scale option;
56
-
width : width option;
57
-
numerator : numerator option;
58
-
denominator : denominator option;
59
-
vertical : vertical_align option;
60
-
horizontal : horizontal_align option;
54
+
(** [render_to_channel oc t text] writes the escape sequence to a channel.
63
-
(** {1 Constructors} *)
56
+
@param oc Output channel
57
+
@param t The sizing metadata
58
+
@param text The text to render (max 4096 bytes of UTF-8)
59
+
@raise Invalid_argument if text exceeds 4096 bytes *)
60
+
val render_to_channel : out_channel -> t -> string -> unit
65
-
(** [make_scale n] creates a scale value.
66
-
@raise Invalid_argument if [n] is not in range 1-7. *)
67
-
val make_scale : int -> scale
62
+
(** {1 Fmt-style Combinators} *)
69
-
(** [make_width n] creates a width value.
70
-
@raise Invalid_argument if [n] is not in range 0-7. *)
71
-
val make_width : int -> width
64
+
(** [pp t] creates a Fmt formatter that wraps text with sizing metadata.
73
-
(** [make_numerator n] creates a numerator value.
74
-
@raise Invalid_argument if [n] is not in range 0-15. *)
75
-
val make_numerator : int -> numerator
68
+
Fmt.pr "This is %a" (Textsize.pp (Textsize.with_scale 2 Textsize.empty)) "big"
71
+
val pp : t -> string Fmt.t
77
-
(** [make_denominator n] creates a denominator value.
78
-
@raise Invalid_argument if [n] is not in range 0-15. *)
79
-
val make_denominator : int -> denominator
73
+
(** [styled t pp_inner] wraps any formatter with sizing metadata.
81
-
(** {1 Metadata Creation} *)
77
+
Fmt.pr "Value: %a" (Textsize.styled (Textsize.with_scale 3 Textsize.empty) Fmt.int) 42
80
+
val styled : t -> 'a Fmt.t -> 'a Fmt.t
83
-
(** Empty metadata (all fields set to [None]). *)
84
-
val empty : metadata
82
+
(** Fmt formatter for double-sized text. *)
83
+
val pp_double : string Fmt.t
86
-
(** [with_scale s metadata] sets the scale. *)
87
-
val with_scale : scale -> metadata -> metadata
85
+
(** Fmt formatter for triple-sized text. *)
86
+
val pp_triple : string Fmt.t
89
-
(** [with_width w metadata] sets the width. *)
90
-
val with_width : width -> metadata -> metadata
88
+
(** Fmt formatter for quadruple-sized text. *)
89
+
val pp_quadruple : string Fmt.t
92
-
(** [with_fraction num den metadata] sets fractional scaling. *)
93
-
val with_fraction : numerator -> denominator -> metadata -> metadata
91
+
(** Fmt formatter for half-sized text. *)
92
+
val pp_half : string Fmt.t
95
-
(** [with_vertical_align v metadata] sets vertical alignment. *)
96
-
val with_vertical_align : vertical_align -> metadata -> metadata
94
+
(** Fmt formatter for superscript text. *)
95
+
val pp_superscript : string Fmt.t
98
-
(** [with_horizontal_align h metadata] sets horizontal alignment. *)
99
-
val with_horizontal_align : horizontal_align -> metadata -> metadata
97
+
(** Fmt formatter for subscript text. *)
98
+
val pp_subscript : string Fmt.t
101
-
(** {1 Escape Sequence Generation} *)
100
+
(** [pp_scaled n] creates a Fmt formatter for text at scale [n].
101
+
@raise Invalid_argument if [n] is not in range 1-7. *)
102
+
val pp_scaled : int -> string Fmt.t
103
-
(** [render metadata text] generates the complete escape sequence for sized text.
104
+
(** [styled_double pp_inner] wraps any formatter with double sizing. *)
105
+
val styled_double : 'a Fmt.t -> 'a Fmt.t
105
-
@param metadata The sizing metadata
106
-
@param text The text to render (max 4096 bytes of UTF-8)
107
-
@return The escape sequence string
108
-
@raise Invalid_argument if text exceeds 4096 bytes *)
109
-
val render : metadata -> string -> string
107
+
(** [styled_triple pp_inner] wraps any formatter with triple sizing. *)
108
+
val styled_triple : 'a Fmt.t -> 'a Fmt.t
111
-
(** [render_to_channel oc metadata text] writes the escape sequence to a channel.
110
+
(** [styled_superscript pp_inner] wraps any formatter with superscript styling. *)
111
+
val styled_superscript : 'a Fmt.t -> 'a Fmt.t
113
-
@param oc Output channel
114
-
@param metadata The sizing metadata
115
-
@param text The text to render (max 4096 bytes of UTF-8)
116
-
@raise Invalid_argument if text exceeds 4096 bytes *)
117
-
val render_to_channel : out_channel -> metadata -> string -> unit
113
+
(** [styled_subscript pp_inner] wraps any formatter with subscript styling. *)
114
+
val styled_subscript : 'a Fmt.t -> 'a Fmt.t
(** {1 Convenience Functions} *)