output.zig

41.6 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// kaomoji constants — all kaomoji defined here, never inlined elsewhere. Rare19// and earned: each marks one genuine moment and never repeats in one output20// block. They are plain text, not ANSI, so they survive pipes and NO_COLOR.21const KAO_FACE = "(˶ᵔ ᵕ ᵔ˶)  "; // hello — her face22const KAO_COZY = "(っ˘ω˘ς)  "; // apply start23const KAO_EXCITED = "╰(*°▽°*)╯  "; // apply success after a failure this session24const KAO_GENTLE = "( ˘ᵕ˘ )  "; // back done25const KAO_CONTENT = "( ´ ∀ ` )  "; // clean freed26const KAO_HAPPY = "( ´ ▽ ` )  "; // doctor all clear / mood all good27const KAO_SLEEPY = "(˘ω˘ )  "; // try / develop exit28const KAO_READY = "( •̀ᴗ•́ )  "; // update start29const KAO_SAD = "(;ω;)  "; // network or ssh errors only — never user typos3031// Exported for TUI use (search.zig references these to avoid \x1b in that file)32pub const C_PINK = PINK;33pub const C_BOLD = BOLD;34pub const C_GREEN = GREEN;35pub const C_YELLOW = YELLOW;36pub const C_RED = RED;37pub const C_CYAN = CYAN;38pub const C_DIM = DIM;39pub const C_RESET = RESET;40pub const C_CLEAR_EOL = "\x1b[K";41pub const C_CURSOR_UP_FMT = "\x1b[{d}A";4243// Precomputed prefix strings44const HDR_C = PINK ++ ":: " ++ RESET;45const HDR_P = ":: ";46const STEP_C = "   " ++ DIM ++ "-> " ++ RESET;47const STEP_P = "   -> ";48const TEACH_C = "   " ++ DIM ++ "= " ++ RESET;49const TEACH_P = "   = ";50const ERR_C = PINK ++ ":: " ++ RED ++ "error:" ++ RESET ++ " ";51const ERR_P = ":: error: ";52const WARN_C = PINK ++ ":: " ++ YELLOW ++ "warning:" ++ RESET ++ " ";53const WARN_P = ":: warning: ";5455var _fw: Io.File.Writer = undefined;56var _w: *Io.Writer = undefined;57var color_enabled: bool = true;58var teach_enabled: bool = false;5960pub fn init(writer: *Io.Writer, io: std.Io, environ: *const std.process.Environ.Map, color_config: bool) void {61    _w = writer;62    color_enabled = color_config and63        (std.Io.File.stdout().isTty(io) catch false) and64        !environ.contains("NO_COLOR");65}6667pub fn setTeach(enabled: bool) void {68    teach_enabled = enabled;69}7071pub fn flush() void {72    _w.flush() catch {};73}7475// Whether ANSI color is active (tty + config + no NO_COLOR). Callers spawning76// child processes that colorize their own output use this to gate the child.77pub fn colorEnabled() bool {78    return color_enabled;79}8081fn c(code: []const u8) []const u8 {82    return if (color_enabled) code else "";83}8485fn hdr() []const u8 {86    return if (color_enabled) HDR_C else HDR_P;87}8889fn step() []const u8 {90    return if (color_enabled) STEP_C else STEP_P;91}9293fn teach_pfx() []const u8 {94    return if (color_enabled) TEACH_C else TEACH_P;95}9697// Raw write — used by TUI98pub fn raw(bytes: []const u8) void {99    _w.writeAll(bytes) catch {};100}101102// Formatted print — used by TUI for in-place rendering103pub fn p(comptime fmt: []const u8, args: anytype) void {104    _w.print(fmt, args) catch {};105}106107pub fn cursorUp(n: usize) void {108    if (n > 0) p("\x1b[{d}A", .{n});109}110111pub fn clearLine() void {112    p("\r\x1b[K", .{});113}114115// --- Error and warning output ---116117pub fn printError(message: []const u8, detail: ?[]const u8, suggestion: ?[]const u8) void {118    p("{s}{s}\n", .{ if (color_enabled) ERR_C else ERR_P, message });119    if (detail) |d| p("   {s}{s}{s}\n", .{ c(DIM), d, c(RESET) });120    // Actionable suggestion in cyan — the next step should catch the eye.121    if (suggestion) |s| p("   {s}-> {s}{s}\n", .{ c(CYAN), s, c(RESET) });122}123124// Like printError, but for genuine system failures (network/ssh/search). The sad125// kaomoji signals "this is on the machine, not on you" — never used for typos or126// not-found errors, which go through printError.127pub fn printSystemError(message: []const u8, detail: ?[]const u8, suggestion: ?[]const u8) void {128    p("{s}{s}{s}\n", .{ KAO_SAD, if (color_enabled) ERR_C else ERR_P, message });129    if (detail) |d| p("   {s}{s}{s}\n", .{ c(DIM), d, c(RESET) });130    if (suggestion) |s| p("   {s}-> {s}{s}\n", .{ c(CYAN), s, c(RESET) });131}132133pub fn printWarning(message: []const u8) void {134    p("{s}{s}\n", .{ if (color_enabled) WARN_C else WARN_P, message });135}136137pub fn aborted() void {138    p("{s}aborted\n", .{hdr()});139}140141// One-time dim note when ~/.nina.conf is migrated to the XDG config path.142pub fn configMigrated(path: []const u8) void {143    p("{s}{s}config migrated to {s}{s}\n", .{ step(), c(DIM), path, c(RESET) });144}145146pub fn printTeach(cmd: []const u8) void {147    if (teach_enabled) p("{s}{s}{s}\n", .{ teach_pfx(), cmd, c(RESET) });148}149150pub fn printSubstep(comptime fmt: []const u8, args: anytype) void {151    p("{s}", .{step()});152    p(fmt, args);153    p("\n", .{});154}155156pub fn hookFailed(name: []const u8, code: u8, hook_output: []const u8) void {157    p("{s}{s} hook exited with code {d}{s}\n\n", .{ hdr(), name, code, c(RESET) });158159    if (hook_output.len > 0) {160        var lines = std.mem.splitScalar(u8, hook_output, '\n');161        var shown: [5][]const u8 = undefined;162        var count: usize = 0;163        while (lines.next()) |line| {164            const trimmed = std.mem.trim(u8, line, " \t\r");165            if (trimmed.len == 0) continue;166            shown[count % shown.len] = trimmed;167            count += 1;168        }169170        const display_count = @min(count, shown.len);171        const start = count - display_count;172        for (0..display_count) |i| {173            const line = shown[(start + i) % shown.len];174            p("   {s}{s}{s}\n", .{ c(DIM), line, c(RESET) });175        }176        p("\n", .{});177    }178}179180pub fn hookWarning(name: []const u8, code: u8, hook_output: []const u8) void {181    _ = hook_output;182    p("{s}   warning: {s} hook exited with code {d}{s}\n", .{ c(YELLOW), name, code, c(RESET) });183}184185// --- Confirmation prompt (returns true = yes) ---186187pub fn confirm(prompt: []const u8) bool {188    p("   {s}continue? [Y/n]  ", .{prompt});189    flush();190    var buf: [64]u8 = undefined;191    var i: usize = 0;192    while (i < buf.len) {193        const n = std.posix.read(std.posix.STDIN_FILENO, buf[i .. i + 1]) catch break;194        if (n == 0) break;195        if (buf[i] == '\n') break;196        i += 1;197    }198    const input = std.mem.trim(u8, buf[0..i], " \t");199    if (input.len == 0) return true;200    return input[0] != 'n' and input[0] != 'N';201}202203// Like confirm, but defaults to NO on an empty answer — for prompts that touch204// system files, where a stray Enter should never trigger the action.205pub fn confirmDefaultNo(question: []const u8) bool {206    p("   {s} [y/N]  ", .{question});207    flush();208    var buf: [64]u8 = undefined;209    var i: usize = 0;210    while (i < buf.len) {211        const n = std.posix.read(std.posix.STDIN_FILENO, buf[i .. i + 1]) catch break;212        if (n == 0) break;213        if (buf[i] == '\n') break;214        i += 1;215    }216    const input = std.mem.trim(u8, buf[0..i], " \t");217    if (input.len == 0) return false;218    return input[0] == 'y' or input[0] == 'Y';219}220221// --- Apply / rebuild ---222223pub fn applyStart(machine: []const u8) void {224    p("{s}{s}rebuilding {s}...\n", .{ KAO_COZY, hdr(), machine });225}226227// after_failure: true only when the previous apply this session failed and this228// one succeeded — the one moment that earns the excited kaomoji. Routine229// successes show no kaomoji.230pub fn applyDone(gen: u32, elapsed_ms: u64, after_failure: bool) void {231    const face = if (after_failure) KAO_EXCITED else "";232    const secs = @as(f64, @floatFromInt(elapsed_ms)) / 1000.0;233    if (elapsed_ms >= 1000) {234        p("{s}{s}generation {s}{d}{s}  {s}[{d:.1}s]{s}\n", .{ face, hdr(), c(BOLD), gen, c(RESET), c(DIM), secs, c(RESET) });235    } else {236        p("{s}{s}generation {s}{d}{s}\n", .{ face, hdr(), c(BOLD), gen, c(RESET) });237    }238}239240pub fn applyFailed(translated: []const u8) void {241    p("{s}build failed\n", .{if (color_enabled) ERR_C else ERR_P});242    if (translated.len > 0) p("   {s}{s}{s}\n", .{ c(DIM), translated, c(RESET) });243    p("   {s}-> nina doctor{s}\n", .{ c(DIM), c(RESET) });244}245246pub fn applyDry(machine: []const u8) void {247    p("{s}dry run  {s}\n", .{ hdr(), machine });248}249250pub fn applyDryDone() void {251    p("{s}no changes applied\n", .{hdr()});252}253254// --- Check ---255256pub fn checkStart(machine: []const u8) void {257    p("{s}checking {s}...\n", .{ hdr(), machine });258}259260pub fn checkOk() void {261    p("{s}{s}ok{s}\n", .{ hdr(), c(GREEN), c(RESET) });262}263264pub fn checkFailed(msg: []const u8) void {265    p("{s}config invalid\n", .{if (color_enabled) ERR_C else ERR_P});266    if (msg.len > 0) p("   {s}{s}{s}\n", .{ c(DIM), msg, c(RESET) });267}268269// --- Back / go ---270271pub fn backStart(machine: []const u8, from: u32, to: u32) void {272    p("{s}rolling back  {s}  gen {d} -> gen {d}\n", .{ hdr(), machine, from, to });273}274275pub fn goStart(machine: []const u8, current: u32, target: u32) void {276    p("{s}switching  {s}  gen {d} -> gen {d}\n", .{ hdr(), machine, current, target });277}278279pub fn generationDone(n: u32) void {280    p("{s}done  gen {s}{d}{s}\n", .{ hdr(), c(BOLD), n, c(RESET) });281}282283// `back` has nothing older to roll back to. This is a clean stop, not a build284// failure — the rollback would otherwise surface nixos-rebuild's confusing285// 'no profile version older than the current' as a fake build error.286pub fn alreadyOldest() void {287    p("{s}already at the oldest generation\n", .{if (color_enabled) ERR_C else ERR_P});288}289290// Like generationDone but for `back` specifically — a successful rollback earns291// the gentle kaomoji. `go` keeps the plain generationDone line.292pub fn backDone(n: u32) void {293    p("{s}{s}done  gen {s}{d}{s}\n", .{ KAO_GENTLE, hdr(), c(BOLD), n, c(RESET) });294}295296// --- History ---297298pub fn historyHeader(machine: []const u8) void {299    p("{s}generations  {s}\n\n", .{ hdr(), machine });300}301302pub fn historyRow(gen: types.GenerationInfo) void {303    if (gen.current) {304        p("   {s}{d}{s}   {s}   {s}   {s}current{s}\n", .{ c(BOLD), gen.number, c(RESET), gen.date, gen.time, c(BOLD), c(RESET) });305    } else {306        p("   {s}{d}   {s}   {s}{s}\n", .{ c(DIM), gen.number, gen.date, gen.time, c(RESET) });307    }308}309310// --- Clean ---311312pub fn cleanStart(machine: []const u8, keep: u32, total: u32) void {313    p("{s}cleaning  {s}  keeping {d} of {d}\n", .{ hdr(), machine, keep, total });314}315316// Fewer generations than the keep limit — there's nothing to collect. Avoids the317// nonsensical 'keeping 5 of 1'.318pub fn cleanNothing(machine: []const u8, total: u32) void {319    p("{s}cleaning  {s}\n\n", .{ hdr(), machine });320    p("   only {d} generation{s} — nothing to remove.\n", .{ total, if (total == 1) "" else "s" });321}322323pub fn cleanDone() void {324    p("{s}{s}done\n", .{ KAO_CONTENT, hdr() });325}326327// --- Status ---328329pub fn statusHeader() void {330    p("{s}status\n\n", .{hdr()});331}332333pub fn statusRow(machine: []const u8, gen: u32, time: []const u8, size: []const u8, ok: bool) void {334    if (ok) {335        p("   {s}{s}{s}   gen {s}{d}{s}   {s}{s}   {s}{s}\n", .{ c(DIM), machine, c(RESET), c(BOLD), gen, c(RESET), c(DIM), time, size, c(RESET) });336    } else {337        p("   {s}{s}   {s}unreachable{s}\n", .{ c(RED), machine, "", c(RESET) });338    }339}340341// Dim Home Manager generation line, indented under the machine row. Only shown342// when standalone HM is detected; absent otherwise so the layout is unchanged.343pub fn statusHomeRow(gen: u32, detail: []const u8) void {344    if (detail.len > 0) {345        p("   {s}         hm  gen {d}   {s}{s}\n", .{ c(DIM), gen, detail, c(RESET) });346    } else {347        p("   {s}         hm  gen {d}{s}\n", .{ c(DIM), gen, c(RESET) });348    }349}350351// --- Diff ---352353pub fn diffHeader(a: u32, b: u32, machine: []const u8) void {354    p("{s}gen {d} -> gen {d}  {s}\n\n", .{ hdr(), a, b, machine });355}356357pub fn diffRow(entry: types.DiffEntry) void {358    switch (entry.op) {359        .add => p("   {s}+{s} {s}   {s}\n", .{ c(GREEN), c(RESET), entry.package, entry.new_version orelse "" }),360        .remove => p("   {s}-{s} {s}   {s}\n", .{ c(RED), c(RESET), entry.package, entry.old_version orelse "" }),361        .change => p("   {s}^{s} {s}   {s} -> {s}\n", .{ c(CYAN), c(RESET), entry.package, entry.old_version orelse "", entry.new_version orelse "" }),362    }363}364365// --- Doctor ---366367pub fn doctorHeader(machine: []const u8) void {368    p("{s}diagnosing  {s}\n\n", .{ hdr(), machine });369}370371pub fn doctorRow(check: types.DoctorCheck) void {372    const status_str = switch (check.status) {373        .ok => if (color_enabled) GREEN ++ "ok" ++ RESET else "ok",374        .warn => if (color_enabled) YELLOW ++ "warn" ++ RESET else "warn",375        .fail => if (color_enabled) RED ++ "fail" ++ RESET else "fail",376    };377    const note_str = check.note orelse "";378    p("   {s:<16}  {s}   {s}\n", .{ check.name, status_str, note_str });379}380381pub fn doctorSummary(warnings: u32, failures: u32) void {382    if (failures > 0) {383        p("{s}{d} problems\n", .{ hdr(), failures });384    } else if (warnings > 0) {385        p("{s}{d} warnings\n", .{ hdr(), warnings });386    } else {387        p("{s}{s}{s}all good{s}\n", .{ KAO_HAPPY, hdr(), c(GREEN), c(RESET) });388    }389}390391// --- Update ---392393pub fn updateStart(machine: []const u8) void {394    p("{s}updating channels  {s}\n\n", .{ hdr(), machine });395}396397pub fn updateChannel(name: []const u8, old: ?[]const u8, new: ?[]const u8) void {398    if (old != null and new != null and !std.mem.eql(u8, old.?, new.?)) {399        p("   {s}   {s} -> {s}\n", .{ name, old.?, new.? });400    } else {401        p("   {s}   {s}no change{s}\n", .{ name, c(DIM), c(RESET) });402    }403}404405pub fn updateDone() void {406    p("\n{s}done\n", .{hdr()});407}408409// --- Upgrade ---410411pub fn upgradeStart(machine: []const u8) void {412    p("{s}upgrading  {s}\n", .{ hdr(), machine });413}414415// --- Log ---416417pub fn logHeader(machine: []const u8) void {418    p("{s}history  {s}\n\n", .{ hdr(), machine });419}420421pub fn logRow(date: []const u8, time: []const u8, action: []const u8, detail: []const u8) void {422    p("   {s}{s}  {s}{s}   {s:<16}  {s}\n", .{ c(DIM), date, time, c(RESET), action, detail });423}424425// --- Edit ---426427pub fn editOpen(path: []const u8, editor: []const u8) void {428    p("{s}opening {s}\n", .{ hdr(), path });429    printSubstep("{s}", .{editor});430    p("\n   {s}run nina check to validate before applying{s}\n", .{ c(DIM), c(RESET) });431}432433// --- Fmt ---434435pub fn fmtStart(path: []const u8) void {436    p("{s}formatting  {s}\n", .{ hdr(), path });437}438439pub fn fmtDone() void {440    p("{s}done\n", .{hdr()});441}442443pub fn fmtNeedsFormat() void {444    p("{s}needs formatting  {s}run nina fmt to fix{s}\n", .{ hdr(), c(DIM), c(RESET) });445}446447// --- Repl ---448449pub fn replStart() void {450    p("{s}nix repl  {s}nixpkgs loaded{s}  :q to exit\n", .{ hdr(), c(DIM), c(RESET) });451}452453// --- Develop ---454455pub fn developStart(pkgs: []const []const u8) void {456    p("{s}entering dev shell\n\n   ", .{hdr()});457    for (pkgs, 0..) |pkg, i| {458        if (i > 0) p("  ", .{});459        p("{s}", .{pkg});460    }461    p("\n\n   {s}-> press Ctrl+C or type 'exit' to return{s}\n\n", .{ c(DIM), c(RESET) });462}463464pub fn developDone() void {465    p("{s}{s}back\n", .{ KAO_SLEEPY, hdr() });466}467468// --- Info ---469470pub fn infoHeader(machine: []const u8) void {471    p("{s}{s}\n\n", .{ hdr(), machine });472}473474pub fn infoRow(key: []const u8, val: []const u8) void {475    p("   {s:<12}  {s}\n", .{ key, val });476}477478// --- Boot ---479480pub fn bootHeader(machine: []const u8) void {481    p("{s}boot entries  {s}\n\n", .{ hdr(), machine });482}483484pub fn bootEntry(entry: types.BootEntry, idx: usize) void {485    if (entry.current) {486        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) });487    } else {488        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) });489    }490    _ = idx;491}492493// --- Service ---494495pub fn serviceListHeader(machine: []const u8) void {496    p("{s}services  {s}\n\n", .{ hdr(), machine });497}498499pub fn serviceRow(svc: types.ServiceInfo) void {500    const state_str = switch (svc.state) {501        .active => if (color_enabled) GREEN ++ "active" ++ RESET else "active",502        .failed => if (color_enabled) RED ++ "failed" ++ RESET else "failed",503        .inactive => "inactive",504        .unknown => "unknown",505    };506    const uptime = svc.uptime orelse "";507    p("   {s:<24}  {s:<14}  {s}\n", .{ svc.name, state_str, uptime });508}509510pub fn serviceVerb(verb: []const u8, name: []const u8, machine: []const u8) void {511    p("{s}{s} {s}  {s}\n", .{ hdr(), verb, name, machine });512}513514pub fn serviceDone() void {515    p("{s}done\n", .{hdr()});516}517518pub fn serviceLogsHeader(name: []const u8, n: u32, machine: []const u8) void {519    p("{s}{s}  last {d} lines  {s}\n\n", .{ hdr(), name, n, machine });520}521522// --- Store ---523524pub fn storeInfo(info: types.StoreInfo) void {525    p("{s}store\n\n", .{hdr()});526    p("   {s:<16}  {s}\n", .{ "total", info.total_size });527    p("   {s:<16}  {d} paths\n", .{ "live", info.live_paths });528    p("   {s:<16}  {s}{d} paths{s}   {s}run nina clean{s}\n", .{ "reclaimable", c(DIM), info.reclaimable_paths, c(RESET), c(CYAN), c(RESET) });529}530531// --- Channel ---532533pub fn channelListHeader(machine: []const u8) void {534    p("{s}channels  {s}\n\n", .{ hdr(), machine });535}536537pub fn channelRow(ch: types.ChannelInfo) void {538    p("   {s:<16}  {s}\n", .{ ch.name, ch.url });539}540541// --- Flake ---542543pub fn flakeUpdateStart() void {544    p("{s}updating inputs\n\n", .{hdr()});545}546547pub fn flakeInput(input: types.FlakeInput) void {548    if (input.changed) {549        const old = if (input.old_rev) |r| r[0..@min(7, r.len)] else "?";550        const new = if (input.new_rev) |r| r[0..@min(7, r.len)] else "?";551        p("   {s:<20}  {s} -> {s}\n", .{ input.name, old, new });552    } else {553        p("   {s:<20}  {s}no change{s}\n", .{ input.name, c(DIM), c(RESET) });554    }555}556557pub fn flakeLockWritten() void {558    p("\n{s}flake.lock written\n", .{hdr()});559}560561pub fn flakeValid() void {562    p("{s}{s}valid{s}\n", .{ hdr(), c(GREEN), c(RESET) });563}564565pub fn flakeCheckStart() void {566    p("{s}checking flake\n", .{hdr()});567}568569// --- Profile ---570571pub fn profileListHeader() void {572    p("{s}profile packages\n\n", .{hdr()});573}574575pub fn profileRow(attr: []const u8, pkg_version: []const u8, description: []const u8) void {576    p("   {s:<24}  {s:<12}  {s}\n", .{ attr, pkg_version, description });577}578579// --- Install / Remove / Try ---580581// Typo help for install: the query matched nothing, so suggest the closest real582// package name (pink) and let the caller confirm.583pub fn didYouMean(query: []const u8, suggestion: []const u8) void {584    p("{s}{s}'{s}' not found{s}  —  did you mean {s}{s}{s}?\n", .{ hdr(), c(DIM), query, c(RESET), c(PINK), suggestion, c(RESET) });585}586587pub fn installStart(pkg: []const u8, path: types.InstallPath) void {588    const path_str = switch (path) {589        .profile => "profile",590        .system => "system",591    };592    p("{s}installing {s}{s}{s}  {s}\n", .{ hdr(), c(PINK), pkg, c(RESET), path_str });593}594595pub fn installDone(pkg: []const u8) void {596    p("{s}{s}{s}{s} installed  {s}available now{s}\n", .{ hdr(), c(PINK), pkg, c(RESET), c(DIM), c(RESET) });597}598599pub fn removeStart(pkg: []const u8) void {600    p("{s}removing {s}{s}{s}\n", .{ hdr(), c(PINK), pkg, c(RESET) });601}602603// Plain-language health summary. No kaomoji, no hearts — just the facts.604pub fn mood(machine: []const u8, state: []const u8, gen: u32, age: []const u8, size: []const u8) void {605    const healthy = std.mem.eql(u8, state, "running");606    const verdict = if (healthy) "all good" else state;607    const color = if (healthy) GREEN else YELLOW;608    const face = if (healthy) KAO_HAPPY else "";609    p("{s}{s}{s}  {s}{s}{s}\n", .{ face, hdr(), machine, c(color), verdict, c(RESET) });610    if (age.len > 0 or size.len > 0) {611        p("   generation {d}, last applied {s}, {s} system closure\n", .{ gen, age, size });612    } else {613        p("   generation {d}\n", .{gen});614    }615}616617pub fn installEditorPrompt(pkg: []const u8, config_path: []const u8, line: u32, editor: []const u8) void {618    p("{s}opening {s}  add {s}{s}{s} to systemPackages\n", .{ hdr(), config_path, c(PINK), pkg, c(RESET) });619    const cmd = std.fmt.allocPrint(std.heap.page_allocator, "{s} {s} +{d}", .{ editor, config_path, line }) catch editor;620    printSubstep("{s}", .{cmd});621    p("\n   {s}save and close when done{s}\n\n", .{ c(DIM), c(RESET) });622}623624pub fn installSelectPrompt(pkg: []const u8, pkg_version: []const u8) void {625    p("{s}{s}{s}{s}  {s}\n\n", .{ hdr(), c(PINK), pkg, c(RESET), pkg_version });626    p("   [i] profile install    {s}instant  no rebuild{s}\n", .{ c(DIM), c(RESET) });627    p("   [s] system install     {s}opens editor  requires apply{s}\n", .{ c(DIM), c(RESET) });628    p("   [t] try now            {s}exits when done{s}\n\n", .{ c(DIM), c(RESET) });629    p("   > ", .{});630    flush();631}632633pub fn tryStart(pkg: []const u8) void {634    p("{s}trying {s}{s}{s}  exit when done\n", .{ hdr(), c(PINK), pkg, c(RESET) });635}636637pub fn tryExitHint() void {638    p("   {s}-> press Ctrl+C or type 'exit' to return{s}\n", .{ c(DIM), c(RESET) });639}640641pub fn tryDone() void {642    p("{s}{s}back\n", .{ KAO_SLEEPY, hdr() });643}644645// --- List ---646647pub fn listHeader(machine: []const u8) void {648    p("{s}packages  {s}\n\n", .{ hdr(), machine });649}650651pub fn listSection(title: []const u8) void {652    p("   {s}{s}{s}\n", .{ c(DIM), title, c(RESET) });653}654655// Padded name so the version column lines up into a clean two-column table.656pub fn listPkg(name: []const u8, pkg_version: []const u8) void {657    p("   {s}{s:<16}{s}  {s}{s}{s}\n", .{ c(PINK), name, c(RESET), c(DIM), pkg_version, c(RESET) });658}659660pub fn blankLine() void {661    p("\n", .{});662}663664// --- Hello ---665666pub fn hello(machines: []const types.Machine) void {667    p("{s}{s}nina\n\n", .{ KAO_FACE, hdr() });668    for (machines) |m| {669        const kind = if (m.local) "local" else "ssh";670        const detail = if (m.local) "default" else m.host orelse "";671        p("   {s}{s}{s}   {s}   {s}\n", .{ c(DIM), m.name, c(RESET), kind, detail });672    }673    p("\n", .{});674    const quick = [_][2][]const u8{675        .{ "apply", "rebuild and switch" },676        .{ "search <q>", "find packages" },677        .{ "install <pkg>", "add to profile or system" },678        .{ "status", "machine health" },679        .{ "back", "roll back one generation" },680        .{ "home apply", "apply home config" },681        .{ "home back", "roll back home config" },682        .{ "home history", "list home generations" },683        .{ "home check", "validate home config" },684        .{ "home diff", "compare home generations" },685        .{ "home packages", "list managed packages" },686    };687    for (quick) |cmd| {688        p("   {s:<16}  {s}{s}{s}\n", .{ cmd[0], c(DIM), cmd[1], c(RESET) });689    }690    p("\n", .{});691}692693// --- Help ---694695pub fn help() void {696    p("{s}nina  {s}NixOS Intuitive Navigation Assistant by Asha Software{s}\n\n", .{ hdr(), c(DIM), c(RESET) });697    const cmds = [_][2][]const u8{698        .{ "apply", "rebuild and switch" },699        .{ "back", "roll back one generation" },700        .{ "go <n>", "switch to generation n" },701        .{ "history", "list all generations" },702        .{ "clean", "remove old generations" },703        .{ "search <q>", "find packages" },704        .{ "install <pkg>", "add to profile or system" },705        .{ "remove <pkg>", "remove from profile or system" },706        .{ "try <pkg>", "test without installing" },707        .{ "list", "show installed packages" },708        .{ "edit", "open configuration.nix" },709        .{ "check", "validate config" },710        .{ "diff", "changes between generations" },711        .{ "status", "machine health" },712        .{ "update", "refresh channels" },713        .{ "upgrade", "update and rebuild" },714        .{ "log", "operation history" },715        .{ "doctor", "diagnose issues" },716        .{ "mood", "plain-language health" },717        .{ "develop", "enter dev shell" },718        .{ "flake", "flake management" },719        .{ "build", "build a package" },720        .{ "run", "run without installing" },721        .{ "service", "manage services" },722        .{ "store", "nix store tools" },723        .{ "channel", "manage channels" },724        .{ "profile", "user profile packages" },725        .{ "home", "home manager commands (apply/back/history/edit/check/diff/packages)" },726        .{ "info", "system information" },727        .{ "boot", "boot entries" },728        .{ "fmt", "format configuration.nix" },729        .{ "repl", "nix repl with nixpkgs" },730        .{ "option <q>", "search nixos options" },731        .{ "pkg", "inspect packages" },732        .{ "why <pkg>", "what pulled a package in" },733        .{ "pin", "pin flake inputs" },734        .{ "hash", "compute nix hash" },735        .{ "fetch", "fetch and hash a url" },736        .{ "goodbye", "uninstall nina" },737        .{ "hello", "list machines" },738        .{ "help", "this message" },739    };740    for (cmds) |cmd| {741        p("   {s:<18}  {s}{s}{s}\n", .{ cmd[0], c(DIM), cmd[1], c(RESET) });742    }743    p("\n   {s}flags: --on <machine>  --dry  --check  --no-apply  --last <n>  --all  --json  --version{s}\n", .{ c(DIM), c(RESET) });744}745746// Render a grouped command's subcommand list, shown when the group is invoked747// with no subcommand or an explicit `help`. Rows are {invocation, description}.748pub fn subcommandHelp(group: []const u8, rows: []const [2][]const u8, footer: ?[]const u8) void {749    p("{s}{s} subcommands\n\n", .{ hdr(), group });750    for (rows) |row| {751        p("   {s:<16}  {s}{s}{s}\n", .{ row[0], c(DIM), row[1], c(RESET) });752    }753    if (footer) |f| p("\n   {s}{s}{s}\n", .{ c(DIM), f, c(RESET) });754    p("\n   nina {s} help  {s}for this message{s}\n", .{ group, c(DIM), c(RESET) });755}756757pub fn version() void {758    p("{s}nina  v{s}  zig 0.16  zero dependencies\n", .{ hdr(), nina_version.VERSION });759}760761// --- Search (text output before TUI) ---762763pub fn searchResult(pkg: types.NixPackage) void {764    p("   {s}{s}{s}   {s}{s}{s}   {s}\n", .{ c(PINK), pkg.pname, c(RESET), c(DIM), pkg.version, c(RESET), pkg.description });765}766767pub fn searchHeader(query: []const u8, count: usize) void {768    p("{s}search nixpkgs {s}  {s}{d} results{s}\n\n", .{ hdr(), query, c(DIM), count, c(RESET) });769}770771// --- Gen commands ---772773pub fn genCurrent(n: u32) void {774    p("{d}\n", .{n});775}776777pub fn done() void {778    p("{s}done\n", .{hdr()});779}780781pub fn runStart(pkg: []const u8) void {782    p("{s}running {s}{s}{s}\n", .{ hdr(), c(PINK), pkg, c(RESET) });783}784785pub fn buildStart(attr: []const u8) void {786    p("{s}building {s}\n", .{ hdr(), attr });787}788789pub fn buildDone() void {790    p("{s}done\n", .{hdr()});791}792793// --- Self-update (nina update) ---794795pub fn updateSelfStart() void {796    p("{s}{s}checking for updates\n", .{ KAO_READY, hdr() });797}798799pub fn updateSelfCurrent(ver: []const u8) void {800    p("{s}{s}nina {s} is up to date{s}\n", .{ hdr(), c(GREEN), ver, c(RESET) });801}802803pub fn updateSelfAvailable(current: []const u8, latest: []const u8) void {804    p("{s}update available\n", .{hdr()});805    p("{s}current  {s}{s}{s}\n", .{ step(), c(DIM), current, c(RESET) });806    p("{s}latest   {s}{s}{s}{s}\n", .{ step(), c(BOLD), c(GREEN), latest, c(RESET) });807}808809fn releaseNotesHeading(line: []const u8) []const u8 {810    var i: usize = 0;811    while (i < line.len and line[i] == '#') : (i += 1) {}812    return std.mem.trim(u8, line[i..], " \t");813}814815fn releaseNotesBullet(line: []const u8) ?[]const u8 {816    if (line.len < 2) return null;817    const marker = line[0];818    if ((marker == '-' or marker == '*' or marker == '+') and line[1] == ' ') return line[2..];819    if (std.ascii.isDigit(marker)) {820        var i: usize = 1;821        while (i < line.len and std.ascii.isDigit(line[i])) : (i += 1) {}822        if (i + 1 < line.len and line[i] == '.' and line[i + 1] == ' ') return line[i + 2 ..];823    }824    return null;825}826827pub fn updateSelfReleaseNotes(notes: []const u8) void {828    const trimmed = std.mem.trim(u8, notes, " \t\r\n");829    if (trimmed.len == 0) return;830831    p("{s}changelog\n", .{hdr()});832    var lines = std.mem.splitScalar(u8, trimmed, '\n');833    while (lines.next()) |raw_line| {834        const line = if (raw_line.len > 0 and raw_line[raw_line.len - 1] == '\r') raw_line[0 .. raw_line.len - 1] else raw_line;835        const text = std.mem.trim(u8, line, " \t");836        if (text.len == 0) {837            p("\n", .{});838            continue;839        }840        if (text[0] == '#') {841            const title = releaseNotesHeading(text);842            if (title.len == 0) continue;843            p("   {s}{s}{s}{s}\n", .{ c(BOLD), c(CYAN), title, c(RESET) });844            continue;845        }846        if (releaseNotesBullet(text)) |item| {847            p("   {s}- {s}{s}\n", .{ c(CYAN), item, c(RESET) });848            continue;849        }850        p("   {s}\n", .{text});851    }852}853854pub fn updateSelfDownloading(ver: []const u8, platform: []const u8) void {855    p("{s}downloading nina {s} for {s}\n", .{ step(), ver, platform });856}857858pub fn updateSelfVerifying() void {859    p("{s}verifying checksum\n", .{step()});860}861862pub fn updateSelfInstalling(install_path: []const u8) void {863    p("{s}installing to {s}\n", .{ step(), install_path });864}865866pub fn updateSelfDone(old_ver: []const u8, new_ver: []const u8) void {867    p("{s}updated  {s} {s}→{s} {s}\n", .{ hdr(), old_ver, c(DIM), c(RESET), new_ver });868}869870pub fn updateSelfNoPlatform(platform: []const u8) void {871    p("{s}no pre-built binary for {s}\n", .{ hdr(), platform });872    p("{s}check kepr.uk/nina/releases for available platforms\n", .{step()});873}874875pub fn updateSelfNetworkError() void {876    p("{s}{s}\n", .{ if (color_enabled) WARN_C else WARN_P, "could not reach kepr.uk — check your connection" });877}878879pub fn updateSelfChecksumFailed() void {880    p("{s}checksum mismatch — download may be corrupt\n", .{if (color_enabled) ERR_C else ERR_P});881    p("{s}try again or download manually from kepr.uk/nina/releases\n", .{step()});882}883884pub fn updateSelfNixManaged(new_ver: []const u8) void {885    p("{s}upgrading to {s}{s}{s} via nix profile\n", .{ step(), c(BOLD), new_ver, c(RESET) });886}887888pub fn updateSelfNixFailed() void {889    p("{s}nix profile upgrade failed\n", .{if (color_enabled) ERR_C else ERR_P});890    p("{s}try manually: nix profile upgrade '.*nina.*'\n", .{step()});891}892893pub fn updateSelfNotInProfile() void {894    p("{s}nina is in the nix store but not found as a profile element\n", .{hdr()});895    p("{s}reinstall via 'nix profile add' to enable self-update\n", .{step()});896}897898// --- Goodbye / uninstall ---899900pub fn goodbyeStart() void {901    p("{s}uninstalling nina\n", .{hdr()});902}903904pub fn goodbyeFile(path: []const u8) void {905    p("{s}will remove {s}\n", .{ step(), path });906}907908pub fn goodbyeNix() void {909    p("{s}will remove nina from nix profile\n", .{step()});910    p("{s}command: nix profile remove nina\n", .{step()});911}912913pub fn goodbyeDone() void {914    p("{s}goodbye! see kepr.uk/nina to reinstall\n", .{hdr()});915}916917pub fn goodbyeFailed(msg: []const u8) void {918    p("{s}{s}\n", .{ if (color_enabled) ERR_C else ERR_P, msg });919}920921// --- Setup ---922923pub fn setupCheck() void {924    p("{s}checking nix features\n", .{hdr()});925}926927pub fn setupFeatures(nix_command: bool, flakes: bool) void {928    p("{s}nix-command  {s}{s}{s}\n", .{929        step(),930        if (nix_command) c(GREEN) else "",931        if (nix_command) "enabled" else "not enabled",932        if (nix_command) c(RESET) else "",933    });934    p("{s}flakes       {s}{s}{s}\n", .{935        step(),936        if (flakes) c(GREEN) else "",937        if (flakes) "enabled" else "not enabled",938        if (flakes) c(RESET) else "",939    });940}941942pub fn setupAllSet() void {943    p("{s}all set\n", .{hdr()});944}945946// Printed once, before the first search, when the nixpkgs registry still points947// at a remote URL. Flush so it lands before `nix registry pin` and any results.948pub fn pinningRegistry() void {949    p("{s}pinning nixpkgs for fast local search...\n", .{hdr()});950    flush();951}952953// --- Plain (non-tty) search rendering ---954// Color-gated equivalents of the raw-ANSI TUI widget, for piped/scripted search.955// Using the gated header + c() keeps ANSI out of non-tty output (NO_COLOR / pipes).956957pub fn searchPlainHeader(mode_str: []const u8, query: []const u8, count: u64) void {958    p("{s}search {s} {s}  {s}{d} results{s}\n", .{ hdr(), mode_str, query, c(DIM), count, c(RESET) });959}960961pub fn searchPlainNoResults() void {962    p("   no results\n", .{});963}964965pub fn searchPlainPackage(pname: []const u8, pkg_version: []const u8, description: []const u8, unfree: bool) void {966    if (unfree) {967        p("   {s}   {s}{s}{s}   {s}unfree{s}   {s}\n", .{ pname, c(CYAN), pkg_version, c(RESET), c(YELLOW), c(RESET), description });968    } else {969        p("   {s}   {s}{s}{s}   {s}\n", .{ pname, c(CYAN), pkg_version, c(RESET), description });970    }971}972973pub fn searchPlainOption(name: []const u8, type_str: []const u8) void {974    p("   {s}   {s}{s}{s}\n", .{ name, c(DIM), type_str, c(RESET) });975}976977pub fn searchEmptyQuery() void {978    p("{s}search needs a query  {s}e.g. nina search firefox{s}\n", .{ hdr(), c(DIM), c(RESET) });979}980981pub fn setupEnabling() void {982    p("{s}enabling experimental features\n", .{hdr()});983}984985pub fn setupDone(path: []const u8) void {986    p("{s}wrote {s}\n", .{ step(), path });987    p("{s}done  open a new shell to pick up the change\n", .{hdr()});988}989990// --- NixOS setup (declarative configuration.nix) ---991992pub fn setupNixosOffer(features_line: []const u8, conf_path: []const u8) void {993    p("{s}on NixOS these go in your system config\n", .{hdr()});994    p("   nina can add this line to {s}{s}{s}:\n\n", .{ c(DIM), conf_path, c(RESET) });995    p("       {s}{s}{s}\n\n", .{ c(CYAN), features_line, c(RESET) });996}997998pub fn setupNixosWrote(conf_path: []const u8) void {999    p("{s}added the line to {s}  {s}(backup: {s}.nina-bak){s}\n", .{ step(), conf_path, c(DIM), conf_path, c(RESET) });1000    p("{s}now run {s}sudo nixos-rebuild switch{s} — then nina's ready\n", .{ hdr(), c(BOLD), c(RESET) });1001}10021003pub fn setupNixosManual(features_line: []const u8, conf_path: []const u8) void {1004    p("{s}no problem — add this line inside the {s}{{ }}{s} in {s}:\n\n", .{ hdr(), c(DIM), c(RESET), conf_path });1005    p("       {s}{s}{s}\n\n", .{ c(CYAN), features_line, c(RESET) });1006    p("   then run {s}sudo nixos-rebuild switch{s} — then nina's ready\n", .{ c(BOLD), c(RESET) });1007}10081009pub fn setupNixosNeedsRebuild(conf_path: []const u8) void {1010    p("{s}already declared in {s}\n", .{ hdr(), conf_path });1011    p("   just run {s}sudo nixos-rebuild switch{s} to activate it\n", .{ c(BOLD), c(RESET) });1012}10131014pub fn pinDone(input: []const u8, commit: []const u8) void {1015    p("{s}pinned {s} -> {s}\n", .{ hdr(), input, commit });1016}10171018pub fn unpinDone(input: []const u8) void {1019    p("{s}unpinned {s}\n", .{ hdr(), input });1020}10211022pub fn hashResult(hash: []const u8) void {1023    p("{s}\n", .{hash});1024}10251026pub fn fetchResult(hash: []const u8, url: []const u8) void {1027    _ = url;1028    p("{s}\n", .{hash});1029}10301031pub fn storeRepairStart() void {1032    p("{s}repairing store\n", .{hdr()});1033}10341035pub fn storeVerifyStart() void {1036    p("{s}verifying store\n", .{hdr()});1037}10381039pub fn storeGcDone(freed: []const u8) void {1040    p("{s}freed {s}\n", .{ hdr(), freed });1041}10421043pub fn storePath(path: []const u8) void {1044    p("{s}\n", .{path});1045}10461047pub fn pkgResult(key: []const u8, val: []const u8) void {1048    p("   {s:<16}  {s}\n", .{ key, val });1049}10501051pub fn channelDone() void {1052    p("{s}done\n", .{hdr()});1053}10541055pub fn flakeShowHeader(name: []const u8) void {1056    p("{s}{s}\n\n", .{ hdr(), name });1057}10581059pub fn flakeShowEntry(kind: []const u8, name: []const u8, desc: []const u8) void {1060    p("   {s:<12}  {s:<24}  {s}\n", .{ kind, name, desc });1061}10621063// --- Home Manager ---10641065pub fn homeNotInstalled() void {1066    p("{s}home manager not detected  {s}nothing to do{s}\n", .{ hdr(), c(DIM), c(RESET) });1067}10681069// HM is a NixOS/flake module — rebuilt by nixos-rebuild, not the standalone CLI.1070pub fn homeModuleManaged() void {1071    p("{s}home manager is managed by your system config\n", .{hdr()});1072    p("   {s}-> run {s}nina apply{s}{s} to rebuild both together{s}\n", .{ c(CYAN), c(BOLD), c(RESET), c(CYAN), c(RESET) });1073}10741075pub fn homeApplyStart(machine: []const u8) void {1076    p("{s}{s}applying home config  {s}\n", .{ KAO_COZY, hdr(), machine });1077}10781079pub fn homeApplyDone(gen: u32, elapsed_ms: u64) void {1080    const secs = @as(f64, @floatFromInt(elapsed_ms)) / 1000.0;1081    // gen 0 means the post-switch generation re-read failed — the switch itself1082    // succeeded, so report success without a misleading "generation 0".1083    if (gen == 0) {1084        if (elapsed_ms >= 1000) {1085            p("{s}done  {s}[{d:.1}s]{s}\n", .{ hdr(), c(DIM), secs, c(RESET) });1086        } else {1087            p("{s}done\n", .{hdr()});1088        }1089        return;1090    }1091    if (elapsed_ms >= 1000) {1092        p("{s}generation {s}{d}{s}  {s}[{d:.1}s]{s}\n", .{ hdr(), c(BOLD), gen, c(RESET), c(DIM), secs, c(RESET) });1093    } else {1094        p("{s}generation {s}{d}{s}\n", .{ hdr(), c(BOLD), gen, c(RESET) });1095    }1096}10971098// `home` was invoked against a remote machine. Detection + flake-ref are1099// local-only, so we don't act on a remote — point the user at the local run.1100pub fn homeLocalOnly(machine: []const u8) void {1101    p("{s}home manager commands run on the local machine only\n", .{hdr()});1102    p("   {s}-> '{s}' is remote; run nina home on that machine directly{s}\n", .{ c(DIM), machine, c(RESET) });1103}11041105pub fn homeApplyDry(machine: []const u8) void {1106    p("{s}home dry run  {s}\n", .{ hdr(), machine });1107}11081109pub fn homeApplyDryDone() void {1110    p("{s}{s}ok{s}  no changes applied\n", .{ hdr(), c(GREEN), c(RESET) });1111}11121113pub fn homeBackStart(machine: []const u8, from: u32, to: u32) void {1114    p("{s}rolling back home config  {s}  gen {d} -> gen {d}\n", .{ hdr(), machine, from, to });1115}11161117pub fn homeBackDone(n: u32) void {1118    p("{s}{s}done  gen {s}{d}{s}\n", .{ KAO_GENTLE, hdr(), c(BOLD), n, c(RESET) });1119}11201121pub fn homeHistoryHeader(machine: []const u8) void {1122    p("{s}home generations  {s}\n\n", .{ hdr(), machine });1123}11241125pub fn homeHistoryRow(number: u32, date: []const u8, time: []const u8, current: bool) void {1126    if (current) {1127        p("   {s}{d}{s}   {s}   {s}   {s}current{s}\n", .{ c(BOLD), number, c(RESET), date, time, c(BOLD), c(RESET) });1128    } else {1129        p("   {s}{d}   {s}   {s}{s}\n", .{ c(DIM), number, date, time, c(RESET) });1130    }1131}11321133pub fn homeEditOpen(path: []const u8, editor: []const u8) void {1134    p("{s}opening {s}\n", .{ hdr(), path });1135    printSubstep("{s}", .{editor});1136}11371138pub fn homeCheckStart(machine: []const u8) void {1139    p("{s}checking home config  {s}\n", .{ hdr(), machine });1140}11411142pub fn homeCheckOk() void {1143    p("{s}{s}ok{s}\n", .{ hdr(), c(GREEN), c(RESET) });1144}11451146pub fn homeDiffHeader(a: u32, b: u32, machine: []const u8) void {1147    p("{s}home gen {d} -> gen {d}  {s}\n\n", .{ hdr(), a, b, machine });1148}11491150pub fn homeNothingToDiff() void {1151    p("{s}only one home generation — nothing to diff yet\n", .{hdr()});1152}11531154pub fn homePackagesHeader(machine: []const u8) void {1155    p("{s}home packages  {s}\n\n", .{ hdr(), machine });1156}11571158// --- First-run wizard ---11591160pub fn firstRunBanner() void {1161    p("{s}{s}nina \u{2014} first run\n\n", .{ KAO_FACE, hdr() });1162}11631164pub fn firstRunNoConfig() void {1165    p("   no config found. let me get set up.\n\n", .{});1166}11671168// Print a prompt line and read the user's answer. Returns the default if the1169// user presses Enter without typing anything. buf must be at least 256 bytes.1170// Returns a slice into buf (or default if empty input).1171pub fn firstRunPrompt(label: []const u8, default: []const u8, buf: []u8) []const u8 {1172    p("   {s:<14} {s}> {s}", .{ label, c(DIM), c(RESET) });1173    flush();1174    var i: usize = 0;1175    while (i < buf.len - 1) {1176        const n = std.posix.read(std.posix.STDIN_FILENO, buf[i .. i + 1]) catch break;1177        if (n == 0) break;1178        if (buf[i] == '\n') break;1179        i += 1;1180    }1181    const input = std.mem.trim(u8, buf[0..i], " \t\r");1182    if (input.len == 0) {1183        // Echo the default so the output shows what was chosen1184        p("{s}{s}{s}\n", .{ c(DIM), default, c(RESET) });1185        flush();1186        return default;1187    }1188    return input;1189}11901191pub fn firstRunScanning() void {1192    p("\n   {s}:: scanning for config...{s}\n", .{ c(DIM), c(RESET) });1193}11941195// Report what the scan found at /etc/nixos, noting flake vs channel.1196pub fn firstRunDetected(path: []const u8, is_flake: bool) void {1197    const kind = if (is_flake) "flake-based system" else "channel-based system";1198    p("   {s}-> found {s}{s}   {s}({s}){s}\n\n", .{ c(CYAN), path, c(RESET), c(DIM), kind, c(RESET) });1199}12001201pub fn firstRunNoneFound() void {1202    p("   {s}-> nothing found at /etc/nixos{s}\n\n", .{ c(DIM), c(RESET) });1203}12041205// Prompt with a pre-filled default shown in brackets. Empty input accepts the1206// default. When `detected` and a default is present, note that enter confirms.1207pub fn firstRunPromptDefault(label: []const u8, default: []const u8, detected: bool, buf: []u8) []const u8 {1208    if (default.len > 0) {1209        p("   {s:<14} {s}[{s}]{s} > ", .{ label, c(DIM), default, c(RESET) });1210        if (detected) p("{s}enter to confirm{s} ", .{ c(DIM), c(RESET) });1211    } else {1212        p("   {s:<14} {s}> {s}", .{ label, c(DIM), c(RESET) });1213    }1214    flush();1215    var i: usize = 0;1216    while (i < buf.len - 1) {1217        const n = std.posix.read(std.posix.STDIN_FILENO, buf[i .. i + 1]) catch break;1218        if (n == 0) break;1219        if (buf[i] == '\n') break;1220        i += 1;1221    }1222    const input = std.mem.trim(u8, buf[0..i], " \t\r");1223    if (input.len == 0) {1224        p("{s}{s}{s}\n", .{ c(DIM), default, c(RESET) });1225        flush();1226        return default;1227    }1228    return input;1229}12301231// Shown before channel operations on a flake-managed system, where nix-channel1232// commands generally don't apply.1233pub fn flakeChannelNote() void {1234    p("{s}{s}note: flake-based system — use {s}nina flake update{s}{s} to update inputs{s}\n", .{ hdr(), c(DIM), c(CYAN), c(RESET), c(DIM), c(RESET) });1235}12361237pub fn firstRunWritten(path: []const u8) void {1238    p("\n   {s}written to {s}{s}\n\n", .{ c(DIM), path, c(RESET) });1239}12401241pub fn firstRunSkipped() void {1242    p("\n   {s}skipping setup in non-interactive mode{s}\n", .{ c(DIM), c(RESET) });1243}