|
| 1 | +#import "_lib/cram-snap.typ": theader |
| 2 | + |
| 3 | +#{ |
| 4 | + set table(inset: (x: 1.5mm, y: 1.7mm)) |
| 5 | + |
| 6 | + table( |
| 7 | + columns: (30mm, 1fr), |
| 8 | + |
| 9 | + theader[std.fmt format string], |
| 10 | + |
| 11 | + table.cell( |
| 12 | + colspan: 2, |
| 13 | + |
| 14 | + grid( |
| 15 | + columns: (1fr, 124mm), |
| 16 | + [ |
| 17 | + format string must be comptime-known and may contain placeholders in this format:\ |
| 18 | + `{[argument][specifier]:[fill][alignment][width].[precision]}`\ |
| 19 | + To print literal curly braces, escape them by writing them twice, e.g. `{{` or `}}`. |
| 20 | + ], |
| 21 | + text(size: 8pt)[ |
| 22 | + *Note*: most of the parameters are optional and may be omitted. |
| 23 | + Also you can leave out separators like `:` and `.` when all parameters after the separator are omitted. |
| 24 | + Only exception is the *fill* parameter. If a non-zero fill character is required at the same time as width is specified, one has to specify alignment as well, as otherwise the digit following `:` is interpreted as width, not fill. |
| 25 | + ], |
| 26 | + ), |
| 27 | + ), |
| 28 | + |
| 29 | + [`argument`], [ |
| 30 | + `[score]` - field name (an identifier) enclose in square brackets\ |
| 31 | + `2` - numeric index (omit means use next argument) |
| 32 | + ], |
| 33 | + |
| 34 | + [`specifier`], [ |
| 35 | + #box(inset: (top: 2mm))[ |
| 36 | + a type-dependent formatting option that determines how a type should formatted |
| 37 | + ] |
| 38 | + |
| 39 | + #show table.cell.where(x: 0): it => [ |
| 40 | + #align(center)[ |
| 41 | + #it.body |
| 42 | + ] |
| 43 | + ] |
| 44 | + |
| 45 | + #table( |
| 46 | + columns: (14mm, 1fr), |
| 47 | + [`x`, `X`], [output numeric value in hexadecimal notation], |
| 48 | + [`s`], |
| 49 | + [ |
| 50 | + for pointer-to-many and C pointers of u8, print as a C-string using zero-termination\ |
| 51 | + for slices of u8, print the entire slice as a string without zero-termination |
| 52 | + ], |
| 53 | + |
| 54 | + [`e`], [ output floating point value in scientific notation ], |
| 55 | + [`d`], [ output numeric value in decimal notation ], |
| 56 | + [`b`], [ output integer value in binary notation ], |
| 57 | + [`o`], [ output integer value in octal notation ], |
| 58 | + [`c`], [ output integer as an ASCII character. Integer type must have 8 bits at max. ], |
| 59 | + [`u`], [ output integer as an UTF-8 sequence. Integer type must have 21 bits at max. ], |
| 60 | + [`?`], |
| 61 | + [ |
| 62 | + output optional value as either the unwrapped value, or null;\ |
| 63 | + may be followed by a format specifier for the underlying value. |
| 64 | + ], |
| 65 | + |
| 66 | + [`!`], |
| 67 | + [ |
| 68 | + output error union value as either the unwrapped value, or the formatted error value;\ |
| 69 | + may be followed by a format specifier for the underlying value. |
| 70 | + ], |
| 71 | + |
| 72 | + [`*`], [ output the address of the value instead of the value itself. ], |
| 73 | + [`any`], [ output a value of any type using its default format. ], |
| 74 | + ) |
| 75 | + ], |
| 76 | + |
| 77 | + |
| 78 | + [`fill`], [ |
| 79 | + is a single unicode codepoint which is used to pad the formatted text |
| 80 | + ], |
| 81 | + |
| 82 | + [`alignment`], [ |
| 83 | + is one of the three bytes `<`, `^`, or `>` to make the text left-, center-, or right-aligned, respectively |
| 84 | + ], |
| 85 | + |
| 86 | + [`width`], [ |
| 87 | + is the total width of the field in unicode codepoints |
| 88 | + ], |
| 89 | + |
| 90 | + [`precision`], [ |
| 91 | + specifies how many decimals a formatted number should have |
| 92 | + ], |
| 93 | + |
| 94 | + table.cell( |
| 95 | + colspan: 2, |
| 96 | + stroke: (top: rgb("#333")), |
| 97 | + block( |
| 98 | + inset: (x: 0mm, y: 0mm, left: 6mm, top: 1mm), |
| 99 | + outset: 0mm, |
| 100 | + )[ |
| 101 | + value with `struct`, `vector`, `unioni` or `enum` type can have a custom formatting function defined as:\ |
| 102 | + |
| 103 | + ```zig |
| 104 | + pub fn format(value: ?, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void |
| 105 | + ``` |
| 106 | + |
| 107 | + with ? being the type formatted, this function will be called instead of the default implementation. |
| 108 | + ], |
| 109 | + ) |
| 110 | + ) |
| 111 | +} |
0 commit comments