package matrix

  1. Overview
  2. Docs

Module Ansi.WriterSource

Byte buffer writers.

Byte buffer writers for escape sequence emission.

A writer wraps a Stdlib.Bytes.t buffer and manages a write position. Writers are mutable and not thread-safe: use one writer per thread.

Writers

Sourcetype t

The type for byte buffer writers.

Sourceval make : bytes -> t

make buf is a writer targeting buf. The buffer must be large enough to contain all generated output; no bounds checking is performed.

Sourceval make_counting : unit -> t

make_counting () is a writer that tracks output length without writing any bytes. Useful for measuring escape sequence sizes before allocating a buffer.

Inspection

Sourceval len : t -> int

len w is the number of bytes written so far.

Sourceval pos : t -> int

pos w is the current write position. Same as len.

Sourceval reset_pos : t -> unit

reset_pos w resets the write position to zero. The underlying buffer is not cleared.

Sourceval slice : t -> bytes

slice w is a fresh copy of the bytes written so far.

Writing

Sourceval write_char : t -> char -> unit

write_char w c appends character c. In counting mode, increments the position without writing.

Sourceval write_string : t -> string -> unit

write_string w s appends string s.

Sourceval write_subbytes : t -> bytes -> int -> int -> unit

write_subbytes w buf off len appends len bytes from buf starting at offset off.