Skip to documentation
SLOP

tiny.smg.cli.output

Reference tiny.smg cli output

Defined in cli.

API (31)

Actions

Public operations.

Values and defaults

Public values and defaults.

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

Source

Called byCallsNo direct callstest; no linktools.smg.src.cli.outputtest: usage error width preserves bla...cli.outputwriteClickUsageErrorcli.outputclickUsageLineWidth
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callstest; no linktools.smg.src.cli.outputtest: display width counts utf8 codep...cli.outputwriteBoxLineDisplaycli.outputwritePaddedDisplayLinecli.outputwriteStyledBoxLineDisplaycli.outputwriteStyledUsageLinecli.outputdisplayWidth
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallscli.outputwriteClickBoxErrorcli.outputwriteClickUsageErrorcli.outputwriteRootUsageErrorcli.outputwriteDocHardlinecli.outputwriteDocTextcli.outputwriteRepeatedDoccli.outputwriteBoxBottom
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallscli.outputwriteClickBoxErrorcli.outputwriteClickUsageErrorcli.outputwriteRootUsageErrorcli.outputwriteDocHardlinecli.outputwriteDocTextcli.outputwriteSpacesDoccli.outputwriteBoxLine
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callerscli.outputdisplayWidthcli.outputwriteDocHardlinecli.outputwriteDocTextcli.outputwriteSpacesDoccli.outputwriteBoxLineDisplay
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallscli.outputwriteClickBoxErrorcli.outputwriteClickUsageErrorcli.outputwriteRootUsageErrorcli.outputwriteDocHardlinecli.outputwriteDocTextcli.outputwriteRepeatedDoccli.outputwriteBoxTop
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callerscli.outputwriteErrFmtcli.outputwriteByteLimitExceeded
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallscli.validationrejectForbiddenOptionValuescli.validationrejectMissingOptionValuescli.outputwriteBoxBottomcli.outputwriteBoxLinecli.outputwriteBoxTopcli.outputwriteErrcli.outputwritePaddedAsciiLinecli.outputwriteClickBoxError
Static calls · unresolved targets: 0 · external targets: 1.
Called byCallscli.outputwriteNoSuchOptioncli.validationvalidateQueryNameCommandcli.validationrejectUnexpectedOptionscli.validationrejectUnexpectedOptionsPlaincli.validationrejectUnexpectedScanOptions+13 morecli.outputclickUsageLineWidthcli.outputwriteBoxBottomcli.outputwriteBoxLinecli.outputwriteBoxTopcli.outputwriteErrcli.outputwritePaddedAsciiLinecli.outputwriteClickUsageError
Static calls · unresolved targets: 0 · external targets: 1.
Called byCallsNo direct callscli.outputwriteBoxBottomcli.outputwriteBoxLinecli.outputwriteBoxLineDisplaycli.outputwriteBoxTopcli.outputwritePaddedAsciiLine+8 morecli.outputwriteDocHardline
Static calls · unresolved targets: 1 · external targets: 0.
Called byCallsNo direct callscli.outputwriteBoxBottomcli.outputwriteBoxLinecli.outputwriteBoxLineDisplayprivate; no linktools.smg.src.cli.outputwriteBoxRowContentcli.outputwriteBoxTop+10 morecli.outputwriteDocText
Static calls · unresolved targets: 1 · external targets: 0.
Called byCallsNo direct callscli.outputwriteClickBoxErrorcli.outputwriteClickUsageErrorcli.outputwriteErrFmtcli.outputwriteRootUsageErrorcli.outputwriteStaleSourceHead+4 morecli.outputwriteErr
Static calls · unresolved targets: 1 · external targets: 1.
Called byCallscli.outputwriteByteLimitExceededcli.validationrejectInvalidMetacommand.checkrunprivate; no linktools.smg.src.command.rules.addaddKindprivate; no linktools.smg.src.command.rules.adddenyRule+4 morecli.outputwriteErrcli.outputwriteErrFmt
Static calls · unresolved targets: 0 · external targets: 1.
Called byCallsNo direct callerscli.outputwriteClickUsageErrorcli.outputwriteNoSuchOption
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callscli.jsonedgeArraycli.jsonstringArraycli.outputwriteOutFmtcommand.checkruncommand.concepts.renderwriteList+10 morecli.outputwriteOut
Static calls · unresolved targets: 1 · external targets: 1.
Called byCallscommand.searchindexcommand.usagesruncli.outputwriteOutcli.outputwriteOutFmt
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallscli.outputwriteClickBoxErrorcli.outputwriteClickUsageErrorcli.outputwriteRootUsageErrorcli.outputwriteDocHardlinecli.outputwriteDocTextcli.outputwriteSpacesDoccli.outputwritePaddedAsciiLine
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callerscli.outputdisplayWidthcli.outputwriteDocHardlinecli.outputwriteDocTextcli.outputwriteSpacesDoccli.outputwritePaddedDisplayLine
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallscli.outputwriteBoxBottomcli.outputwriteBoxTopprivate; no linktools.smg.src.cli.table.richwriteBordercli.outputwriteDocTextcli.outputwriteRepeatedDoc
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callerscli.outputwriteBoxBottomcli.outputwriteBoxLinecli.outputwriteBoxTopcli.outputwriteErrcli.outputwritePaddedAsciiLinecli.outputwriteRootUsageError
Static calls · unresolved targets: 0 · external targets: 1.
Called byCallscli.outputwriteBoxLinecli.outputwriteBoxLineDisplaycli.outputwritePaddedAsciiLinecli.outputwritePaddedDisplayLinecli.outputwriteStyledBoxLineDisplay+3 morecli.outputwriteDocTextcli.outputwriteSpacesDoc
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callerscli.outputwriteErrcli.outputwriteStaleSourceHead
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callersprivate; no linktools.smg.src.cli.outputboxRulecli.outputwriteDocHardlinecli.outputwriteStyledTextcli.outputwriteStyledBoxBottom
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callerscli.outputdisplayWidthprivate; no linktools.smg.src.cli.outputwriteBoxRowContentcli.outputwriteDocHardlinecli.outputwriteSpacesDoccli.outputwriteStyledTextcli.outputwriteStyledBoxLineDisplay
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callersprivate; no linktools.smg.src.cli.outputboxRulecli.outputwriteDocHardlinecli.outputwriteStyledTextcli.outputwriteStyledBoxTop
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callsprivate; no linktools.smg.src.cli.outputwriteBoxRowContentcli.outputwriteStyledBoxBottomcli.outputwriteStyledBoxLineDisplaycli.outputwriteStyledBoxTopcli.outputwriteStyledUsageLinecli.outputwriteStyledText
Static calls · unresolved targets: 1 · external targets: 0.
Called byCallsNo direct callerscli.outputdisplayWidthcli.outputwriteDocHardlinecli.outputwriteDocTextcli.outputwriteSpacesDoccli.outputwriteStyledTextcli.outputwriteStyledUsageLine
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallscommand.checkruncli.outputwriteErrcli.outputwriteWrappedError
Static calls · unresolved targets: 0 · external targets: 6.

