1
1
Fork
You've already forked Lesser-Format
0
A format utility for quick custom formatting in Zig.
  • Zig 100%
2026年07月09日 18:25:21 +09:30
src add strControlPicturesFormat fmter + tests 2026年07月09日 18:25:21 +09:30
.gitignore Inital Commit of base source 2025年11月13日 08:40:06 +10:30
build.zig Update license year in LICENSE + fixes missing license in build.zig 2026年07月09日 16:39:07 +09:30
build.zig.zon add strControlPicturesFormat fmter + tests 2026年07月09日 18:25:21 +09:30
FUNDING.yml Inital Commit of base source 2025年11月13日 08:40:06 +10:30
LICENSE Update license year in LICENSE + fixes missing license in build.zig 2026年07月09日 16:39:07 +09:30
README.org add strControlPicturesFormat fmter + tests 2026年07月09日 18:25:21 +09:30

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 .str but all control chars are replaced with the equivelent from the Unicode Control Pictures Block.
    • .fixed_c_str : C-like string that can be passed to std.mem.sliceTo(str, 0) prior to "{s}".
    • .flags : Prints out enabled fields in a flag struct (struct with just bool s). Skips non bool fields.
    • .unix_time : An int that is convertible into a std.posix.time_t, Print an 8601 like date-time. libc required.
  • time8601Format. Prints out a 8601 like time-date from a Linux epoch. [2025年11月12日T17:51:05]. libc required.
  • strControlPicturesFormat. Prints string translating control chars to the Control Pictures Block. "␉Hello World␊".
  • flagsFormat. Prints out enabled fields in a flag struct (struct with just bool s). Skips non bool fields.
  • HexDump. Prints out a formatted hex dump from the provided u8 slice.
  • formatWithHintAndFlags. Creates a fmt function, nearly identical to formatWithHint. 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.