It's also important not to emit escape codes at all when TERM=dumb. (You'll get this behavior automatically if you implement color support by asking terminfo to the escape codes.)
const c = @cImport({
@cInclude("ncurses.h");
@cInclude("term.h");
});
pub fn main() !void {
// Initialize terminfo
_ = c.setupterm(null, 1, null);
// Get capability strings
const setaf = c.tigetstr("setaf"); // set foreground
const setab = c.tigetstr("setab"); // set background
const sgr0 = c.tigetstr("sgr0"); // reset
// Parameterize for red foreground
const red = c.tparm(setaf, c.COLOR_RED, 0, 0, 0, 0, 0, 0, 0, 0);
// Use it
_ = c.printf("%sThis is red%s\n", red, sgr0);
}