package matrix

Build not yet checked
  1. Overview
  2. Docs
Fast, modern terminal toolkit for OCaml

Install

dune-project
 Dependency

Authors

Maintainers

Sources

mosaic-0.3.0.tbz
sha256=a92cbbcbe016fb19fb0a749222da0e459a9567aef3f4c7340d9bd6b71c53ed6f
sha512=6a7ab054605538bb31a2b73a1a6d093981a2704c9f0af5852221c05735290d74aca7c7282298c4d0f91e86a800e2ccd94b4918af883cd963449c758eb6b272b3

doc/matrix.text/Matrix_text/Layout/Source/index.html

Module Layout.SourceSource

Texts indexed by grapheme cluster and logical line.

A source keeps its text's bytes as they are, and indexes every cluster, those of width 0 included. CR LF is one cluster of two bytes. A source indexes each logical line, and a source made by edit shares the index of every line the edit leaves whole with the source it was made from. A line that holds more than printable ASCII has its clusters indexed when something first asks about it, with their widths by the width method and tab width it was last laid out with. A source also keeps its layouts (Layout.create). Sources made from one another share what they cache, so they must not be used by two domains in parallel.

Sourcetype t

The type for sources.

Sourceval of_string : string -> t

of_string s is the source of s.

Sourceval text : t -> string

text t is the text of t.

Sourceval length : t -> int

length t is the number of clusters of t.

Sourceval byte_offset : t -> int -> int

byte_offset t g is the byte offset of boundary g.

Sourceval grapheme_of_byte : t -> affinity:affinity -> int -> int

grapheme_of_byte t ~affinity b is the boundary at byte offset b, clamped to the text. An offset inside a cluster gives the boundary before it if affinity is Upstream, and after it if Downstream.

Sourceval line_count : t -> int

line_count t is the number of logical lines of t, empty ones and an empty last line included. It is at least 1.

Sourceval line_start : t -> int -> int

line_start t line is the first boundary of line.

Sourceval line_end : t -> int -> int

line_end t line is the boundary before the line terminator of line, or the end of t for the last line.

Sourceval line_of_offset : t -> int -> int

line_of_offset t g is the logical line of boundary g.

Sourceval columns : ?width_method:width_method -> ?tab_width:int -> t -> first:int -> last:int -> int

columns t ~first ~last is the width of the clusters from boundary first to boundary last, negative if last is before first.

Sourceval slice : t -> first:int -> last:int -> string

slice t ~first ~last is a copy of the bytes from boundary first to boundary last, and "" if last is not after first.

Sourceval edit : t -> first:int -> last:int -> string -> t

edit t ~first ~last s is the source of t's text with the bytes from first to last replaced by s. It copies the text, indexes again the lines the replacement touches, and shares the index of the others with t, which is unchanged.

Raises Invalid_argument unless 0 <= first <= last <= String.length (text t).