zorael / kameloso

IRC bot with Twitch support
Boost Software License 1.0
9 stars 3 forks source link

colour tags #117

Closed zorael closed 2 years ago

zorael commented 2 years ago

This changes colouring from using the the quite frankly unreadable format specifier Tinting to using custom colour <tags>.

enum pattern = "IRC Parse Exception: %s%s%s (at %1$s%4$s%3$s:%1$s%5$d%3$s)";
logger.warningf(pattern, Tint.log, e.msg, Tint.warning, e.file, e.line);

...becomes...

enum pattern = "IRC Parse Exception: <l>%s<w> (at <l>%s<w>:<l>%d<w>)";
logger.warningf(pattern.expandTags, e.msg, e.file, e.line);

Where the lowercase letter in the <tag> correlates to a std.experimental.LogLevel, the same way we've been using them with kameloso.common.Tint so far. <i> is LogLevel.info, <w> is LogLevel.warning, </> is LogLevel.off, etc.

The immediate advantage of this is that things become considerably more legible. Mistakes are easier to spot. The immediate disadvantage is that all our coloured output is now untested overnight and may have things like format specifier/parameter mismatches. It's hard to test.

Compile-time memory use went down slightly at least, so there's at least that.