Skip to documentation
SLOP

tiny.pretty.TextWriter

Reference tiny.pretty TextWriter

Defined in tiny.pretty.

Adapts incremental text production to the Pretty renderer without allocating.

API (4)

Actions

Public operations.

Fields and members

Public fields and members.

No direct callersNo direct callstiny.prettyTextWriter
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Source: lib/pretty/core/src/stream.zig:7

zig
/// Adapts incremental text production to the Pretty renderer without allocating./// Flushes propagate to the wrapped writer so process-boundary ordering is preserved.pub const TextWriter = struct {    writer: std.Io.Writer,    output: *std.Io.Writer,    options: types.LayoutOptions,    pub fn init(        output: *std.Io.Writer,        buffer: []u8,        options: types.LayoutOptions,    ) TextWriter {        return .{            .writer = .{                .vtable = &.{                    .drain = drain,                    .flush = flush,                },                .buffer = buffer,            },            .output = output,            .options = options,        };    }    fn drain(        writer: *std.Io.Writer,        data: []const []const u8,        splat: usize,    ) std.Io.Writer.Error!usize {        const self: *TextWriter = @alignCast(@fieldParentPtr("writer", writer));        std.debug.assert(data.len > 0);        try self.write(writer.buffered());        writer.end = 0;        var consumed: usize = 0;        for (data[0 .. data.len - 1]) |bytes| {            try self.write(bytes);            consumed += bytes.len;        }        const pattern = data[data.len - 1];        for (0..splat) |_| {            try self.write(pattern);            consumed += pattern.len;        }        return consumed;    }    fn flush(writer: *std.Io.Writer) std.Io.Writer.Error!void {        const self: *TextWriter = @alignCast(@fieldParentPtr("writer", writer));        try self.write(writer.buffered());        writer.end = 0;        try self.output.flush();    }    fn write(self: *TextWriter, bytes: []const u8) std.Io.Writer.Error!void {        render.write(            self.output,            .{ .text = bytes },            self.options,        ) catch return error.WriteFailed;    }};

Source: lib/pretty/core/src/root.zig:117

zig
pub const TextWriter = @import("stream.zig").TextWriter;
Called byCallsNo direct callsdiagnosticwriteStderrTextdiagnosticwriteStdoutTexttest sourcelib.pretty.core.src.streamtest: text writer flush reaches its o...test sourcelib.pretty.core.src.streamtest: text writer preserves fragmente...test sourcelib.pretty.core.src.streamtest: text writer routes incremental ...TextWriterinit
Static calls · unresolved targets: 0 · external targets: 0.

Audit

Definitions2
Public names2
Members3
Version26.7.0
Revisiondaab053ee433