output.zig

22.1 KB · raw

1// output.zig — the only file that writes to stdout2// All ANSI codes live here. No raw escape sequences elsewhere.3const std = @import("std");4const types = @import("types.zig");5const nina_version = @import("version.zig");6const Io = std.Io;78// Color constants — all ANSI codes live here only9const PINK = "\x1b[38;2;255;183;197m";10const BOLD = "\x1b[1m";11const GREEN = "\x1b[32m";12const YELLOW = "\x1b[33m";13const RED = "\x1b[31m";14const CYAN = "\x1b[36m";15const DIM = "\x1b[2m";16const RESET = "\x1b[0m";1718// Exported for TUI use (search.zig references these to avoid \x1b in that file)19pub const C_PINK = PINK;20pub const C_BOLD = BOLD;21pub const C_GREEN = GREEN;22pub const C_YELLOW = YELLOW;23pub const C_RED = RED;24pub const C_CYAN = CYAN;25pub const C_DIM = DIM;26pub const C_RESET = RESET;27pub const C_CLEAR_EOL = "\x1b[K";28pub const C_CURSOR_UP_FMT = "\x1b[{d}A";2930// Precomputed prefix strings31const HDR_C = PINK ++ ":: " ++ RESET;32const HDR_P = ":: ";33const STEP_C = "   " ++ DIM ++ "-> " ++ RESET;34const STEP_P = "   -> ";35const TEACH_C = "   " ++ DIM ++ "= " ++ RESET;36const TEACH_P = "   = ";37const ERR_C = PINK ++ ":: " ++ RED ++ "error:" ++ RESET ++ " ";38const ERR_P = ":: error: ";39const WARN_C = PINK ++ ":: " ++ YELLOW ++ "warning:" ++ RESET ++ " ";40const WARN_P = ":: warning: ";4142var _fw: Io.File.Writer = undefined;43var _w: *Io.Writer = undefined;44var color_enabled: bool = true;45var teach_enabled: bool = false;4647pub fn init(writer: *Io.Writer, environ: *const std.process.Environ.Map, color_config: bool) void {48    _w = writer;49    color_enabled = color_config and50        isStdoutTty() and51        !environ.contains("NO_COLOR");52}5354// libc-free tty check: tcgetattr fails with NotATerminal on a non-tty.55// Avoiding std.c.isatty keeps the binary cross-compilable without libc.56fn isStdoutTty() bool {57    _ = std.posix.tcgetattr(std.posix.STDOUT_FILENO) catch return false;58    return true;59}6061pub fn setTeach(enabled: bool) void {62    teach_enabled = enabled;63}6465pub fn flush() void {66    _w.flush() catch {};67}6869fn c(code: []const u8) []const u8 {70    return if (color_enabled) code else "";71}7273fn hdr() []const u8 {74    return if (color_enabled) HDR_C else HDR_P;75}7677fn step() []const u8 {78    return if (color_enabled) STEP_C else STEP_P;79}8081fn teach_pfx() []const u8 {82    return if (color_enabled) TEACH_C else TEACH_P;83}8485// Raw write — used by TUI86pub fn raw(bytes: []const u8) void {87    _w.writeAll(bytes) catch {};88}8990// Formatted print — used by TUI for in-place rendering91pub fn p(comptime fmt: []const u8, args: anytype) void {92    _w.print(fmt, args) catch {};93}9495pub fn cursorUp(n: usize) void {96    if (n > 0) p("\x1b[{d}A", .{n});97}9899pub fn clearLine() void {100    p("\r\x1b[K", .{});101}102103// --- Error and warning output ---104105pub fn printError(message: []const u8, detail: ?[]const u8, suggestion: ?[]const u8) void {106    p("{s}{s}\n", .{ if (color_enabled) ERR_C else ERR_P, message });107    if (detail) |d| p("   {s}{s}{s}\n", .{ c(DIM), d, c(RESET) });108    if (suggestion) |s| p("   {s}-> {s}{s}\n", .{ c(DIM), s, c(RESET) });109}110111pub fn printWarning(message: []const u8) void {112    p("{s}{s}\n", .{ if (color_enabled) WARN_C else WARN_P, message });113}114115pub fn printTeach(cmd: []const u8) void {116    if (teach_enabled) p("{s}{s}{s}\n", .{ teach_pfx(), cmd, c(RESET) });117}118119pub fn printSubstep(comptime fmt: []const u8, args: anytype) void {120    p("{s}", .{step()});121    p(fmt, args);122    p("\n", .{});123}124125// --- Confirmation prompt (returns true = yes) ---126127pub fn confirm(prompt: []const u8) bool {128    p("   {s}continue? [Y/n]  ", .{prompt});129    flush();130    var buf: [64]u8 = undefined;131    var i: usize = 0;132    while (i < buf.len) {133        const n = std.posix.read(std.posix.STDIN_FILENO, buf[i .. i + 1]) catch break;134        if (n == 0) break;135        if (buf[i] == '\n') break;136        i += 1;137    }138    const input = std.mem.trim(u8, buf[0..i], " \t");139    if (input.len == 0) return true;140    return input[0] != 'n' and input[0] != 'N';141}142143// --- Apply / rebuild ---144145pub fn applyStart(machine: []const u8) void {146    p("{s}rebuilding {s}...\n", .{ hdr(), machine });147}148149pub fn applyDone(gen: u32, elapsed_ms: u64) void {150    const secs = @as(f64, @floatFromInt(elapsed_ms)) / 1000.0;151    if (elapsed_ms >= 1000) {152        p("{s}generation {s}{d}{s}  {s}[{d:.1}s]{s}\n", .{ hdr(), c(BOLD), gen, c(RESET), c(DIM), secs, c(RESET) });153    } else {154        p("{s}generation {s}{d}{s}\n", .{ hdr(), c(BOLD), gen, c(RESET) });155    }156}157158pub fn applyFailed(translated: []const u8) void {159    p("{s}build failed\n", .{if (color_enabled) ERR_C else ERR_P});160    if (translated.len > 0) p("   {s}{s}{s}\n", .{ c(DIM), translated, c(RESET) });161    p("   {s}-> nina doctor{s}\n", .{ c(DIM), c(RESET) });162}163164pub fn applyDry(machine: []const u8) void {165    p("{s}dry run  {s}\n", .{ hdr(), machine });166}167168pub fn applyDryDone() void {169    p("{s}no changes applied\n", .{hdr()});170}171172// --- Check ---173174pub fn checkStart(machine: []const u8) void {175    p("{s}checking {s}...\n", .{ hdr(), machine });176}177178pub fn checkOk() void {179    p("{s}{s}ok{s}\n", .{ hdr(), c(GREEN), c(RESET) });180}181182pub fn checkFailed(msg: []const u8) void {183    p("{s}config invalid\n", .{if (color_enabled) ERR_C else ERR_P});184    if (msg.len > 0) p("   {s}{s}{s}\n", .{ c(DIM), msg, c(RESET) });185}186187// --- Back / go ---188189pub fn backStart(machine: []const u8, from: u32, to: u32) void {190    p("{s}rolling back  {s}  gen {d} -> gen {d}\n", .{ hdr(), machine, from, to });191}192193pub fn goStart(machine: []const u8, current: u32, target: u32) void {194    p("{s}switching  {s}  gen {d} -> gen {d}\n", .{ hdr(), machine, current, target });195}196197pub fn generationDone(n: u32) void {198    p("{s}done  gen {s}{d}{s}\n", .{ hdr(), c(BOLD), n, c(RESET) });199}200201// --- History ---202203pub fn historyHeader(machine: []const u8) void {204    p("{s}generations  {s}\n\n", .{ hdr(), machine });205}206207pub fn historyRow(gen: types.GenerationInfo) void {208    if (gen.current) {209        p("   {s}{d}{s}   {s}   {s}   {s}current{s}\n", .{ c(BOLD), gen.number, c(RESET), gen.date, gen.time, c(BOLD), c(RESET) });210    } else {211        p("   {s}{d}   {s}   {s}{s}\n", .{ c(DIM), gen.number, gen.date, gen.time, c(RESET) });212    }213}214215// --- Clean ---216217pub fn cleanStart(machine: []const u8, keep: u32, total: u32) void {218    p("{s}cleaning  {s}  keeping {d} of {d}\n", .{ hdr(), machine, keep, total });219}220221pub fn cleanDone(freed: []const u8) void {222    p("{s}freed {s}\n", .{ hdr(), freed });223}224225// --- Status ---226227pub fn statusHeader() void {228    p("{s}status\n\n", .{hdr()});229}230231pub fn statusRow(machine: []const u8, gen: u32, time: []const u8, size: []const u8, ok: bool) void {232    if (ok) {233        p("   {s}{s}   gen {d}   {s}   {s}{s}\n", .{ c(DIM), machine, gen, time, size, c(RESET) });234    } else {235        p("   {s}{s}   {s}unreachable{s}\n", .{ c(RED), machine, "", c(RESET) });236    }237}238239// --- Diff ---240241pub fn diffHeader(a: u32, b: u32, machine: []const u8) void {242    p("{s}gen {d} -> gen {d}  {s}\n\n", .{ hdr(), a, b, machine });243}244245pub fn diffRow(entry: types.DiffEntry) void {246    switch (entry.op) {247        .add => p("   {s}+{s} {s}   {s}\n", .{ c(GREEN), c(RESET), entry.package, entry.new_version orelse "" }),248        .remove => p("   {s}-{s} {s}   {s}\n", .{ c(RED), c(RESET), entry.package, entry.old_version orelse "" }),249        .change => p("   {s}^{s} {s}   {s} -> {s}\n", .{ c(CYAN), c(RESET), entry.package, entry.old_version orelse "", entry.new_version orelse "" }),250    }251}252253// --- Doctor ---254255pub fn doctorHeader(machine: []const u8) void {256    p("{s}diagnosing  {s}\n\n", .{ hdr(), machine });257}258259pub fn doctorRow(check: types.DoctorCheck) void {260    const status_str = switch (check.status) {261        .ok => if (color_enabled) GREEN ++ "ok" ++ RESET else "ok",262        .warn => if (color_enabled) YELLOW ++ "warn" ++ RESET else "warn",263        .fail => if (color_enabled) RED ++ "fail" ++ RESET else "fail",264    };265    const note_str = check.note orelse "";266    p("   {s:<16}  {s}   {s}\n", .{ check.name, status_str, note_str });267}268269pub fn doctorSummary(warnings: u32, failures: u32) void {270    if (failures > 0) {271        p("{s}{d} problems\n", .{ hdr(), failures });272    } else if (warnings > 0) {273        p("{s}{d} warnings\n", .{ hdr(), warnings });274    } else {275        p("{s}{s}all good{s}\n", .{ hdr(), c(GREEN), c(RESET) });276    }277}278279// --- Update ---280281pub fn updateStart(machine: []const u8) void {282    p("{s}updating channels  {s}\n\n", .{ hdr(), machine });283}284285pub fn updateChannel(name: []const u8, old: ?[]const u8, new: ?[]const u8) void {286    if (old != null and new != null and !std.mem.eql(u8, old.?, new.?)) {287        p("   {s}   {s} -> {s}\n", .{ name, old.?, new.? });288    } else {289        p("   {s}   {s}no change{s}\n", .{ name, c(DIM), c(RESET) });290    }291}292293pub fn updateDone() void {294    p("\n{s}done\n", .{hdr()});295}296297// --- Upgrade ---298299pub fn upgradeStart(machine: []const u8) void {300    p("{s}upgrading  {s}\n", .{ hdr(), machine });301}302303// --- Log ---304305pub fn logHeader(machine: []const u8) void {306    p("{s}history  {s}\n\n", .{ hdr(), machine });307}308309pub fn logRow(date: []const u8, time: []const u8, action: []const u8, detail: []const u8) void {310    p("   {s}  {s}   {s:<12}  {s}\n", .{ date, time, action, detail });311}312313// --- Edit ---314315pub fn editOpen(path: []const u8, editor: []const u8) void {316    p("{s}opening {s}\n", .{ hdr(), path });317    printSubstep("{s}", .{editor});318    p("\n   {s}run nina check to validate before applying{s}\n", .{ c(DIM), c(RESET) });319}320321// --- Fmt ---322323pub fn fmtStart(path: []const u8) void {324    p("{s}formatting  {s}\n", .{ hdr(), path });325}326327pub fn fmtDone() void {328    p("{s}done\n", .{hdr()});329}330331pub fn fmtNeedsFormat() void {332    p("{s}needs formatting  {s}run nina fmt to fix{s}\n", .{ hdr(), c(DIM), c(RESET) });333}334335// --- Repl ---336337pub fn replStart() void {338    p("{s}nix repl  {s}nixpkgs loaded{s}  :q to exit\n", .{ hdr(), c(DIM), c(RESET) });339}340341// --- Develop ---342343pub fn developStart(pkgs: []const []const u8) void {344    p("{s}entering dev shell\n\n   ", .{hdr()});345    for (pkgs, 0..) |pkg, i| {346        if (i > 0) p("  ", .{});347        p("{s}", .{pkg});348    }349    p("\n\n   {s}exit to return{s}\n\n", .{ c(DIM), c(RESET) });350}351352pub fn developDone() void {353    p("{s}back\n", .{hdr()});354}355356// --- Info ---357358pub fn infoHeader(machine: []const u8) void {359    p("{s}{s}\n\n", .{ hdr(), machine });360}361362pub fn infoRow(key: []const u8, val: []const u8) void {363    p("   {s:<12}  {s}\n", .{ key, val });364}365366// --- Boot ---367368pub fn bootHeader(machine: []const u8) void {369    p("{s}boot entries  {s}\n\n", .{ hdr(), machine });370}371372pub fn bootEntry(entry: types.BootEntry, idx: usize) void {373    if (entry.current) {374        p("   {s}> {s}{s}{s}\n", .{ c(BOLD), entry.title, if (entry.date) |d| std.fmt.allocPrint(std.heap.page_allocator, "   {s}", .{d}) catch "   " else "", c(RESET) });375    } else {376        p("   {s}  {s}{s}{s}\n", .{ c(DIM), entry.title, if (entry.date) |d| std.fmt.allocPrint(std.heap.page_allocator, "   {s}", .{d}) catch "   " else "", c(RESET) });377    }378    _ = idx;379}380381// --- Service ---382383pub fn serviceListHeader(machine: []const u8) void {384    p("{s}services  {s}\n\n", .{ hdr(), machine });385}386387pub fn serviceRow(svc: types.ServiceInfo) void {388    const state_str = switch (svc.state) {389        .active => if (color_enabled) GREEN ++ "active" ++ RESET else "active",390        .failed => if (color_enabled) RED ++ "failed" ++ RESET else "failed",391        .inactive => "inactive",392        .unknown => "unknown",393    };394    const uptime = svc.uptime orelse "";395    p("   {s:<24}  {s:<14}  {s}\n", .{ svc.name, state_str, uptime });396}397398pub fn serviceVerb(verb: []const u8, name: []const u8, machine: []const u8) void {399    p("{s}{s} {s}  {s}\n", .{ hdr(), verb, name, machine });400}401402pub fn serviceDone() void {403    p("{s}done\n", .{hdr()});404}405406pub fn serviceLogsHeader(name: []const u8, n: u32, machine: []const u8) void {407    p("{s}{s}  last {d} lines  {s}\n\n", .{ hdr(), name, n, machine });408}409410// --- Store ---411412pub fn storeInfo(info: types.StoreInfo) void {413    p("{s}store\n\n", .{hdr()});414    p("   {s:<16}  {s}\n", .{ "total", info.total_size });415    p("   {s:<16}  {d} paths\n", .{ "live", info.live_paths });416    p("   {s:<16}  {s}{d} paths{s}   run nina clean\n", .{ "reclaimable", c(DIM), info.reclaimable_paths, c(RESET) });417}418419// --- Channel ---420421pub fn channelListHeader(machine: []const u8) void {422    p("{s}channels  {s}\n\n", .{ hdr(), machine });423}424425pub fn channelRow(ch: types.ChannelInfo) void {426    p("   {s:<16}  {s}\n", .{ ch.name, ch.url });427}428429// --- Flake ---430431pub fn flakeUpdateStart() void {432    p("{s}updating inputs\n\n", .{hdr()});433}434435pub fn flakeInput(input: types.FlakeInput) void {436    if (input.changed) {437        const old = if (input.old_rev) |r| r[0..@min(7, r.len)] else "?";438        const new = if (input.new_rev) |r| r[0..@min(7, r.len)] else "?";439        p("   {s:<20}  {s} -> {s}\n", .{ input.name, old, new });440    } else {441        p("   {s:<20}  {s}no change{s}\n", .{ input.name, c(DIM), c(RESET) });442    }443}444445pub fn flakeLockWritten() void {446    p("\n{s}flake.lock written\n", .{hdr()});447}448449pub fn flakeValid() void {450    p("{s}{s}valid{s}\n", .{ hdr(), c(GREEN), c(RESET) });451}452453pub fn flakeCheckStart() void {454    p("{s}checking flake\n", .{hdr()});455}456457// --- Profile ---458459pub fn profileListHeader() void {460    p("{s}profile packages\n\n", .{hdr()});461}462463pub fn profileRow(attr: []const u8, pkg_version: []const u8, description: []const u8) void {464    p("   {s:<24}  {s:<12}  {s}\n", .{ attr, pkg_version, description });465}466467// --- Install / Remove / Try ---468469pub fn installStart(pkg: []const u8, path: types.InstallPath) void {470    const path_str = switch (path) {471        .profile => "profile",472        .system => "system",473    };474    p("{s}installing {s}{s}{s}  {s}\n", .{ hdr(), c(PINK), pkg, c(RESET), path_str });475}476477pub fn installDone(pkg: []const u8) void {478    p("{s}{s}{s}{s} installed  {s}available now{s}\n", .{ hdr(), c(PINK), pkg, c(RESET), c(DIM), c(RESET) });479}480481pub fn installEditorPrompt(pkg: []const u8, config_path: []const u8, line: u32, editor: []const u8) void {482    p("{s}opening {s}  add {s}{s}{s} to systemPackages\n", .{ hdr(), config_path, c(PINK), pkg, c(RESET) });483    const cmd = std.fmt.allocPrint(std.heap.page_allocator, "{s} {s} +{d}", .{ editor, config_path, line }) catch editor;484    printSubstep("{s}", .{cmd});485    p("\n   {s}save and close when done{s}\n\n", .{ c(DIM), c(RESET) });486}487488pub fn installSelectPrompt(pkg: []const u8, pkg_version: []const u8) void {489    p("{s}{s}{s}{s}  {s}\n\n", .{ hdr(), c(PINK), pkg, c(RESET), pkg_version });490    p("   [i] profile install    {s}instant  no rebuild{s}\n", .{ c(DIM), c(RESET) });491    p("   [s] system install     {s}opens editor  requires apply{s}\n", .{ c(DIM), c(RESET) });492    p("   [t] try now            {s}exits when done{s}\n\n", .{ c(DIM), c(RESET) });493    p("   > ", .{});494    flush();495}496497pub fn tryStart(pkg: []const u8) void {498    p("{s}trying {s}{s}{s}  exit when done\n", .{ hdr(), c(PINK), pkg, c(RESET) });499}500501pub fn tryDone() void {502    p("{s}back\n", .{hdr()});503}504505// --- List ---506507pub fn listHeader() void {508    p("{s}installed packages\n\n", .{hdr()});509}510511pub fn listSection(title: []const u8) void {512    p("   {s}{s}{s}\n", .{ c(DIM), title, c(RESET) });513}514515pub fn listPkg(name: []const u8, pkg_version: []const u8) void {516    p("   {s}{s}{s}   {s}{s}{s}\n", .{ c(PINK), name, c(RESET), c(DIM), pkg_version, c(RESET) });517}518519// --- Hello ---520521pub fn hello(machines: []const types.Machine) void {522    p("{s}nina\n\n", .{hdr()});523    for (machines) |m| {524        const kind = if (m.local) "local" else "ssh";525        const detail = if (m.local) "default" else m.host orelse "";526        p("   {s}{s}{s}   {s}   {s}\n", .{ c(DIM), m.name, c(RESET), kind, detail });527    }528    p("\n", .{});529}530531// --- Help ---532533pub fn help() void {534    p("{s}nina  {s}nixos helper{s}\n\n", .{ hdr(), c(DIM), c(RESET) });535    const cmds = [_][2][]const u8{536        .{ "apply", "rebuild and switch" },537        .{ "back", "roll back one generation" },538        .{ "go <n>", "switch to generation n" },539        .{ "history", "list all generations" },540        .{ "clean", "remove old generations" },541        .{ "search <q>", "find packages" },542        .{ "install <pkg>", "add to profile or system" },543        .{ "remove <pkg>", "remove from profile or system" },544        .{ "try <pkg>", "test without installing" },545        .{ "list", "show installed packages" },546        .{ "edit", "open configuration.nix" },547        .{ "check", "validate config" },548        .{ "diff", "changes between generations" },549        .{ "status", "machine health" },550        .{ "update", "refresh channels" },551        .{ "upgrade", "update and rebuild" },552        .{ "log", "operation history" },553        .{ "doctor", "diagnose issues" },554        .{ "develop", "enter dev shell" },555        .{ "flake", "flake management" },556        .{ "build", "build a package" },557        .{ "run", "run without installing" },558        .{ "service", "manage services" },559        .{ "store", "nix store tools" },560        .{ "channel", "manage channels" },561        .{ "profile", "user profile packages" },562        .{ "info", "system information" },563        .{ "boot", "boot entries" },564        .{ "fmt", "format configuration.nix" },565        .{ "repl", "nix repl with nixpkgs" },566        .{ "option <q>", "search nixos options" },567        .{ "pkg", "inspect packages" },568        .{ "pin", "pin flake inputs" },569        .{ "hash", "compute nix hash" },570        .{ "fetch", "fetch and hash a url" },571        .{ "hello", "list machines" },572        .{ "help", "this message" },573    };574    for (cmds) |cmd| {575        p("   {s:<18}  {s}{s}{s}\n", .{ cmd[0], c(DIM), cmd[1], c(RESET) });576    }577    p("\n   {s}flags: --on <machine>  --dry  --check  --no-apply  --last <n>  --all  --json{s}\n", .{ c(DIM), c(RESET) });578}579580pub fn version() void {581    p("{s}nina  v{s}  zig 0.16  zero dependencies\n", .{ hdr(), nina_version.VERSION });582}583584// --- Search (text output before TUI) ---585586pub fn searchResult(pkg: types.NixPackage) void {587    p("   {s}{s}{s}   {s}{s}{s}   {s}\n", .{ c(PINK), pkg.pname, c(RESET), c(DIM), pkg.version, c(RESET), pkg.description });588}589590pub fn searchHeader(query: []const u8, count: usize) void {591    p("{s}search nixpkgs {s}  {s}{d} results{s}\n\n", .{ hdr(), query, c(DIM), count, c(RESET) });592}593594// --- Gen commands ---595596pub fn genCurrent(n: u32) void {597    p("{d}\n", .{n});598}599600pub fn done() void {601    p("{s}done\n", .{hdr()});602}603604pub fn runStart(pkg: []const u8) void {605    p("{s}running {s}{s}{s}\n", .{ hdr(), c(PINK), pkg, c(RESET) });606}607608pub fn buildStart(attr: []const u8) void {609    p("{s}building {s}\n", .{ hdr(), attr });610}611612pub fn buildDone() void {613    p("{s}done\n", .{hdr()});614}615616// --- Self-update (nina update) ---617618pub fn updateSelfStart() void {619    p("{s}checking for updates\n", .{hdr()});620}621622pub fn updateSelfCurrent(ver: []const u8) void {623    p("{s}{s}nina {s} is up to date{s}\n", .{ hdr(), c(GREEN), ver, c(RESET) });624}625626pub fn updateSelfAvailable(current: []const u8, latest: []const u8) void {627    p("{s}current  {s}\n", .{ step(), current });628    p("{s}latest   {s}{s}{s}\n", .{ step(), c(BOLD), latest, c(RESET) });629}630631pub fn updateSelfDownloading(ver: []const u8, platform: []const u8) void {632    p("{s}downloading nina {s} for {s}\n", .{ step(), ver, platform });633}634635pub fn updateSelfVerifying() void {636    p("{s}verifying checksum\n", .{step()});637}638639pub fn updateSelfInstalling(install_path: []const u8) void {640    p("{s}installing to {s}\n", .{ step(), install_path });641}642643pub fn updateSelfDone(old_ver: []const u8, new_ver: []const u8) void {644    p("{s}updated  {s} {s}→{s} {s}\n", .{ hdr(), old_ver, c(DIM), c(RESET), new_ver });645}646647pub fn updateSelfNoPlatform(platform: []const u8) void {648    p("{s}no pre-built binary for {s}\n", .{ hdr(), platform });649    p("{s}check kepr.uk/nina/releases for available platforms\n", .{step()});650}651652pub fn updateSelfNetworkError() void {653    p("{s}{s}\n", .{ if (color_enabled) WARN_C else WARN_P, "could not reach kepr.uk — check your connection" });654}655656pub fn updateSelfChecksumFailed() void {657    p("{s}checksum mismatch — download may be corrupt\n", .{if (color_enabled) ERR_C else ERR_P});658    p("{s}try again or download manually from kepr.uk/nina/releases\n", .{step()});659}660661// --- Setup ---662663pub fn setupCheck() void {664    p("{s}checking nix features\n", .{hdr()});665}666667pub fn setupFeatures(nix_command: bool, flakes: bool) void {668    p("{s}nix-command  {s}{s}{s}\n", .{669        step(),670        if (nix_command) c(GREEN) else "",671        if (nix_command) "enabled" else "not enabled",672        if (nix_command) c(RESET) else "",673    });674    p("{s}flakes       {s}{s}{s}\n", .{675        step(),676        if (flakes) c(GREEN) else "",677        if (flakes) "enabled" else "not enabled",678        if (flakes) c(RESET) else "",679    });680}681682pub fn setupAllSet() void {683    p("{s}all set\n", .{hdr()});684}685686pub fn setupEnabling() void {687    p("{s}enabling experimental features\n", .{hdr()});688}689690pub fn setupDone(path: []const u8, is_nixos: bool) void {691    p("{s}wrote {s}\n", .{ step(), path });692    p("{s}done  open a new shell to pick up the change\n", .{hdr()});693    if (is_nixos) {694        printSubstep("to persist across nixos-rebuild, add to configuration.nix:", .{});695        printSubstep("  nix.settings.experimental-features = [ \"nix-command\" \"flakes\" ];", .{});696    }697}698699pub fn pinDone(input: []const u8, commit: []const u8) void {700    p("{s}pinned {s} -> {s}\n", .{ hdr(), input, commit });701}702703pub fn unpinDone(input: []const u8) void {704    p("{s}unpinned {s}\n", .{ hdr(), input });705}706707pub fn hashResult(hash: []const u8) void {708    p("{s}\n", .{hash});709}710711pub fn fetchResult(hash: []const u8, url: []const u8) void {712    _ = url;713    p("{s}\n", .{hash});714}715716pub fn storeRepairStart() void {717    p("{s}repairing store\n", .{hdr()});718}719720pub fn storeVerifyStart() void {721    p("{s}verifying store\n", .{hdr()});722}723724pub fn storeGcDone(freed: []const u8) void {725    p("{s}freed {s}\n", .{ hdr(), freed });726}727728pub fn storePath(path: []const u8) void {729    p("{s}\n", .{path});730}731732pub fn pkgResult(key: []const u8, val: []const u8) void {733    p("   {s:<16}  {s}\n", .{ key, val });734}735736pub fn channelDone() void {737    p("{s}done\n", .{hdr()});738}739740pub fn flakeShowHeader(name: []const u8) void {741    p("{s}{s}\n\n", .{ hdr(), name });742}743744pub fn flakeShowEntry(kind: []const u8, name: []const u8, desc: []const u8) void {745    p("   {s:<12}  {s:<24}  {s}\n", .{ kind, name, desc });746}