A format utility for quick custom formatting in Zig.
- Zig 100%
| src |
add strControlPicturesFormat fmter + tests
|
|
| .gitignore | Inital Commit of base source | |
| build.zig | Update license year in LICENSE + fixes missing license in build.zig | |
| build.zig.zon |
add strControlPicturesFormat fmter + tests
|
|
| FUNDING.yml | Inital Commit of base source | |
| LICENSE | Update license year in LICENSE + fixes missing license in build.zig | |
| README.org |
add strControlPicturesFormat fmter + tests
|
|
Lesser-Format
https://ko-fi.com/img/githubbutton_sm.svg
A format utility for quick custom formatting in Zig. zig@0.16.0. (No-AI).
const Example = struct {
a: u8,
b: u16, // as hex
c: bool, // skipped
d: []u8, // str
pub const format = formatWithHint(@This(), .{ .b = "0x{X}", .d = .str, .c = .skip});
};
API
-
formatWithHint. Creates a fmt function, changing the behaviour of matching fields. Value args follow...<fn>: calls the fn like a format procedure for that field.<ptr>: assumption is a format string, concat and use..skip: skips and doesn't print the field..skip_noted: skips printing out the value but still notes the existence of the field. E.g..field_name = ⋯..str: Anything string like gets formatted with"{s}"..str_ctrlpic: Like.strbut all control chars are replaced with the equivelent from the Unicode Control Pictures Block..fixed_c_str: C-like string that can be passed tostd.mem.sliceTo(str, 0)prior to"{s}"..flags: Prints out enabled fields in a flag struct (struct with justbools). Skips non bool fields..unix_time: An int that is convertible into astd.posix.time_t, Print an 8601 like date-time.libcrequired.
time8601Format. Prints out a 8601 like time-date from a Linux epoch.[2025年11月12日T17:51:05].libcrequired.strControlPicturesFormat. Prints string translating control chars to the Control Pictures Block."␉Hello World␊".flagsFormat. Prints out enabled fields in a flag struct (struct with justbools). Skips non bool fields.HexDump. Prints out a formatted hex dump from the providedu8slice.formatWithHintAndFlags. Creates a fmt function, nearly identical toformatWithHint. Any unspecified bool fields be used in the trailing enabled flags indicator..{ .field_name= *, (A B D) }
Project Usage
Add to your build.zig.zon...
zig fetch --save git+https://codeberg.org/MinervasRefuge/Lesser-Format
Add to your build.zig...
const dependency_lesser_fmt = b.dependency("lesser_format", .{
.target = target,
.optimize = optimise,
.link_libc = true, // or `false` if time printing isn't needed
});
your_module.addImport("lesser_format", dependency_lesser_fmt.module("lesser_format"));
BSD-3-Clause : Copyright © 2025,2026 Abigale Raeck.