123const std = @import("std");4const types = @import("types.zig");5const nina_version = @import("version.zig");6const Io = std.Io;789const 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";1718192021const KAO_FACE = "(˶ᵔ ᵕ ᵔ˶) "; 22const KAO_COZY = "(っ˘ω˘ς) "; 23const KAO_EXCITED = "╰(*°▽°*)╯ "; 24const KAO_GENTLE = "( ˘ᵕ˘ ) "; 25const KAO_CONTENT = "( ´ ∀ ` ) "; 26const KAO_HAPPY = "( ´ ▽ ` ) "; 27const KAO_SLEEPY = "(˘ω˘ ) "; 28const KAO_SAD = "(;ω;) "; 293031pub const C_PINK = PINK;32pub const C_BOLD = BOLD;33pub const C_GREEN = GREEN;34pub const C_YELLOW = YELLOW;35pub const C_RED = RED;36pub const C_CYAN = CYAN;37pub const C_DIM = DIM;38pub const C_RESET = RESET;39pub const C_CLEAR_EOL = "\x1b[K";40pub const C_CURSOR_UP_FMT = "\x1b[{d}A";414243const HDR_C = PINK ++ ":: " ++ RESET;44const HDR_P = ":: ";45const STEP_C = " " ++ DIM ++ "-> " ++ RESET;46const STEP_P = " -> ";47const TEACH_C = " " ++ DIM ++ "= " ++ RESET;48const TEACH_P = " = ";49const ERR_C = PINK ++ ":: " ++ RED ++ "error:" ++ RESET ++ " ";50const ERR_P = ":: error: ";51const WARN_C = PINK ++ ":: " ++ YELLOW ++ "warning:" ++ RESET ++ " ";52const WARN_P = ":: warning: ";5354var _fw: Io.File.Writer = undefined;55var _w: *Io.Writer = undefined;56var color_enabled: bool = true;57var teach_enabled: bool = false;5859pub fn init(writer: *Io.Writer, io: std.Io, environ: *const std.process.Environ.Map, color_config: bool) void {60 _w = writer;61 color_enabled = color_config and62 (std.Io.File.stdout().isTty(io) catch false) and63 !environ.contains("NO_COLOR");64}6566pub fn setTeach(enabled: bool) void {67 teach_enabled = enabled;68}6970pub fn flush() void {71 _w.flush() catch {};72}7374fn c(code: []const u8) []const u8 {75 return if (color_enabled) code else "";76}7778fn hdr() []const u8 {79 return if (color_enabled) HDR_C else HDR_P;80}8182fn step() []const u8 {83 return if (color_enabled) STEP_C else STEP_P;84}8586fn teach_pfx() []const u8 {87 return if (color_enabled) TEACH_C else TEACH_P;88}899091pub fn raw(bytes: []const u8) void {92 _w.writeAll(bytes) catch {};93}949596pub fn p(comptime fmt: []const u8, args: anytype) void {97 _w.print(fmt, args) catch {};98}99100pub fn cursorUp(n: usize) void {101 if (n > 0) p("\x1b[{d}A", .{n});102}103104pub fn clearLine() void {105 p("\r\x1b[K", .{});106}107108109110pub fn printError(message: []const u8, detail: ?[]const u8, suggestion: ?[]const u8) void {111 p("{s}{s}\n", .{ if (color_enabled) ERR_C else ERR_P, message });112 if (detail) |d| p(" {s}{s}{s}\n", .{ c(DIM), d, c(RESET) });113 if (suggestion) |s| p(" {s}-> {s}{s}\n", .{ c(DIM), s, c(RESET) });114}115116117118119pub fn printSystemError(message: []const u8, detail: ?[]const u8, suggestion: ?[]const u8) void {120 p("{s}{s}{s}\n", .{ KAO_SAD, if (color_enabled) ERR_C else ERR_P, message });121 if (detail) |d| p(" {s}{s}{s}\n", .{ c(DIM), d, c(RESET) });122 if (suggestion) |s| p(" {s}-> {s}{s}\n", .{ c(DIM), s, c(RESET) });123}124125pub fn printWarning(message: []const u8) void {126 p("{s}{s}\n", .{ if (color_enabled) WARN_C else WARN_P, message });127}128129pub fn printTeach(cmd: []const u8) void {130 if (teach_enabled) p("{s}{s}{s}\n", .{ teach_pfx(), cmd, c(RESET) });131}132133pub fn printSubstep(comptime fmt: []const u8, args: anytype) void {134 p("{s}", .{step()});135 p(fmt, args);136 p("\n", .{});137}138139140141pub fn confirm(prompt: []const u8) bool {142 p(" {s}continue? [Y/n] ", .{prompt});143 flush();144 var buf: [64]u8 = undefined;145 var i: usize = 0;146 while (i < buf.len) {147 const n = std.posix.read(std.posix.STDIN_FILENO, buf[i .. i + 1]) catch break;148 if (n == 0) break;149 if (buf[i] == '\n') break;150 i += 1;151 }152 const input = std.mem.trim(u8, buf[0..i], " \t");153 if (input.len == 0) return true;154 return input[0] != 'n' and input[0] != 'N';155}156157158159pub fn applyStart(machine: []const u8) void {160 p("{s}{s}rebuilding {s}...\n", .{ KAO_COZY, hdr(), machine });161}162163164165166pub fn applyDone(gen: u32, elapsed_ms: u64, after_failure: bool) void {167 const face = if (after_failure) KAO_EXCITED else "";168 const secs = @as(f64, @floatFromInt(elapsed_ms)) / 1000.0;169 if (elapsed_ms >= 1000) {170 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) });171 } else {172 p("{s}{s}generation {s}{d}{s}\n", .{ face, hdr(), c(BOLD), gen, c(RESET) });173 }174}175176pub fn applyFailed(translated: []const u8) void {177 p("{s}build failed\n", .{if (color_enabled) ERR_C else ERR_P});178 if (translated.len > 0) p(" {s}{s}{s}\n", .{ c(DIM), translated, c(RESET) });179 p(" {s}-> nina doctor{s}\n", .{ c(DIM), c(RESET) });180}181182pub fn applyDry(machine: []const u8) void {183 p("{s}dry run {s}\n", .{ hdr(), machine });184}185186pub fn applyDryDone() void {187 p("{s}no changes applied\n", .{hdr()});188}189190191192pub fn checkStart(machine: []const u8) void {193 p("{s}checking {s}...\n", .{ hdr(), machine });194}195196pub fn checkOk() void {197 p("{s}{s}ok{s}\n", .{ hdr(), c(GREEN), c(RESET) });198}199200pub fn checkFailed(msg: []const u8) void {201 p("{s}config invalid\n", .{if (color_enabled) ERR_C else ERR_P});202 if (msg.len > 0) p(" {s}{s}{s}\n", .{ c(DIM), msg, c(RESET) });203}204205206207pub fn backStart(machine: []const u8, from: u32, to: u32) void {208 p("{s}rolling back {s} gen {d} -> gen {d}\n", .{ hdr(), machine, from, to });209}210211pub fn goStart(machine: []const u8, current: u32, target: u32) void {212 p("{s}switching {s} gen {d} -> gen {d}\n", .{ hdr(), machine, current, target });213}214215pub fn generationDone(n: u32) void {216 p("{s}done gen {s}{d}{s}\n", .{ hdr(), c(BOLD), n, c(RESET) });217}218219220221pub fn backDone(n: u32) void {222 p("{s}{s}done gen {s}{d}{s}\n", .{ KAO_GENTLE, hdr(), c(BOLD), n, c(RESET) });223}224225226227pub fn historyHeader(machine: []const u8) void {228 p("{s}generations {s}\n\n", .{ hdr(), machine });229}230231pub fn historyRow(gen: types.GenerationInfo) void {232 if (gen.current) {233 p(" {s}{d}{s} {s} {s} {s}current{s}\n", .{ c(BOLD), gen.number, c(RESET), gen.date, gen.time, c(BOLD), c(RESET) });234 } else {235 p(" {s}{d} {s} {s}{s}\n", .{ c(DIM), gen.number, gen.date, gen.time, c(RESET) });236 }237}238239240241pub fn cleanStart(machine: []const u8, keep: u32, total: u32) void {242 p("{s}cleaning {s} keeping {d} of {d}\n", .{ hdr(), machine, keep, total });243}244245pub fn cleanDone(freed: []const u8) void {246 p("{s}{s}freed {s}\n", .{ KAO_CONTENT, hdr(), freed });247}248249250251pub fn statusHeader() void {252 p("{s}status\n\n", .{hdr()});253}254255pub fn statusRow(machine: []const u8, gen: u32, time: []const u8, size: []const u8, ok: bool) void {256 if (ok) {257 p(" {s}{s} gen {d} {s} {s}{s}\n", .{ c(DIM), machine, gen, time, size, c(RESET) });258 } else {259 p(" {s}{s} {s}unreachable{s}\n", .{ c(RED), machine, "", c(RESET) });260 }261}262263264265pub fn diffHeader(a: u32, b: u32, machine: []const u8) void {266 p("{s}gen {d} -> gen {d} {s}\n\n", .{ hdr(), a, b, machine });267}268269pub fn diffRow(entry: types.DiffEntry) void {270 switch (entry.op) {271 .add => p(" {s}+{s} {s} {s}\n", .{ c(GREEN), c(RESET), entry.package, entry.new_version orelse "" }),272 .remove => p(" {s}-{s} {s} {s}\n", .{ c(RED), c(RESET), entry.package, entry.old_version orelse "" }),273 .change => p(" {s}^{s} {s} {s} -> {s}\n", .{ c(CYAN), c(RESET), entry.package, entry.old_version orelse "", entry.new_version orelse "" }),274 }275}276277278279pub fn doctorHeader(machine: []const u8) void {280 p("{s}diagnosing {s}\n\n", .{ hdr(), machine });281}282283pub fn doctorRow(check: types.DoctorCheck) void {284 const status_str = switch (check.status) {285 .ok => if (color_enabled) GREEN ++ "ok" ++ RESET else "ok",286 .warn => if (color_enabled) YELLOW ++ "warn" ++ RESET else "warn",287 .fail => if (color_enabled) RED ++ "fail" ++ RESET else "fail",288 };289 const note_str = check.note orelse "";290 p(" {s:<16} {s} {s}\n", .{ check.name, status_str, note_str });291}292293pub fn doctorSummary(warnings: u32, failures: u32) void {294 if (failures > 0) {295 p("{s}{d} problems\n", .{ hdr(), failures });296 } else if (warnings > 0) {297 p("{s}{d} warnings\n", .{ hdr(), warnings });298 } else {299 p("{s}{s}{s}all good{s}\n", .{ KAO_HAPPY, hdr(), c(GREEN), c(RESET) });300 }301}302303304305pub fn updateStart(machine: []const u8) void {306 p("{s}updating channels {s}\n\n", .{ hdr(), machine });307}308309pub fn updateChannel(name: []const u8, old: ?[]const u8, new: ?[]const u8) void {310 if (old != null and new != null and !std.mem.eql(u8, old.?, new.?)) {311 p(" {s} {s} -> {s}\n", .{ name, old.?, new.? });312 } else {313 p(" {s} {s}no change{s}\n", .{ name, c(DIM), c(RESET) });314 }315}316317pub fn updateDone() void {318 p("\n{s}done\n", .{hdr()});319}320321322323pub fn upgradeStart(machine: []const u8) void {324 p("{s}upgrading {s}\n", .{ hdr(), machine });325}326327328329pub fn logHeader(machine: []const u8) void {330 p("{s}history {s}\n\n", .{ hdr(), machine });331}332333pub fn logRow(date: []const u8, time: []const u8, action: []const u8, detail: []const u8) void {334 p(" {s} {s} {s:<12} {s}\n", .{ date, time, action, detail });335}336337338339pub fn editOpen(path: []const u8, editor: []const u8) void {340 p("{s}opening {s}\n", .{ hdr(), path });341 printSubstep("{s}", .{editor});342 p("\n {s}run nina check to validate before applying{s}\n", .{ c(DIM), c(RESET) });343}344345346347pub fn fmtStart(path: []const u8) void {348 p("{s}formatting {s}\n", .{ hdr(), path });349}350351pub fn fmtDone() void {352 p("{s}done\n", .{hdr()});353}354355pub fn fmtNeedsFormat() void {356 p("{s}needs formatting {s}run nina fmt to fix{s}\n", .{ hdr(), c(DIM), c(RESET) });357}358359360361pub fn replStart() void {362 p("{s}nix repl {s}nixpkgs loaded{s} :q to exit\n", .{ hdr(), c(DIM), c(RESET) });363}364365366367pub fn developStart(pkgs: []const []const u8) void {368 p("{s}entering dev shell\n\n ", .{hdr()});369 for (pkgs, 0..) |pkg, i| {370 if (i > 0) p(" ", .{});371 p("{s}", .{pkg});372 }373 p("\n\n {s}exit to return{s}\n\n", .{ c(DIM), c(RESET) });374}375376pub fn developDone() void {377 p("{s}{s}back\n", .{ KAO_SLEEPY, hdr() });378}379380381382pub fn infoHeader(machine: []const u8) void {383 p("{s}{s}\n\n", .{ hdr(), machine });384}385386pub fn infoRow(key: []const u8, val: []const u8) void {387 p(" {s:<12} {s}\n", .{ key, val });388}389390391392pub fn bootHeader(machine: []const u8) void {393 p("{s}boot entries {s}\n\n", .{ hdr(), machine });394}395396pub fn bootEntry(entry: types.BootEntry, idx: usize) void {397 if (entry.current) {398 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) });399 } else {400 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) });401 }402 _ = idx;403}404405406407pub fn serviceListHeader(machine: []const u8) void {408 p("{s}services {s}\n\n", .{ hdr(), machine });409}410411pub fn serviceRow(svc: types.ServiceInfo) void {412 const state_str = switch (svc.state) {413 .active => if (color_enabled) GREEN ++ "active" ++ RESET else "active",414 .failed => if (color_enabled) RED ++ "failed" ++ RESET else "failed",415 .inactive => "inactive",416 .unknown => "unknown",417 };418 const uptime = svc.uptime orelse "";419 p(" {s:<24} {s:<14} {s}\n", .{ svc.name, state_str, uptime });420}421422pub fn serviceVerb(verb: []const u8, name: []const u8, machine: []const u8) void {423 p("{s}{s} {s} {s}\n", .{ hdr(), verb, name, machine });424}425426pub fn serviceDone() void {427 p("{s}done\n", .{hdr()});428}429430pub fn serviceLogsHeader(name: []const u8, n: u32, machine: []const u8) void {431 p("{s}{s} last {d} lines {s}\n\n", .{ hdr(), name, n, machine });432}433434435436pub fn storeInfo(info: types.StoreInfo) void {437 p("{s}store\n\n", .{hdr()});438 p(" {s:<16} {s}\n", .{ "total", info.total_size });439 p(" {s:<16} {d} paths\n", .{ "live", info.live_paths });440 p(" {s:<16} {s}{d} paths{s} run nina clean\n", .{ "reclaimable", c(DIM), info.reclaimable_paths, c(RESET) });441}442443444445pub fn channelListHeader(machine: []const u8) void {446 p("{s}channels {s}\n\n", .{ hdr(), machine });447}448449pub fn channelRow(ch: types.ChannelInfo) void {450 p(" {s:<16} {s}\n", .{ ch.name, ch.url });451}452453454455pub fn flakeUpdateStart() void {456 p("{s}updating inputs\n\n", .{hdr()});457}458459pub fn flakeInput(input: types.FlakeInput) void {460 if (input.changed) {461 const old = if (input.old_rev) |r| r[0..@min(7, r.len)] else "?";462 const new = if (input.new_rev) |r| r[0..@min(7, r.len)] else "?";463 p(" {s:<20} {s} -> {s}\n", .{ input.name, old, new });464 } else {465 p(" {s:<20} {s}no change{s}\n", .{ input.name, c(DIM), c(RESET) });466 }467}468469pub fn flakeLockWritten() void {470 p("\n{s}flake.lock written\n", .{hdr()});471}472473pub fn flakeValid() void {474 p("{s}{s}valid{s}\n", .{ hdr(), c(GREEN), c(RESET) });475}476477pub fn flakeCheckStart() void {478 p("{s}checking flake\n", .{hdr()});479}480481482483pub fn profileListHeader() void {484 p("{s}profile packages\n\n", .{hdr()});485}486487pub fn profileRow(attr: []const u8, pkg_version: []const u8, description: []const u8) void {488 p(" {s:<24} {s:<12} {s}\n", .{ attr, pkg_version, description });489}490491492493pub fn installStart(pkg: []const u8, path: types.InstallPath) void {494 const path_str = switch (path) {495 .profile => "profile",496 .system => "system",497 };498 p("{s}installing {s}{s}{s} {s}\n", .{ hdr(), c(PINK), pkg, c(RESET), path_str });499}500501pub fn installDone(pkg: []const u8) void {502 p("{s}{s}{s}{s} installed {s}available now{s}\n", .{ hdr(), c(PINK), pkg, c(RESET), c(DIM), c(RESET) });503}504505pub fn removeStart(pkg: []const u8) void {506 p("{s}removing {s}{s}{s}\n", .{ hdr(), c(PINK), pkg, c(RESET) });507}508509510pub fn mood(machine: []const u8, state: []const u8, gen: u32, age: []const u8, size: []const u8) void {511 const healthy = std.mem.eql(u8, state, "running");512 const verdict = if (healthy) "all good" else state;513 const color = if (healthy) GREEN else YELLOW;514 const face = if (healthy) KAO_HAPPY else "";515 p("{s}{s}{s} {s}{s}{s}\n", .{ face, hdr(), machine, c(color), verdict, c(RESET) });516 if (age.len > 0 or size.len > 0) {517 p(" generation {d}, last applied {s}, {s} system closure\n", .{ gen, age, size });518 } else {519 p(" generation {d}\n", .{gen});520 }521}522523pub fn installEditorPrompt(pkg: []const u8, config_path: []const u8, line: u32, editor: []const u8) void {524 p("{s}opening {s} add {s}{s}{s} to systemPackages\n", .{ hdr(), config_path, c(PINK), pkg, c(RESET) });525 const cmd = std.fmt.allocPrint(std.heap.page_allocator, "{s} {s} +{d}", .{ editor, config_path, line }) catch editor;526 printSubstep("{s}", .{cmd});527 p("\n {s}save and close when done{s}\n\n", .{ c(DIM), c(RESET) });528}529530pub fn installSelectPrompt(pkg: []const u8, pkg_version: []const u8) void {531 p("{s}{s}{s}{s} {s}\n\n", .{ hdr(), c(PINK), pkg, c(RESET), pkg_version });532 p(" [i] profile install {s}instant no rebuild{s}\n", .{ c(DIM), c(RESET) });533 p(" [s] system install {s}opens editor requires apply{s}\n", .{ c(DIM), c(RESET) });534 p(" [t] try now {s}exits when done{s}\n\n", .{ c(DIM), c(RESET) });535 p(" > ", .{});536 flush();537}538539pub fn tryStart(pkg: []const u8) void {540 p("{s}trying {s}{s}{s} exit when done\n", .{ hdr(), c(PINK), pkg, c(RESET) });541}542543pub fn tryDone() void {544 p("{s}{s}back\n", .{ KAO_SLEEPY, hdr() });545}546547548549pub fn listHeader() void {550 p("{s}installed packages\n\n", .{hdr()});551}552553pub fn listSection(title: []const u8) void {554 p(" {s}{s}{s}\n", .{ c(DIM), title, c(RESET) });555}556557pub fn listPkg(name: []const u8, pkg_version: []const u8) void {558 p(" {s}{s}{s} {s}{s}{s}\n", .{ c(PINK), name, c(RESET), c(DIM), pkg_version, c(RESET) });559}560561562563pub fn hello(machines: []const types.Machine) void {564 p("{s}{s}nina\n\n", .{ KAO_FACE, hdr() });565 for (machines) |m| {566 const kind = if (m.local) "local" else "ssh";567 const detail = if (m.local) "default" else m.host orelse "";568 p(" {s}{s}{s} {s} {s}\n", .{ c(DIM), m.name, c(RESET), kind, detail });569 }570 p("\n", .{});571 const quick = [_][2][]const u8{572 .{ "apply", "rebuild and switch" },573 .{ "search <q>", "find packages" },574 .{ "install <pkg>", "add to profile or system" },575 .{ "status", "machine health" },576 .{ "back", "roll back one generation" },577 .{ "update", "refresh channels" },578 };579 for (quick) |cmd| {580 p(" {s:<16} {s}{s}{s}\n", .{ cmd[0], c(DIM), cmd[1], c(RESET) });581 }582 p("\n", .{});583}584585586587pub fn help() void {588 p("{s}nina {s}nixos helper{s}\n\n", .{ hdr(), c(DIM), c(RESET) });589 const cmds = [_][2][]const u8{590 .{ "apply", "rebuild and switch" },591 .{ "back", "roll back one generation" },592 .{ "go <n>", "switch to generation n" },593 .{ "history", "list all generations" },594 .{ "clean", "remove old generations" },595 .{ "search <q>", "find packages" },596 .{ "install <pkg>", "add to profile or system" },597 .{ "remove <pkg>", "remove from profile or system" },598 .{ "try <pkg>", "test without installing" },599 .{ "list", "show installed packages" },600 .{ "edit", "open configuration.nix" },601 .{ "check", "validate config" },602 .{ "diff", "changes between generations" },603 .{ "status", "machine health" },604 .{ "update", "refresh channels" },605 .{ "upgrade", "update and rebuild" },606 .{ "log", "operation history" },607 .{ "doctor", "diagnose issues" },608 .{ "mood", "plain-language health" },609 .{ "develop", "enter dev shell" },610 .{ "flake", "flake management" },611 .{ "build", "build a package" },612 .{ "run", "run without installing" },613 .{ "service", "manage services" },614 .{ "store", "nix store tools" },615 .{ "channel", "manage channels" },616 .{ "profile", "user profile packages" },617 .{ "info", "system information" },618 .{ "boot", "boot entries" },619 .{ "fmt", "format configuration.nix" },620 .{ "repl", "nix repl with nixpkgs" },621 .{ "option <q>", "search nixos options" },622 .{ "pkg", "inspect packages" },623 .{ "pin", "pin flake inputs" },624 .{ "hash", "compute nix hash" },625 .{ "fetch", "fetch and hash a url" },626 .{ "goodbye", "uninstall nina" },627 .{ "hello", "list machines" },628 .{ "help", "this message" },629 };630 for (cmds) |cmd| {631 p(" {s:<18} {s}{s}{s}\n", .{ cmd[0], c(DIM), cmd[1], c(RESET) });632 }633 p("\n {s}flags: --on <machine> --dry --check --no-apply --last <n> --all --json{s}\n", .{ c(DIM), c(RESET) });634}635636pub fn version() void {637 p("{s}nina v{s} zig 0.16 zero dependencies\n", .{ hdr(), nina_version.VERSION });638}639640641642pub fn searchResult(pkg: types.NixPackage) void {643 p(" {s}{s}{s} {s}{s}{s} {s}\n", .{ c(PINK), pkg.pname, c(RESET), c(DIM), pkg.version, c(RESET), pkg.description });644}645646pub fn searchHeader(query: []const u8, count: usize) void {647 p("{s}search nixpkgs {s} {s}{d} results{s}\n\n", .{ hdr(), query, c(DIM), count, c(RESET) });648}649650651652pub fn genCurrent(n: u32) void {653 p("{d}\n", .{n});654}655656pub fn done() void {657 p("{s}done\n", .{hdr()});658}659660pub fn runStart(pkg: []const u8) void {661 p("{s}running {s}{s}{s}\n", .{ hdr(), c(PINK), pkg, c(RESET) });662}663664pub fn buildStart(attr: []const u8) void {665 p("{s}building {s}\n", .{ hdr(), attr });666}667668pub fn buildDone() void {669 p("{s}done\n", .{hdr()});670}671672673674pub fn updateSelfStart() void {675 p("{s}checking for updates\n", .{hdr()});676}677678pub fn updateSelfCurrent(ver: []const u8) void {679 p("{s}{s}nina {s} is up to date{s}\n", .{ hdr(), c(GREEN), ver, c(RESET) });680}681682pub fn updateSelfAvailable(current: []const u8, latest: []const u8) void {683 p("{s}current {s}\n", .{ step(), current });684 p("{s}latest {s}{s}{s}\n", .{ step(), c(BOLD), latest, c(RESET) });685}686687pub fn updateSelfDownloading(ver: []const u8, platform: []const u8) void {688 p("{s}downloading nina {s} for {s}\n", .{ step(), ver, platform });689}690691pub fn updateSelfVerifying() void {692 p("{s}verifying checksum\n", .{step()});693}694695pub fn updateSelfInstalling(install_path: []const u8) void {696 p("{s}installing to {s}\n", .{ step(), install_path });697}698699pub fn updateSelfDone(old_ver: []const u8, new_ver: []const u8) void {700 p("{s}updated {s} {s}→{s} {s}\n", .{ hdr(), old_ver, c(DIM), c(RESET), new_ver });701}702703pub fn updateSelfNoPlatform(platform: []const u8) void {704 p("{s}no pre-built binary for {s}\n", .{ hdr(), platform });705 p("{s}check kepr.uk/nina/releases for available platforms\n", .{step()});706}707708pub fn updateSelfNetworkError() void {709 p("{s}{s}\n", .{ if (color_enabled) WARN_C else WARN_P, "could not reach kepr.uk — check your connection" });710}711712pub fn updateSelfChecksumFailed() void {713 p("{s}checksum mismatch — download may be corrupt\n", .{if (color_enabled) ERR_C else ERR_P});714 p("{s}try again or download manually from kepr.uk/nina/releases\n", .{step()});715}716717pub fn updateSelfNixManaged(new_ver: []const u8) void {718 p("{s}upgrading to {s}{s}{s} via nix profile\n", .{ step(), c(BOLD), new_ver, c(RESET) });719}720721pub fn updateSelfNixFailed() void {722 p("{s}nix profile upgrade failed\n", .{if (color_enabled) ERR_C else ERR_P});723 p("{s}try manually: nix profile upgrade '.*nina.*'\n", .{step()});724}725726pub fn updateSelfNixSystemManaged() void {727 p("{s}nina appears to be managed by your NixOS system configuration\n", .{hdr()});728 p("{s}to update: sudo nixos-rebuild switch\n", .{step()});729 p("{s}to reinstall as a profile package: curl -fsSL kepr.uk/nina/install.sh | sh\n", .{step()});730}731732733734pub fn goodbyeStart() void {735 p("{s}uninstalling nina\n", .{hdr()});736}737738pub fn goodbyeFile(path: []const u8) void {739 p("{s}will remove {s}\n", .{ step(), path });740}741742pub fn goodbyeNix() void {743 p("{s}will remove nina from nix profile\n", .{step()});744 p("{s}command: nix profile remove '.*nina.*'\n", .{step()});745}746747pub fn goodbyeNixSystemManaged() void {748 p("{s}nina is managed by your NixOS system configuration\n", .{hdr()});749 p("{s}to remove: delete ~/nina.nix, then run sudo nixos-rebuild switch\n", .{step()});750 p("{s}or remove the nina import from /etc/nixos/configuration.nix directly\n", .{step()});751}752753pub fn goodbyeNixFileFound(path: []const u8) void {754 p("{s}found {s} (NixOS config snippet from the installer)\n", .{ step(), path });755}756757pub fn goodbyeDone() void {758 p("{s}goodbye! reinstall anytime: curl -fsSL kepr.uk/nina/install.sh | sh\n", .{hdr()});759}760761pub fn goodbyeFailed(msg: []const u8) void {762 p("{s}{s}\n", .{ if (color_enabled) ERR_C else ERR_P, msg });763}764765766767pub fn setupCheck() void {768 p("{s}checking nix features\n", .{hdr()});769}770771pub fn setupFeatures(nix_command: bool, flakes: bool) void {772 p("{s}nix-command {s}{s}{s}\n", .{773 step(),774 if (nix_command) c(GREEN) else "",775 if (nix_command) "enabled" else "not enabled",776 if (nix_command) c(RESET) else "",777 });778 p("{s}flakes {s}{s}{s}\n", .{779 step(),780 if (flakes) c(GREEN) else "",781 if (flakes) "enabled" else "not enabled",782 if (flakes) c(RESET) else "",783 });784}785786pub fn setupAllSet() void {787 p("{s}all set\n", .{hdr()});788}789790791792pub fn pinningRegistry() void {793 p("{s}pinning nixpkgs for fast local search...\n", .{hdr()});794 flush();795}796797798799800801pub fn searchPlainHeader(mode_str: []const u8, query: []const u8, count: u64) void {802 p("{s}search {s} {s} {s}{d} results{s}\n", .{ hdr(), mode_str, query, c(DIM), count, c(RESET) });803}804805pub fn searchPlainNoResults() void {806 p(" no results\n", .{});807}808809pub fn searchPlainPackage(pname: []const u8, pkg_version: []const u8, description: []const u8, unfree: bool) void {810 if (unfree) {811 p(" {s} {s}{s}{s} {s}unfree{s} {s}\n", .{ pname, c(DIM), pkg_version, c(RESET), c(YELLOW), c(RESET), description });812 } else {813 p(" {s} {s}{s}{s} {s}\n", .{ pname, c(DIM), pkg_version, c(RESET), description });814 }815}816817pub fn searchPlainOption(name: []const u8, type_str: []const u8) void {818 p(" {s} {s}{s}{s}\n", .{ name, c(DIM), type_str, c(RESET) });819}820821pub fn searchEmptyQuery() void {822 p("{s}search needs a query {s}e.g. nina search firefox{s}\n", .{ hdr(), c(DIM), c(RESET) });823}824825pub fn setupEnabling() void {826 p("{s}enabling experimental features\n", .{hdr()});827}828829pub fn setupDone(path: []const u8, is_nixos: bool) void {830 p("{s}wrote {s}\n", .{ step(), path });831 p("{s}done open a new shell to pick up the change\n", .{hdr()});832 if (is_nixos) {833 printSubstep("to persist across nixos-rebuild, add to configuration.nix:", .{});834 printSubstep(" nix.settings.experimental-features = [ \"nix-command\" \"flakes\" ];", .{});835 }836}837838pub fn pinDone(input: []const u8, commit: []const u8) void {839 p("{s}pinned {s} -> {s}\n", .{ hdr(), input, commit });840}841842pub fn unpinDone(input: []const u8) void {843 p("{s}unpinned {s}\n", .{ hdr(), input });844}845846pub fn hashResult(hash: []const u8) void {847 p("{s}\n", .{hash});848}849850pub fn fetchResult(hash: []const u8, url: []const u8) void {851 _ = url;852 p("{s}\n", .{hash});853}854855pub fn storeRepairStart() void {856 p("{s}repairing store\n", .{hdr()});857}858859pub fn storeVerifyStart() void {860 p("{s}verifying store\n", .{hdr()});861}862863pub fn storeGcDone(freed: []const u8) void {864 p("{s}freed {s}\n", .{ hdr(), freed });865}866867pub fn storePath(path: []const u8) void {868 p("{s}\n", .{path});869}870871pub fn pkgResult(key: []const u8, val: []const u8) void {872 p(" {s:<16} {s}\n", .{ key, val });873}874875pub fn channelDone() void {876 p("{s}done\n", .{hdr()});877}878879pub fn flakeShowHeader(name: []const u8) void {880 p("{s}{s}\n\n", .{ hdr(), name });881}882883pub fn flakeShowEntry(kind: []const u8, name: []const u8, desc: []const u8) void {884 p(" {s:<12} {s:<24} {s}\n", .{ kind, name, desc });885}