Source: tools/smg/src/cli/output.zig

zig
const std = @import("std");const alloc = @import("alloc");const pretty = @import("pretty");const pretty_usage = @import("pretty_usage");pub const stale_source_head_message = "Error: .smg/ changed while this command was running. No update was applied; retry the command.\n";pub fn writeOut(data: []const u8) !u8 {    var stdout_buffer: [4096]u8 = undefined;    var stdout = std.Io.File.stdout().writer(std.Options.debug_io, &stdout_buffer);    try pretty.write(&stdout.interface, .{ .text = data }, .{ .width = 88 });    try stdout.interface.flush();    return 0;}pub fn writeOutFmt(allocator: std.mem.Allocator, comptime fmt: []const u8, args: anytype) !u8 {    return try writeOut(try std.fmt.allocPrint(allocator, fmt, args));}pub fn writeErr(data: []const u8) !void {    var stderr_buffer: [4096]u8 = undefined;    var stderr = std.Io.File.stderr().writer(std.Options.debug_io, &stderr_buffer);    try pretty.write(&stderr.interface, .{ .text = data }, .{ .width = 88 });    try stderr.interface.flush();}pub fn writeErrFmt(allocator: std.mem.Allocator, comptime fmt: []const u8, args: anytype) !void {    const text_value = try std.fmt.allocPrint(allocator, fmt, args);    defer allocator.free(text_value);    try writeErr(text_value);}pub fn writeStaleSourceHead() !void {    try writeErr(stale_source_head_message);}pub fn writeByteLimitExceeded(    allocator: std.mem.Allocator,    limit_name: []const u8,    value: usize,    option: []const u8,) !u8 {    try writeErrFmt(        allocator,        "Error: {s} is {d} bytes. Raise it with {s} SIZE.\n",        .{ limit_name, value, option },    );    return 2;}pub fn writeWrappedError(allocator: std.mem.Allocator, message: []const u8) !void {    const text_value = try std.fmt.allocPrint(allocator, "Error: {s}", .{message});    defer allocator.free(text_value);    var out: std.Io.Writer.Allocating = .init(allocator);    defer out.deinit();    var words = std.mem.tokenizeScalar(u8, text_value, ' ');    var width: usize = 0;    while (words.next()) |word| {        if (width == 0) {            try out.writer.writeAll(word);            width = word.len;        } else if (width + 1 + word.len > 80) {            if (width < 80) try out.writer.writeByte(' ');            try out.writer.writeByte('\n');            try out.writer.writeAll(word);            width = word.len;        } else {            try out.writer.writeByte(' ');            try out.writer.writeAll(word);            width += 1 + word.len;        }    }    try out.writer.writeByte('\n');    try writeErr(out.written());}pub fn writeProcessError(err: anyerror) void {    pretty_usage.Terminal.stderr(alloc.standaloneProcessAllocator(), .{}).writeErrorTextFmt("smg", "{s}", .{@errorName(err)}) catch {};}pub fn writeNoSuchOption(allocator: std.mem.Allocator, command: []const u8, signature: []const u8, option: []const u8) !void {    try writeClickUsageError(allocator, command, signature, try std.fmt.allocPrint(allocator, "No such option: {s}", .{option}));}pub fn writeClickUsageError(allocator: std.mem.Allocator, command: []const u8, signature: []const u8, message: []const u8) !void {    var out: std.Io.Writer.Allocating = .init(allocator);    const usage_width = clickUsageLineWidth(command);    try writePaddedAsciiLine(&out.writer, "", 80);    try writePaddedAsciiLine(&out.writer, try std.fmt.allocPrint(allocator, " Usage: smg {s} {s}", .{ command, signature }), usage_width);    try writePaddedAsciiLine(&out.writer, "", 80);    try writePaddedAsciiLine(&out.writer, try std.fmt.allocPrint(allocator, " Try 'smg {s} --help' for help", .{command}), usage_width);    try writeBoxTop(&out.writer, "Error", 80);    try writeBoxLine(&out.writer, message, 80);    try writeBoxBottom(&out.writer, 80);    try writePaddedAsciiLine(&out.writer, "", 80);    try writeErr(out.written());}pub fn clickUsageLineWidth(command: []const u8) usize {    return if (std.mem.eql(u8, command, "blame")) 70 else 80;}pub fn writeRootUsageError(allocator: std.mem.Allocator, command_name: []const u8, message: []const u8) !void {    var out: std.Io.Writer.Allocating = .init(allocator);    try writePaddedAsciiLine(&out.writer, "", 80);    try writePaddedAsciiLine(&out.writer, try std.fmt.allocPrint(allocator, " Usage: {s} [OPTIONS] COMMAND [ARGS]...", .{command_name}), 80);    try writePaddedAsciiLine(&out.writer, "", 80);    try writePaddedAsciiLine(&out.writer, try std.fmt.allocPrint(allocator, " Try '{s} --help' for help", .{command_name}), 80);    try writeBoxTop(&out.writer, "Error", 80);    try writeBoxLine(&out.writer, message, 80);    try writeBoxBottom(&out.writer, 80);    try writePaddedAsciiLine(&out.writer, "", 80);    try writeErr(out.written());}pub fn writeClickBoxError(allocator: std.mem.Allocator, message: []const u8) !void {    var out: std.Io.Writer.Allocating = .init(allocator);    try writeBoxTop(&out.writer, "Error", 80);    try writeBoxLine(&out.writer, message, 80);    try writeBoxBottom(&out.writer, 80);    try writePaddedAsciiLine(&out.writer, "", 80);    try writeErr(out.written());}pub fn writeDocText(writer: *std.Io.Writer, value: []const u8) !void {    try pretty.write(writer, .{ .text = value }, .{ .width = 88 });}pub fn helpColorMode() pretty.ColorMode {    return pretty_usage.terminalColorMode(std.Io.File.stdout());}pub fn writeStyledText(writer: *std.Io.Writer, style: pretty.Style, value: []const u8, mode: pretty.ColorMode) !void {    const text_doc = pretty.Doc{ .text = value };    const styled_doc = pretty.Doc{ .styled = .{ .style = style, .doc = &text_doc } };    try pretty.write(writer, styled_doc, .{ .width = 88, .color = mode });}const box_rule_glyph = "\xE2\x94\x80";const box_rule_capacity = 96;fn boxRule(buffer: *[box_rule_capacity * box_rule_glyph.len]u8, count: usize) []const u8 {    std.debug.assert(count <= box_rule_capacity);    for (0..count) |index| {        @memcpy(buffer[index * box_rule_glyph.len ..][0..box_rule_glyph.len], box_rule_glyph);    }    return buffer[0 .. count * box_rule_glyph.len];}pub fn writeStyledBoxTop(writer: *std.Io.Writer, title: []const u8, width: usize, mode: pretty.ColorMode) !void {    var rule_buffer: [box_rule_capacity * box_rule_glyph.len]u8 = undefined;    try writeStyledText(writer, .muted, "\xE2\x95\xAD\xE2\x94\x80 ", mode);    try writeStyledText(writer, .title, title, mode);    try writeStyledText(writer, .muted, " ", mode);    try writeStyledText(writer, .muted, boxRule(&rule_buffer, width - title.len - 5), mode);    try writeStyledText(writer, .muted, "\xE2\x95\xAE", mode);    try writeDocHardline(writer);}pub fn writeStyledBoxLineDisplay(writer: *std.Io.Writer, message: []const u8, width: usize, mode: pretty.ColorMode) !void {    try writeStyledText(writer, .muted, "\xE2\x94\x82 ", mode);    try writeBoxRowContent(writer, message, mode);    try writeSpacesDoc(writer, width -| displayWidth(message) -| 3);    try writeStyledText(writer, .muted, "\xE2\x94\x82", mode);    try writeDocHardline(writer);}fn writeBoxRowContent(writer: *std.Io.Writer, message: []const u8, mode: pretty.ColorMode) !void {    const name_len = boxRowNameLength(message);    if (name_len == 0) {        try writeDocText(writer, message);        return;    }    const style: pretty.Style = if (message[0] == '-') .type_name else .name;    try writeStyledText(writer, style, message[0..name_len], mode);    try writeDocText(writer, message[name_len..]);}fn boxRowNameLength(message: []const u8) usize {    if (message.len == 0 or message[0] == ' ') return 0;    var index: usize = 0;    while (index + 1 < message.len) : (index += 1) {        if (message[index] == ' ' and message[index + 1] == ' ') return index;    }    return 0;}pub fn writeStyledBoxBottom(writer: *std.Io.Writer, width: usize, mode: pretty.ColorMode) !void {    var rule_buffer: [box_rule_capacity * box_rule_glyph.len]u8 = undefined;    try writeStyledText(writer, .muted, "\xE2\x95\xB0", mode);    try writeStyledText(writer, .muted, boxRule(&rule_buffer, width - 2), mode);    try writeStyledText(writer, .muted, "\xE2\x95\xAF", mode);    try writeDocHardline(writer);}pub fn writeStyledUsageLine(writer: *std.Io.Writer, label: []const u8, rest: []const u8, width: usize, mode: pretty.ColorMode) !void {    try writeDocText(writer, " ");    try writeStyledText(writer, .keyword, label, mode);    try writeStyledText(writer, .source, rest, mode);    const used = 1 + displayWidth(label) + displayWidth(rest);    try writeSpacesDoc(writer, width -| used);    try writeDocHardline(writer);}pub fn writeDocHardline(writer: *std.Io.Writer) !void {    try pretty.write(writer, pretty.hardline, .{ .width = 88 });}pub fn writeSpacesDoc(writer: *std.Io.Writer, count: usize) !void {    var rest = count;    var spaces: [128]u8 = undefined;    @memset(&spaces, ' ');    while (rest != 0) {        const chunk = @min(rest, spaces.len);        try writeDocText(writer, spaces[0..chunk]);        rest -= chunk;    }}pub fn writeRepeatedDoc(writer: *std.Io.Writer, value: []const u8, count: usize) !void {    for (0..count) |_| try writeDocText(writer, value);}pub fn writePaddedAsciiLine(writer: *std.Io.Writer, value: []const u8, width: usize) !void {    try writeDocText(writer, value);    try writeSpacesDoc(writer, width -| value.len);    try writeDocHardline(writer);}pub fn writePaddedDisplayLine(writer: *std.Io.Writer, value: []const u8, width: usize) !void {    try writeDocText(writer, value);    try writeSpacesDoc(writer, width -| displayWidth(value));    try writeDocHardline(writer);}pub fn writeBoxTop(writer: *std.Io.Writer, title: []const u8, width: usize) !void {    try writeDocText(writer, "\xE2\x95\xAD\xE2\x94\x80 ");    try writeDocText(writer, title);    try writeDocText(writer, " ");    try writeRepeatedDoc(writer, "\xE2\x94\x80", width - title.len - 5);    try writeDocText(writer, "\xE2\x95\xAE");    try writeDocHardline(writer);}pub fn writeBoxLine(writer: *std.Io.Writer, message: []const u8, width: usize) !void {    try writeDocText(writer, "\xE2\x94\x82 ");    try writeDocText(writer, message);    try writeSpacesDoc(writer, width -| message.len -| 3);    try writeDocText(writer, "\xE2\x94\x82");    try writeDocHardline(writer);}pub fn writeBoxLineDisplay(writer: *std.Io.Writer, message: []const u8, width: usize) !void {    try writeDocText(writer, "\xE2\x94\x82 ");    try writeDocText(writer, message);    try writeSpacesDoc(writer, width -| displayWidth(message) -| 3);    try writeDocText(writer, "\xE2\x94\x82");    try writeDocHardline(writer);}pub fn writeBoxBottom(writer: *std.Io.Writer, width: usize) !void {    try writeDocText(writer, "\xE2\x95\xB0");    try writeRepeatedDoc(writer, "\xE2\x94\x80", width - 2);    try writeDocText(writer, "\xE2\x95\xAF");    try writeDocHardline(writer);}pub fn displayWidth(value: []const u8) usize {    var width: usize = 0;    var index: usize = 0;    while (index < value.len) {        const byte = value[index];        if (byte < 0x80) {            width += 1;            index += 1;            continue;        }        const sequence_len = std.unicode.utf8ByteSequenceLength(byte) catch 1;        width += 1;        index += @min(sequence_len, value.len - index);    }    return width;}test "display width counts utf8 codepoints" {    try std.testing.expectEqual(@as(usize, 5), displayWidth("abcde"));    try std.testing.expectEqual(@as(usize, 5), displayWidth("a\xE2\x80\x94bcd"));}test "usage error width preserves blame compatibility" {    try std.testing.expectEqual(@as(usize, 70), clickUsageLineWidth("blame"));    try std.testing.expectEqual(@as(usize, 80), clickUsageLineWidth("context"));}

Source: tools/smg/src/cli/root.zig:6

zig
pub const output = @import("output.zig");

Complete caller list for cli.output.writeClickUsageError

18 direct callers.

Complete caller list for cli.output.writeDocHardline

13 direct callers.

Complete caller list for cli.output.writeDocText

15 direct callers.

Complete caller list for cli.output.writeErr

9 direct callers.

Complete caller list for cli.output.writeErrFmt

9 direct callers.

Complete caller list for cli.output.writeOut

15 direct callers.

Complete caller list for cli.output.writeSpacesDoc

8 direct callers.

Audit

Definitions32
Public names32
Members0
Version26.7.0
Revisiondaab053ee433