output.zig

25.4 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, io: std.Io, environ: *const std.process.Environ.Map, color_config: bool) void {48    _w = writer;49    color_enabled = color_config and50        (std.Io.File.stdout().isTty(io) catch false) and51        !environ.contains("NO_COLOR");52}5354pub fn setTeach(enabled: bool) void {55    teach_enabled = enabled;56}5758pub fn flush() void {59    _w.flush() catch {};60}6162fn c(code: []const u8) []const u8 {63    return if (color_enabled) code else "";64}6566fn hdr() []const u8 {67    return if (color_enabled) HDR_C else HDR_P;68}6970fn step() []const u8 {71    return if (color_enabled) STEP_C else STEP_P;72}7374fn teach_pfx() []const u8 {75    return if (color_enabled) TEACH_C else TEACH_P;76}7778// Raw write — used by TUI79pub fn raw(bytes: []const u8) void {80    _w.writeAll(bytes) catch {};81}8283// Formatted print — used by TUI for in-place rendering84pub fn p(comptime fmt: []const u8, args: anytype) void {85    _w.print(fmt, args) catch {};86}8788pub fn cursorUp(n: usize) void {89    if (n > 0) p("\x1b[{d}A", .{n});90}9192pub fn clearLine() void {93    p("\r\x1b[K", .{});94}9596// --- Error and warning output ---9798pub fn printError(message: []const u8, detail: ?[]const u8, suggestion: ?[]const u8) void {99    p("{s}{s}\n", .{ if (color_enabled) ERR_C else ERR_P, message });100    if (detail) |d| p("   {s}{s}{s}\n", .{ c(DIM), d, c(RESET) });101    if (suggestion) |s| p("   {s}-> {s}{s}\n", .{ c(DIM), s, c(RESET) });102}103104pub fn printWarning(message: []const u8) void {105    p("{s}{s}\n", .{ if (color_enabled) WARN_C else WARN_P, message });106}107108pub fn printTeach(cmd: []const u8) void {109    if (teach_enabled) p("{s}{s}{s}\n", .{ teach_pfx(), cmd, c(RESET) });110}111112pub fn printSubstep(comptime fmt: []const u8, args: anytype) void {113    p("{s}", .{step()});114    p(fmt, args);115    p("\n", .{});116}117118// --- Confirmation prompt (returns true = yes) ---119120pub fn confirm(prompt: []const u8) bool {121    p("   {s}continue? [Y/n]  ", .{prompt});122    flush();123    var buf: [64]u8 = undefined;124    var i: usize = 0;125    while (i < buf.len) {126        const n = std.posix.read(std.posix.STDIN_FILENO, buf[i .. i + 1]) catch break;127        if (n == 0) break;128        if (buf[i] == '\n') break;129        i += 1;130    }131    const input = std.mem.trim(u8, buf[0..i], " \t");132    if (input.len == 0) return true;133    return input[0] != 'n' and input[0] != 'N';134}135136// --- Apply / rebuild ---137138pub fn applyStart(machine: []const u8) void {139    p("{s}rebuilding {s}...\n", .{ hdr(), machine });140}141142pub fn applyDone(gen: u32, elapsed_ms: u64) void {143    const secs = @as(f64, @floatFromInt(elapsed_ms)) / 1000.0;144    if (elapsed_ms >= 1000) {145        p("{s}generation {s}{d}{s}  {s}[{d:.1}s]{s}\n", .{ hdr(), c(BOLD), gen, c(RESET), c(DIM), secs, c(RESET) });146    } else {147        p("{s}generation {s}{d}{s}\n", .{ hdr(), c(BOLD), gen, c(RESET) });148    }149}150151pub fn applyFailed(translated: []const u8) void {152    p("{s}build failed\n", .{if (color_enabled) ERR_C else ERR_P});153    if (translated.len > 0) p("   {s}{s}{s}\n", .{ c(DIM), translated, c(RESET) });154    p("   {s}-> nina doctor{s}\n", .{ c(DIM), c(RESET) });155}156157pub fn applyDry(machine: []const u8) void {158    p("{s}dry run  {s}\n", .{ hdr(), machine });159}160161pub fn applyDryDone() void {162    p("{s}no changes applied\n", .{hdr()});163}164165// --- Check ---166167pub fn checkStart(machine: []const u8) void {168    p("{s}checking {s}...\n", .{ hdr(), machine });169}170171pub fn checkOk() void {172    p("{s}{s}ok{s}\n", .{ hdr(), c(GREEN), c(RESET) });173}174175pub fn checkFailed(msg: []const u8) void {176    p("{s}config invalid\n", .{if (color_enabled) ERR_C else ERR_P});177    if (msg.len > 0) p("   {s}{s}{s}\n", .{ c(DIM), msg, c(RESET) });178}179180// --- Back / go ---181182pub fn backStart(machine: []const u8, from: u32, to: u32) void {183    p("{s}rolling back  {s}  gen {d} -> gen {d}\n", .{ hdr(), machine, from, to });184}185186pub fn goStart(machine: []const u8, current: u32, target: u32) void {187    p("{s}switching  {s}  gen {d} -> gen {d}\n", .{ hdr(), machine, current, target });188}189190pub fn generationDone(n: u32) void {191    p("{s}done  gen {s}{d}{s}\n", .{ hdr(), c(BOLD), n, c(RESET) });192}193194// --- History ---195196pub fn historyHeader(machine: []const u8) void {197    p("{s}generations  {s}\n\n", .{ hdr(), machine });198}199200pub fn historyRow(gen: types.GenerationInfo) void {201    if (gen.current) {202        p("   {s}{d}{s}   {s}   {s}   {s}current{s}\n", .{ c(BOLD), gen.number, c(RESET), gen.date, gen.time, c(BOLD), c(RESET) });203    } else {204        p("   {s}{d}   {s}   {s}{s}\n", .{ c(DIM), gen.number, gen.date, gen.time, c(RESET) });205    }206}207208// --- Clean ---209210pub fn cleanStart(machine: []const u8, keep: u32, total: u32) void {211    p("{s}cleaning  {s}  keeping {d} of {d}\n", .{ hdr(), machine, keep, total });212}213214pub fn cleanDone(freed: []const u8) void {215    p("{s}freed {s}\n", .{ hdr(), freed });216}217218// --- Status ---219220pub fn statusHeader() void {221    p("{s}status\n\n", .{hdr()});222}223224pub fn statusRow(machine: []const u8, gen: u32, time: []const u8, size: []const u8, ok: bool) void {225    if (ok) {226        p("   {s}{s}   gen {d}   {s}   {s}{s}\n", .{ c(DIM), machine, gen, time, size, c(RESET) });227    } else {228        p("   {s}{s}   {s}unreachable{s}\n", .{ c(RED), machine, "", c(RESET) });229    }230}231232// --- Diff ---233234pub fn diffHeader(a: u32, b: u32, machine: []const u8) void {235    p("{s}gen {d} -> gen {d}  {s}\n\n", .{ hdr(), a, b, machine });236}237238pub fn diffRow(entry: types.DiffEntry) void {239    switch (entry.op) {240        .add => p("   {s}+{s} {s}   {s}\n", .{ c(GREEN), c(RESET), entry.package, entry.new_version orelse "" }),241        .remove => p("   {s}-{s} {s}   {s}\n", .{ c(RED), c(RESET), entry.package, entry.old_version orelse "" }),242        .change => p("   {s}^{s} {s}   {s} -> {s}\n", .{ c(CYAN), c(RESET), entry.package, entry.old_version orelse "", entry.new_version orelse "" }),243    }244}245246// --- Doctor ---247248pub fn doctorHeader(machine: []const u8) void {249    p("{s}diagnosing  {s}\n\n", .{ hdr(), machine });250}251252pub fn doctorRow(check: types.DoctorCheck) void {253    const status_str = switch (check.status) {254        .ok => if (color_enabled) GREEN ++ "ok" ++ RESET else "ok",255        .warn => if (color_enabled) YELLOW ++ "warn" ++ RESET else "warn",256        .fail => if (color_enabled) RED ++ "fail" ++ RESET else "fail",257    };258    const note_str = check.note orelse "";259    p("   {s:<16}  {s}   {s}\n", .{ check.name, status_str, note_str });260}261262pub fn doctorSummary(warnings: u32, failures: u32) void {263    if (failures > 0) {264        p("{s}{d} problems\n", .{ hdr(), failures });265    } else if (warnings > 0) {266        p("{s}{d} warnings\n", .{ hdr(), warnings });267    } else {268        p("{s}{s}all good{s}\n", .{ hdr(), c(GREEN), c(RESET) });269    }270}271272// --- Update ---273274pub fn updateStart(machine: []const u8) void {275    p("{s}updating channels  {s}\n\n", .{ hdr(), machine });276}277278pub fn updateChannel(name: []const u8, old: ?[]const u8, new: ?[]const u8) void {279    if (old != null and new != null and !std.mem.eql(u8, old.?, new.?)) {280        p("   {s}   {s} -> {s}\n", .{ name, old.?, new.? });281    } else {282        p("   {s}   {s}no change{s}\n", .{ name, c(DIM), c(RESET) });283    }284}285286pub fn updateDone() void {287    p("\n{s}done\n", .{hdr()});288}289290// --- Upgrade ---291292pub fn upgradeStart(machine: []const u8) void {293    p("{s}upgrading  {s}\n", .{ hdr(), machine });294}295296// --- Log ---297298pub fn logHeader(machine: []const u8) void {299    p("{s}history  {s}\n\n", .{ hdr(), machine });300}301302pub fn logRow(date: []const u8, time: []const u8, action: []const u8, detail: []const u8) void {303    p("   {s}  {s}   {s:<12}  {s}\n", .{ date, time, action, detail });304}305306// --- Edit ---307308pub fn editOpen(path: []const u8, editor: []const u8) void {309    p("{s}opening {s}\n", .{ hdr(), path });310    printSubstep("{s}", .{editor});311    p("\n   {s}run nina check to validate before applying{s}\n", .{ c(DIM), c(RESET) });312}313314// --- Fmt ---315316pub fn fmtStart(path: []const u8) void {317    p("{s}formatting  {s}\n", .{ hdr(), path });318}319320pub fn fmtDone() void {321    p("{s}done\n", .{hdr()});322}323324pub fn fmtNeedsFormat() void {325    p("{s}needs formatting  {s}run nina fmt to fix{s}\n", .{ hdr(), c(DIM), c(RESET) });326}327328// --- Repl ---329330pub fn replStart() void {331    p("{s}nix repl  {s}nixpkgs loaded{s}  :q to exit\n", .{ hdr(), c(DIM), c(RESET) });332}333334// --- Develop ---335336pub fn developStart(pkgs: []const []const u8) void {337    p("{s}entering dev shell\n\n   ", .{hdr()});338    for (pkgs, 0..) |pkg, i| {339        if (i > 0) p("  ", .{});340        p("{s}", .{pkg});341    }342    p("\n\n   {s}exit to return{s}\n\n", .{ c(DIM), c(RESET) });343}344345pub fn developDone() void {346    p("{s}back\n", .{hdr()});347}348349// --- Info ---350351pub fn infoHeader(machine: []const u8) void {352    p("{s}{s}\n\n", .{ hdr(), machine });353}354355pub fn infoRow(key: []const u8, val: []const u8) void {356    p("   {s:<12}  {s}\n", .{ key, val });357}358359// --- Boot ---360361pub fn bootHeader(machine: []const u8) void {362    p("{s}boot entries  {s}\n\n", .{ hdr(), machine });363}364365pub fn bootEntry(entry: types.BootEntry, idx: usize) void {366    if (entry.current) {367        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) });368    } else {369        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) });370    }371    _ = idx;372}373374// --- Service ---375376pub fn serviceListHeader(machine: []const u8) void {377    p("{s}services  {s}\n\n", .{ hdr(), machine });378}379380pub fn serviceRow(svc: types.ServiceInfo) void {381    const state_str = switch (svc.state) {382        .active => if (color_enabled) GREEN ++ "active" ++ RESET else "active",383        .failed => if (color_enabled) RED ++ "failed" ++ RESET else "failed",384        .inactive => "inactive",385        .unknown => "unknown",386    };387    const uptime = svc.uptime orelse "";388    p("   {s:<24}  {s:<14}  {s}\n", .{ svc.name, state_str, uptime });389}390391pub fn serviceVerb(verb: []const u8, name: []const u8, machine: []const u8) void {392    p("{s}{s} {s}  {s}\n", .{ hdr(), verb, name, machine });393}394395pub fn serviceDone() void {396    p("{s}done\n", .{hdr()});397}398399pub fn serviceLogsHeader(name: []const u8, n: u32, machine: []const u8) void {400    p("{s}{s}  last {d} lines  {s}\n\n", .{ hdr(), name, n, machine });401}402403// --- Store ---404405pub fn storeInfo(info: types.StoreInfo) void {406    p("{s}store\n\n", .{hdr()});407    p("   {s:<16}  {s}\n", .{ "total", info.total_size });408    p("   {s:<16}  {d} paths\n", .{ "live", info.live_paths });409    p("   {s:<16}  {s}{d} paths{s}   run nina clean\n", .{ "reclaimable", c(DIM), info.reclaimable_paths, c(RESET) });410}411412// --- Channel ---413414pub fn channelListHeader(machine: []const u8) void {415    p("{s}channels  {s}\n\n", .{ hdr(), machine });416}417418pub fn channelRow(ch: types.ChannelInfo) void {419    p("   {s:<16}  {s}\n", .{ ch.name, ch.url });420}421422// --- Flake ---423424pub fn flakeUpdateStart() void {425    p("{s}updating inputs\n\n", .{hdr()});426}427428pub fn flakeInput(input: types.FlakeInput) void {429    if (input.changed) {430        const old = if (input.old_rev) |r| r[0..@min(7, r.len)] else "?";431        const new = if (input.new_rev) |r| r[0..@min(7, r.len)] else "?";432        p("   {s:<20}  {s} -> {s}\n", .{ input.name, old, new });433    } else {434        p("   {s:<20}  {s}no change{s}\n", .{ input.name, c(DIM), c(RESET) });435    }436}437438pub fn flakeLockWritten() void {439    p("\n{s}flake.lock written\n", .{hdr()});440}441442pub fn flakeValid() void {443    p("{s}{s}valid{s}\n", .{ hdr(), c(GREEN), c(RESET) });444}445446pub fn flakeCheckStart() void {447    p("{s}checking flake\n", .{hdr()});448}449450// --- Profile ---451452pub fn profileListHeader() void {453    p("{s}profile packages\n\n", .{hdr()});454}455456pub fn profileRow(attr: []const u8, pkg_version: []const u8, description: []const u8) void {457    p("   {s:<24}  {s:<12}  {s}\n", .{ attr, pkg_version, description });458}459460// --- Install / Remove / Try ---461462pub fn installStart(pkg: []const u8, path: types.InstallPath) void {463    const path_str = switch (path) {464        .profile => "profile",465        .system => "system",466    };467    p("{s}installing {s}{s}{s}  {s}\n", .{ hdr(), c(PINK), pkg, c(RESET), path_str });468}469470pub fn installDone(pkg: []const u8) void {471    p("{s}{s}{s}{s} installed  {s}available now{s}\n", .{ hdr(), c(PINK), pkg, c(RESET), c(DIM), c(RESET) });472}473474pub fn installEditorPrompt(pkg: []const u8, config_path: []const u8, line: u32, editor: []const u8) void {475    p("{s}opening {s}  add {s}{s}{s} to systemPackages\n", .{ hdr(), config_path, c(PINK), pkg, c(RESET) });476    const cmd = std.fmt.allocPrint(std.heap.page_allocator, "{s} {s} +{d}", .{ editor, config_path, line }) catch editor;477    printSubstep("{s}", .{cmd});478    p("\n   {s}save and close when done{s}\n\n", .{ c(DIM), c(RESET) });479}480481pub fn installSelectPrompt(pkg: []const u8, pkg_version: []const u8) void {482    p("{s}{s}{s}{s}  {s}\n\n", .{ hdr(), c(PINK), pkg, c(RESET), pkg_version });483    p("   [i] profile install    {s}instant  no rebuild{s}\n", .{ c(DIM), c(RESET) });484    p("   [s] system install     {s}opens editor  requires apply{s}\n", .{ c(DIM), c(RESET) });485    p("   [t] try now            {s}exits when done{s}\n\n", .{ c(DIM), c(RESET) });486    p("   > ", .{});487    flush();488}489490pub fn tryStart(pkg: []const u8) void {491    p("{s}trying {s}{s}{s}  exit when done\n", .{ hdr(), c(PINK), pkg, c(RESET) });492}493494pub fn tryDone() void {495    p("{s}back\n", .{hdr()});496}497498// --- List ---499500pub fn listHeader() void {501    p("{s}installed packages\n\n", .{hdr()});502}503504pub fn listSection(title: []const u8) void {505    p("   {s}{s}{s}\n", .{ c(DIM), title, c(RESET) });506}507508pub fn listPkg(name: []const u8, pkg_version: []const u8) void {509    p("   {s}{s}{s}   {s}{s}{s}\n", .{ c(PINK), name, c(RESET), c(DIM), pkg_version, c(RESET) });510}511512// --- Hello ---513514pub fn hello(machines: []const types.Machine) void {515    p("{s}nina\n\n", .{hdr()});516    for (machines) |m| {517        const kind = if (m.local) "local" else "ssh";518        const detail = if (m.local) "default" else m.host orelse "";519        p("   {s}{s}{s}   {s}   {s}\n", .{ c(DIM), m.name, c(RESET), kind, detail });520    }521    p("\n", .{});522    const quick = [_][2][]const u8{523        .{ "apply",         "rebuild and switch" },524        .{ "search <q>",    "find packages" },525        .{ "install <pkg>", "add to profile or system" },526        .{ "status",        "machine health" },527        .{ "back",          "roll back one generation" },528        .{ "update",        "refresh channels" },529    };530    for (quick) |cmd| {531        p("   {s:<16}  {s}{s}{s}\n", .{ cmd[0], c(DIM), cmd[1], c(RESET) });532    }533    p("\n", .{});534}535536// --- Help ---537538pub fn help() void {539    p("{s}nina  {s}nixos helper{s}\n\n", .{ hdr(), c(DIM), c(RESET) });540    const cmds = [_][2][]const u8{541        .{ "apply", "rebuild and switch" },542        .{ "back", "roll back one generation" },543        .{ "go <n>", "switch to generation n" },544        .{ "history", "list all generations" },545        .{ "clean", "remove old generations" },546        .{ "search <q>", "find packages" },547        .{ "install <pkg>", "add to profile or system" },548        .{ "remove <pkg>", "remove from profile or system" },549        .{ "try <pkg>", "test without installing" },550        .{ "list", "show installed packages" },551        .{ "edit", "open configuration.nix" },552        .{ "check", "validate config" },553        .{ "diff", "changes between generations" },554        .{ "status", "machine health" },555        .{ "update", "refresh channels" },556        .{ "upgrade", "update and rebuild" },557        .{ "log", "operation history" },558        .{ "doctor", "diagnose issues" },559        .{ "develop", "enter dev shell" },560        .{ "flake", "flake management" },561        .{ "build", "build a package" },562        .{ "run", "run without installing" },563        .{ "service", "manage services" },564        .{ "store", "nix store tools" },565        .{ "channel", "manage channels" },566        .{ "profile", "user profile packages" },567        .{ "info", "system information" },568        .{ "boot", "boot entries" },569        .{ "fmt", "format configuration.nix" },570        .{ "repl", "nix repl with nixpkgs" },571        .{ "option <q>", "search nixos options" },572        .{ "pkg", "inspect packages" },573        .{ "pin", "pin flake inputs" },574        .{ "hash", "compute nix hash" },575        .{ "fetch", "fetch and hash a url" },576        .{ "goodbye",       "uninstall nina" },577        .{ "hello",        "list machines" },578        .{ "help",         "this message" },579    };580    for (cmds) |cmd| {581        p("   {s:<18}  {s}{s}{s}\n", .{ cmd[0], c(DIM), cmd[1], c(RESET) });582    }583    p("\n   {s}flags: --on <machine>  --dry  --check  --no-apply  --last <n>  --all  --json{s}\n", .{ c(DIM), c(RESET) });584}585586pub fn version() void {587    p("{s}nina  v{s}  zig 0.16  zero dependencies\n", .{ hdr(), nina_version.VERSION });588}589590// --- Search (text output before TUI) ---591592pub fn searchResult(pkg: types.NixPackage) void {593    p("   {s}{s}{s}   {s}{s}{s}   {s}\n", .{ c(PINK), pkg.pname, c(RESET), c(DIM), pkg.version, c(RESET), pkg.description });594}595596pub fn searchHeader(query: []const u8, count: usize) void {597    p("{s}search nixpkgs {s}  {s}{d} results{s}\n\n", .{ hdr(), query, c(DIM), count, c(RESET) });598}599600// --- Gen commands ---601602pub fn genCurrent(n: u32) void {603    p("{d}\n", .{n});604}605606pub fn done() void {607    p("{s}done\n", .{hdr()});608}609610pub fn runStart(pkg: []const u8) void {611    p("{s}running {s}{s}{s}\n", .{ hdr(), c(PINK), pkg, c(RESET) });612}613614pub fn buildStart(attr: []const u8) void {615    p("{s}building {s}\n", .{ hdr(), attr });616}617618pub fn buildDone() void {619    p("{s}done\n", .{hdr()});620}621622// --- Self-update (nina update) ---623624pub fn updateSelfStart() void {625    p("{s}checking for updates\n", .{hdr()});626}627628pub fn updateSelfCurrent(ver: []const u8) void {629    p("{s}{s}nina {s} is up to date{s}\n", .{ hdr(), c(GREEN), ver, c(RESET) });630}631632pub fn updateSelfAvailable(current: []const u8, latest: []const u8) void {633    p("{s}current  {s}\n", .{ step(), current });634    p("{s}latest   {s}{s}{s}\n", .{ step(), c(BOLD), latest, c(RESET) });635}636637pub fn updateSelfDownloading(ver: []const u8, platform: []const u8) void {638    p("{s}downloading nina {s} for {s}\n", .{ step(), ver, platform });639}640641pub fn updateSelfVerifying() void {642    p("{s}verifying checksum\n", .{step()});643}644645pub fn updateSelfInstalling(install_path: []const u8) void {646    p("{s}installing to {s}\n", .{ step(), install_path });647}648649pub fn updateSelfDone(old_ver: []const u8, new_ver: []const u8) void {650    p("{s}updated  {s} {s}→{s} {s}\n", .{ hdr(), old_ver, c(DIM), c(RESET), new_ver });651}652653pub fn updateSelfNoPlatform(platform: []const u8) void {654    p("{s}no pre-built binary for {s}\n", .{ hdr(), platform });655    p("{s}check kepr.uk/nina/releases for available platforms\n", .{step()});656}657658pub fn updateSelfNetworkError() void {659    p("{s}{s}\n", .{ if (color_enabled) WARN_C else WARN_P, "could not reach kepr.uk — check your connection" });660}661662pub fn updateSelfChecksumFailed() void {663    p("{s}checksum mismatch — download may be corrupt\n", .{if (color_enabled) ERR_C else ERR_P});664    p("{s}try again or download manually from kepr.uk/nina/releases\n", .{step()});665}666667pub fn updateSelfNixManaged(new_ver: []const u8) void {668    p("{s}upgrading to {s}{s}{s} via nix profile\n", .{ step(), c(BOLD), new_ver, c(RESET) });669}670671pub fn updateSelfNixFailed() void {672    p("{s}nix profile upgrade failed\n", .{if (color_enabled) ERR_C else ERR_P});673    p("{s}try manually: nix profile upgrade '.*nina.*'\n", .{step()});674}675676pub fn updateSelfNixSystemManaged() void {677    p("{s}nina appears to be managed by your NixOS system configuration\n", .{hdr()});678    p("{s}to update: sudo nixos-rebuild switch\n", .{step()});679    p("{s}to reinstall as a profile package: curl -fsSL kepr.uk/nina/install.sh | sh\n", .{step()});680}681682// --- Goodbye / uninstall ---683684pub fn goodbyeStart() void {685    p("{s}uninstalling nina\n", .{hdr()});686}687688pub fn goodbyeFile(path: []const u8) void {689    p("{s}will remove {s}\n", .{ step(), path });690}691692pub fn goodbyeNix() void {693    p("{s}will remove nina from nix profile\n", .{step()});694    p("{s}command: nix profile remove '.*nina.*'\n", .{step()});695}696697pub fn goodbyeNixSystemManaged() void {698    p("{s}nina is managed by your NixOS system configuration\n", .{hdr()});699    p("{s}to remove: delete ~/nina.nix, then run sudo nixos-rebuild switch\n", .{step()});700    p("{s}or remove the nina import from /etc/nixos/configuration.nix directly\n", .{step()});701}702703pub fn goodbyeNixFileFound(path: []const u8) void {704    p("{s}found {s} (NixOS config snippet from the installer)\n", .{ step(), path });705}706707pub fn goodbyeDone() void {708    p("{s}goodbye! reinstall anytime: curl -fsSL kepr.uk/nina/install.sh | sh\n", .{hdr()});709}710711pub fn goodbyeFailed(msg: []const u8) void {712    p("{s}{s}\n", .{ if (color_enabled) ERR_C else ERR_P, msg });713}714715// --- Setup ---716717pub fn setupCheck() void {718    p("{s}checking nix features\n", .{hdr()});719}720721pub fn setupFeatures(nix_command: bool, flakes: bool) void {722    p("{s}nix-command  {s}{s}{s}\n", .{723        step(),724        if (nix_command) c(GREEN) else "",725        if (nix_command) "enabled" else "not enabled",726        if (nix_command) c(RESET) else "",727    });728    p("{s}flakes       {s}{s}{s}\n", .{729        step(),730        if (flakes) c(GREEN) else "",731        if (flakes) "enabled" else "not enabled",732        if (flakes) c(RESET) else "",733    });734}735736pub fn setupAllSet() void {737    p("{s}all set\n", .{hdr()});738}739740// Printed once, before the first search, when the nixpkgs registry still points741// at a remote URL. Flush so it lands before `nix registry pin` and any results.742pub fn pinningRegistry() void {743    p("{s}pinning nixpkgs for fast local search...\n", .{hdr()});744    flush();745}746747// --- Plain (non-tty) search rendering ---748// Color-gated equivalents of the raw-ANSI TUI widget, for piped/scripted search.749// Using the gated header + c() keeps ANSI out of non-tty output (NO_COLOR / pipes).750751pub fn searchPlainHeader(mode_str: []const u8, query: []const u8, count: u64) void {752    p("{s}search {s} {s}  {s}{d} results{s}\n", .{ hdr(), mode_str, query, c(DIM), count, c(RESET) });753}754755pub fn searchPlainNoResults() void {756    p("   no results\n", .{});757}758759pub fn searchPlainPackage(pname: []const u8, pkg_version: []const u8, description: []const u8, unfree: bool) void {760    if (unfree) {761        p("   {s}   {s}{s}{s}   {s}unfree{s}   {s}\n", .{ pname, c(DIM), pkg_version, c(RESET), c(YELLOW), c(RESET), description });762    } else {763        p("   {s}   {s}{s}{s}   {s}\n", .{ pname, c(DIM), pkg_version, c(RESET), description });764    }765}766767pub fn searchPlainOption(name: []const u8, type_str: []const u8) void {768    p("   {s}   {s}{s}{s}\n", .{ name, c(DIM), type_str, c(RESET) });769}770771pub fn searchEmptyQuery() void {772    p("{s}search needs a query  {s}e.g. nina search firefox{s}\n", .{ hdr(), c(DIM), c(RESET) });773}774775pub fn setupEnabling() void {776    p("{s}enabling experimental features\n", .{hdr()});777}778779pub fn setupDone(path: []const u8, is_nixos: bool) void {780    p("{s}wrote {s}\n", .{ step(), path });781    p("{s}done  open a new shell to pick up the change\n", .{hdr()});782    if (is_nixos) {783        printSubstep("to persist across nixos-rebuild, add to configuration.nix:", .{});784        printSubstep("  nix.settings.experimental-features = [ \"nix-command\" \"flakes\" ];", .{});785    }786}787788pub fn pinDone(input: []const u8, commit: []const u8) void {789    p("{s}pinned {s} -> {s}\n", .{ hdr(), input, commit });790}791792pub fn unpinDone(input: []const u8) void {793    p("{s}unpinned {s}\n", .{ hdr(), input });794}795796pub fn hashResult(hash: []const u8) void {797    p("{s}\n", .{hash});798}799800pub fn fetchResult(hash: []const u8, url: []const u8) void {801    _ = url;802    p("{s}\n", .{hash});803}804805pub fn storeRepairStart() void {806    p("{s}repairing store\n", .{hdr()});807}808809pub fn storeVerifyStart() void {810    p("{s}verifying store\n", .{hdr()});811}812813pub fn storeGcDone(freed: []const u8) void {814    p("{s}freed {s}\n", .{ hdr(), freed });815}816817pub fn storePath(path: []const u8) void {818    p("{s}\n", .{path});819}820821pub fn pkgResult(key: []const u8, val: []const u8) void {822    p("   {s:<16}  {s}\n", .{ key, val });823}824825pub fn channelDone() void {826    p("{s}done\n", .{hdr()});827}828829pub fn flakeShowHeader(name: []const u8) void {830    p("{s}{s}\n\n", .{ hdr(), name });831}832833pub fn flakeShowEntry(kind: []const u8, name: []const u8, desc: []const u8) void {834    p("   {s:<12}  {s:<24}  {s}\n", .{ kind, name, desc });835}