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}73747576pub fn colorEnabled() bool {77 return color_enabled;78}7980fn c(code: []const u8) []const u8 {81 return if (color_enabled) code else "";82}8384fn hdr() []const u8 {85 return if (color_enabled) HDR_C else HDR_P;86}8788fn step() []const u8 {89 return if (color_enabled) STEP_C else STEP_P;90}9192fn teach_pfx() []const u8 {93 return if (color_enabled) TEACH_C else TEACH_P;94}959697pub fn raw(bytes: []const u8) void {98 _w.writeAll(bytes) catch {};99}100101102pub fn p(comptime fmt: []const u8, args: anytype) void {103 _w.print(fmt, args) catch {};104}105106pub fn cursorUp(n: usize) void {107 if (n > 0) p("\x1b[{d}A", .{n});108}109110pub fn clearLine() void {111 p("\r\x1b[K", .{});112}113114115116pub fn printError(message: []const u8, detail: ?[]const u8, suggestion: ?[]const u8) void {117 p("{s}{s}\n", .{ if (color_enabled) ERR_C else ERR_P, message });118 if (detail) |d| p(" {s}{s}{s}\n", .{ c(DIM), d, c(RESET) });119 120 if (suggestion) |s| p(" {s}-> {s}{s}\n", .{ c(CYAN), s, c(RESET) });121}122123124125126pub fn printSystemError(message: []const u8, detail: ?[]const u8, suggestion: ?[]const u8) void {127 p("{s}{s}{s}\n", .{ KAO_SAD, if (color_enabled) ERR_C else ERR_P, message });128 if (detail) |d| p(" {s}{s}{s}\n", .{ c(DIM), d, c(RESET) });129 if (suggestion) |s| p(" {s}-> {s}{s}\n", .{ c(CYAN), s, c(RESET) });130}131132pub fn printWarning(message: []const u8) void {133 p("{s}{s}\n", .{ if (color_enabled) WARN_C else WARN_P, message });134}135136pub fn printTeach(cmd: []const u8) void {137 if (teach_enabled) p("{s}{s}{s}\n", .{ teach_pfx(), cmd, c(RESET) });138}139140pub fn printSubstep(comptime fmt: []const u8, args: anytype) void {141 p("{s}", .{step()});142 p(fmt, args);143 p("\n", .{});144}145146147148pub fn confirm(prompt: []const u8) bool {149 p(" {s}continue? [Y/n] ", .{prompt});150 flush();151 var buf: [64]u8 = undefined;152 var i: usize = 0;153 while (i < buf.len) {154 const n = std.posix.read(std.posix.STDIN_FILENO, buf[i .. i + 1]) catch break;155 if (n == 0) break;156 if (buf[i] == '\n') break;157 i += 1;158 }159 const input = std.mem.trim(u8, buf[0..i], " \t");160 if (input.len == 0) return true;161 return input[0] != 'n' and input[0] != 'N';162}163164165166pub fn applyStart(machine: []const u8) void {167 p("{s}{s}rebuilding {s}...\n", .{ KAO_COZY, hdr(), machine });168}169170171172173pub fn applyDone(gen: u32, elapsed_ms: u64, after_failure: bool) void {174 const face = if (after_failure) KAO_EXCITED else "";175 const secs = @as(f64, @floatFromInt(elapsed_ms)) / 1000.0;176 if (elapsed_ms >= 1000) {177 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) });178 } else {179 p("{s}{s}generation {s}{d}{s}\n", .{ face, hdr(), c(BOLD), gen, c(RESET) });180 }181}182183pub fn applyFailed(translated: []const u8) void {184 p("{s}build failed\n", .{if (color_enabled) ERR_C else ERR_P});185 if (translated.len > 0) p(" {s}{s}{s}\n", .{ c(DIM), translated, c(RESET) });186 p(" {s}-> nina doctor{s}\n", .{ c(DIM), c(RESET) });187}188189pub fn applyDry(machine: []const u8) void {190 p("{s}dry run {s}\n", .{ hdr(), machine });191}192193pub fn applyDryDone() void {194 p("{s}no changes applied\n", .{hdr()});195}196197198199pub fn checkStart(machine: []const u8) void {200 p("{s}checking {s}...\n", .{ hdr(), machine });201}202203pub fn checkOk() void {204 p("{s}{s}ok{s}\n", .{ hdr(), c(GREEN), c(RESET) });205}206207pub fn checkFailed(msg: []const u8) void {208 p("{s}config invalid\n", .{if (color_enabled) ERR_C else ERR_P});209 if (msg.len > 0) p(" {s}{s}{s}\n", .{ c(DIM), msg, c(RESET) });210}211212213214pub fn backStart(machine: []const u8, from: u32, to: u32) void {215 p("{s}rolling back {s} gen {d} -> gen {d}\n", .{ hdr(), machine, from, to });216}217218pub fn goStart(machine: []const u8, current: u32, target: u32) void {219 p("{s}switching {s} gen {d} -> gen {d}\n", .{ hdr(), machine, current, target });220}221222pub fn generationDone(n: u32) void {223 p("{s}done gen {s}{d}{s}\n", .{ hdr(), c(BOLD), n, c(RESET) });224}225226227228229pub fn alreadyOldest() void {230 p("{s}already at the oldest generation\n", .{if (color_enabled) ERR_C else ERR_P});231}232233234235pub fn backDone(n: u32) void {236 p("{s}{s}done gen {s}{d}{s}\n", .{ KAO_GENTLE, hdr(), c(BOLD), n, c(RESET) });237}238239240241pub fn historyHeader(machine: []const u8) void {242 p("{s}generations {s}\n\n", .{ hdr(), machine });243}244245pub fn historyRow(gen: types.GenerationInfo) void {246 if (gen.current) {247 p(" {s}{d}{s} {s} {s} {s}current{s}\n", .{ c(BOLD), gen.number, c(RESET), gen.date, gen.time, c(BOLD), c(RESET) });248 } else {249 p(" {s}{d} {s} {s}{s}\n", .{ c(DIM), gen.number, gen.date, gen.time, c(RESET) });250 }251}252253254255pub fn cleanStart(machine: []const u8, keep: u32, total: u32) void {256 p("{s}cleaning {s} keeping {d} of {d}\n", .{ hdr(), machine, keep, total });257}258259260261pub fn cleanNothing(machine: []const u8, total: u32) void {262 p("{s}cleaning {s}\n\n", .{ hdr(), machine });263 p(" only {d} generation{s} — nothing to remove.\n", .{ total, if (total == 1) "" else "s" });264}265266pub fn cleanDone(freed: []const u8) void {267 p("{s}{s}freed {s}\n", .{ KAO_CONTENT, hdr(), freed });268}269270271272pub fn statusHeader() void {273 p("{s}status\n\n", .{hdr()});274}275276pub fn statusRow(machine: []const u8, gen: u32, time: []const u8, size: []const u8, ok: bool) void {277 if (ok) {278 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) });279 } else {280 p(" {s}{s} {s}unreachable{s}\n", .{ c(RED), machine, "", c(RESET) });281 }282}283284285286pub fn diffHeader(a: u32, b: u32, machine: []const u8) void {287 p("{s}gen {d} -> gen {d} {s}\n\n", .{ hdr(), a, b, machine });288}289290pub fn diffRow(entry: types.DiffEntry) void {291 switch (entry.op) {292 .add => p(" {s}+{s} {s} {s}\n", .{ c(GREEN), c(RESET), entry.package, entry.new_version orelse "" }),293 .remove => p(" {s}-{s} {s} {s}\n", .{ c(RED), c(RESET), entry.package, entry.old_version orelse "" }),294 .change => p(" {s}^{s} {s} {s} -> {s}\n", .{ c(CYAN), c(RESET), entry.package, entry.old_version orelse "", entry.new_version orelse "" }),295 }296}297298299300pub fn doctorHeader(machine: []const u8) void {301 p("{s}diagnosing {s}\n\n", .{ hdr(), machine });302}303304pub fn doctorRow(check: types.DoctorCheck) void {305 const status_str = switch (check.status) {306 .ok => if (color_enabled) GREEN ++ "ok" ++ RESET else "ok",307 .warn => if (color_enabled) YELLOW ++ "warn" ++ RESET else "warn",308 .fail => if (color_enabled) RED ++ "fail" ++ RESET else "fail",309 };310 const note_str = check.note orelse "";311 p(" {s:<16} {s} {s}\n", .{ check.name, status_str, note_str });312}313314pub fn doctorSummary(warnings: u32, failures: u32) void {315 if (failures > 0) {316 p("{s}{d} problems\n", .{ hdr(), failures });317 } else if (warnings > 0) {318 p("{s}{d} warnings\n", .{ hdr(), warnings });319 } else {320 p("{s}{s}{s}all good{s}\n", .{ KAO_HAPPY, hdr(), c(GREEN), c(RESET) });321 }322}323324325326pub fn updateStart(machine: []const u8) void {327 p("{s}updating channels {s}\n\n", .{ hdr(), machine });328}329330pub fn updateChannel(name: []const u8, old: ?[]const u8, new: ?[]const u8) void {331 if (old != null and new != null and !std.mem.eql(u8, old.?, new.?)) {332 p(" {s} {s} -> {s}\n", .{ name, old.?, new.? });333 } else {334 p(" {s} {s}no change{s}\n", .{ name, c(DIM), c(RESET) });335 }336}337338pub fn updateDone() void {339 p("\n{s}done\n", .{hdr()});340}341342343344pub fn upgradeStart(machine: []const u8) void {345 p("{s}upgrading {s}\n", .{ hdr(), machine });346}347348349350pub fn logHeader(machine: []const u8) void {351 p("{s}history {s}\n\n", .{ hdr(), machine });352}353354pub fn logRow(date: []const u8, time: []const u8, action: []const u8, detail: []const u8) void {355 p(" {s}{s} {s}{s} {s:<12} {s}\n", .{ c(DIM), date, time, c(RESET), action, detail });356}357358359360pub fn editOpen(path: []const u8, editor: []const u8) void {361 p("{s}opening {s}\n", .{ hdr(), path });362 printSubstep("{s}", .{editor});363 p("\n {s}run nina check to validate before applying{s}\n", .{ c(DIM), c(RESET) });364}365366367368pub fn fmtStart(path: []const u8) void {369 p("{s}formatting {s}\n", .{ hdr(), path });370}371372pub fn fmtDone() void {373 p("{s}done\n", .{hdr()});374}375376pub fn fmtNeedsFormat() void {377 p("{s}needs formatting {s}run nina fmt to fix{s}\n", .{ hdr(), c(DIM), c(RESET) });378}379380381382pub fn replStart() void {383 p("{s}nix repl {s}nixpkgs loaded{s} :q to exit\n", .{ hdr(), c(DIM), c(RESET) });384}385386387388pub fn developStart(pkgs: []const []const u8) void {389 p("{s}entering dev shell\n\n ", .{hdr()});390 for (pkgs, 0..) |pkg, i| {391 if (i > 0) p(" ", .{});392 p("{s}", .{pkg});393 }394 p("\n\n {s}exit to return{s}\n\n", .{ c(DIM), c(RESET) });395}396397pub fn developDone() void {398 p("{s}{s}back\n", .{ KAO_SLEEPY, hdr() });399}400401402403pub fn infoHeader(machine: []const u8) void {404 p("{s}{s}\n\n", .{ hdr(), machine });405}406407pub fn infoRow(key: []const u8, val: []const u8) void {408 p(" {s:<12} {s}\n", .{ key, val });409}410411412413pub fn bootHeader(machine: []const u8) void {414 p("{s}boot entries {s}\n\n", .{ hdr(), machine });415}416417pub fn bootEntry(entry: types.BootEntry, idx: usize) void {418 if (entry.current) {419 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) });420 } else {421 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) });422 }423 _ = idx;424}425426427428pub fn serviceListHeader(machine: []const u8) void {429 p("{s}services {s}\n\n", .{ hdr(), machine });430}431432pub fn serviceRow(svc: types.ServiceInfo) void {433 const state_str = switch (svc.state) {434 .active => if (color_enabled) GREEN ++ "active" ++ RESET else "active",435 .failed => if (color_enabled) RED ++ "failed" ++ RESET else "failed",436 .inactive => "inactive",437 .unknown => "unknown",438 };439 const uptime = svc.uptime orelse "";440 p(" {s:<24} {s:<14} {s}\n", .{ svc.name, state_str, uptime });441}442443pub fn serviceVerb(verb: []const u8, name: []const u8, machine: []const u8) void {444 p("{s}{s} {s} {s}\n", .{ hdr(), verb, name, machine });445}446447pub fn serviceDone() void {448 p("{s}done\n", .{hdr()});449}450451pub fn serviceLogsHeader(name: []const u8, n: u32, machine: []const u8) void {452 p("{s}{s} last {d} lines {s}\n\n", .{ hdr(), name, n, machine });453}454455456457pub fn storeInfo(info: types.StoreInfo) void {458 p("{s}store\n\n", .{hdr()});459 p(" {s:<16} {s}\n", .{ "total", info.total_size });460 p(" {s:<16} {d} paths\n", .{ "live", info.live_paths });461 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) });462}463464465466pub fn channelListHeader(machine: []const u8) void {467 p("{s}channels {s}\n\n", .{ hdr(), machine });468}469470pub fn channelRow(ch: types.ChannelInfo) void {471 p(" {s:<16} {s}\n", .{ ch.name, ch.url });472}473474475476pub fn flakeUpdateStart() void {477 p("{s}updating inputs\n\n", .{hdr()});478}479480pub fn flakeInput(input: types.FlakeInput) void {481 if (input.changed) {482 const old = if (input.old_rev) |r| r[0..@min(7, r.len)] else "?";483 const new = if (input.new_rev) |r| r[0..@min(7, r.len)] else "?";484 p(" {s:<20} {s} -> {s}\n", .{ input.name, old, new });485 } else {486 p(" {s:<20} {s}no change{s}\n", .{ input.name, c(DIM), c(RESET) });487 }488}489490pub fn flakeLockWritten() void {491 p("\n{s}flake.lock written\n", .{hdr()});492}493494pub fn flakeValid() void {495 p("{s}{s}valid{s}\n", .{ hdr(), c(GREEN), c(RESET) });496}497498pub fn flakeCheckStart() void {499 p("{s}checking flake\n", .{hdr()});500}501502503504pub fn profileListHeader() void {505 p("{s}profile packages\n\n", .{hdr()});506}507508pub fn profileRow(attr: []const u8, pkg_version: []const u8, description: []const u8) void {509 p(" {s:<24} {s:<12} {s}\n", .{ attr, pkg_version, description });510}511512513514pub fn installStart(pkg: []const u8, path: types.InstallPath) void {515 const path_str = switch (path) {516 .profile => "profile",517 .system => "system",518 };519 p("{s}installing {s}{s}{s} {s}\n", .{ hdr(), c(PINK), pkg, c(RESET), path_str });520}521522pub fn installDone(pkg: []const u8) void {523 p("{s}{s}{s}{s} installed {s}available now{s}\n", .{ hdr(), c(PINK), pkg, c(RESET), c(DIM), c(RESET) });524}525526pub fn removeStart(pkg: []const u8) void {527 p("{s}removing {s}{s}{s}\n", .{ hdr(), c(PINK), pkg, c(RESET) });528}529530531pub fn mood(machine: []const u8, state: []const u8, gen: u32, age: []const u8, size: []const u8) void {532 const healthy = std.mem.eql(u8, state, "running");533 const verdict = if (healthy) "all good" else state;534 const color = if (healthy) GREEN else YELLOW;535 const face = if (healthy) KAO_HAPPY else "";536 p("{s}{s}{s} {s}{s}{s}\n", .{ face, hdr(), machine, c(color), verdict, c(RESET) });537 if (age.len > 0 or size.len > 0) {538 p(" generation {d}, last applied {s}, {s} system closure\n", .{ gen, age, size });539 } else {540 p(" generation {d}\n", .{gen});541 }542}543544pub fn installEditorPrompt(pkg: []const u8, config_path: []const u8, line: u32, editor: []const u8) void {545 p("{s}opening {s} add {s}{s}{s} to systemPackages\n", .{ hdr(), config_path, c(PINK), pkg, c(RESET) });546 const cmd = std.fmt.allocPrint(std.heap.page_allocator, "{s} {s} +{d}", .{ editor, config_path, line }) catch editor;547 printSubstep("{s}", .{cmd});548 p("\n {s}save and close when done{s}\n\n", .{ c(DIM), c(RESET) });549}550551pub fn installSelectPrompt(pkg: []const u8, pkg_version: []const u8) void {552 p("{s}{s}{s}{s} {s}\n\n", .{ hdr(), c(PINK), pkg, c(RESET), pkg_version });553 p(" [i] profile install {s}instant no rebuild{s}\n", .{ c(DIM), c(RESET) });554 p(" [s] system install {s}opens editor requires apply{s}\n", .{ c(DIM), c(RESET) });555 p(" [t] try now {s}exits when done{s}\n\n", .{ c(DIM), c(RESET) });556 p(" > ", .{});557 flush();558}559560pub fn tryStart(pkg: []const u8) void {561 p("{s}trying {s}{s}{s} exit when done\n", .{ hdr(), c(PINK), pkg, c(RESET) });562}563564pub fn tryDone() void {565 p("{s}{s}back\n", .{ KAO_SLEEPY, hdr() });566}567568569570pub fn listHeader(machine: []const u8) void {571 p("{s}packages {s}\n\n", .{ hdr(), machine });572}573574pub fn listSection(title: []const u8) void {575 p(" {s}{s}{s}\n", .{ c(DIM), title, c(RESET) });576}577578579pub fn listPkg(name: []const u8, pkg_version: []const u8) void {580 p(" {s}{s:<16}{s} {s}{s}{s}\n", .{ c(PINK), name, c(RESET), c(DIM), pkg_version, c(RESET) });581}582583pub fn blankLine() void {584 p("\n", .{});585}586587588589pub fn hello(machines: []const types.Machine) void {590 p("{s}{s}nina\n\n", .{ KAO_FACE, hdr() });591 for (machines) |m| {592 const kind = if (m.local) "local" else "ssh";593 const detail = if (m.local) "default" else m.host orelse "";594 p(" {s}{s}{s} {s} {s}\n", .{ c(DIM), m.name, c(RESET), kind, detail });595 }596 p("\n", .{});597 const quick = [_][2][]const u8{598 .{ "apply", "rebuild and switch" },599 .{ "search <q>", "find packages" },600 .{ "install <pkg>", "add to profile or system" },601 .{ "status", "machine health" },602 .{ "back", "roll back one generation" },603 .{ "update", "refresh channels" },604 };605 for (quick) |cmd| {606 p(" {s:<16} {s}{s}{s}\n", .{ cmd[0], c(DIM), cmd[1], c(RESET) });607 }608 p("\n", .{});609}610611612613pub fn help() void {614 p("{s}nina {s}nixos helper{s}\n\n", .{ hdr(), c(DIM), c(RESET) });615 const cmds = [_][2][]const u8{616 .{ "apply", "rebuild and switch" },617 .{ "back", "roll back one generation" },618 .{ "go <n>", "switch to generation n" },619 .{ "history", "list all generations" },620 .{ "clean", "remove old generations" },621 .{ "search <q>", "find packages" },622 .{ "install <pkg>", "add to profile or system" },623 .{ "remove <pkg>", "remove from profile or system" },624 .{ "try <pkg>", "test without installing" },625 .{ "list", "show installed packages" },626 .{ "edit", "open configuration.nix" },627 .{ "check", "validate config" },628 .{ "diff", "changes between generations" },629 .{ "status", "machine health" },630 .{ "update", "refresh channels" },631 .{ "upgrade", "update and rebuild" },632 .{ "log", "operation history" },633 .{ "doctor", "diagnose issues" },634 .{ "mood", "plain-language health" },635 .{ "develop", "enter dev shell" },636 .{ "flake", "flake management" },637 .{ "build", "build a package" },638 .{ "run", "run without installing" },639 .{ "service", "manage services" },640 .{ "store", "nix store tools" },641 .{ "channel", "manage channels" },642 .{ "profile", "user profile packages" },643 .{ "info", "system information" },644 .{ "boot", "boot entries" },645 .{ "fmt", "format configuration.nix" },646 .{ "repl", "nix repl with nixpkgs" },647 .{ "option <q>", "search nixos options" },648 .{ "pkg", "inspect packages" },649 .{ "pin", "pin flake inputs" },650 .{ "hash", "compute nix hash" },651 .{ "fetch", "fetch and hash a url" },652 .{ "goodbye", "uninstall nina" },653 .{ "hello", "list machines" },654 .{ "help", "this message" },655 };656 for (cmds) |cmd| {657 p(" {s:<18} {s}{s}{s}\n", .{ cmd[0], c(DIM), cmd[1], c(RESET) });658 }659 p("\n {s}flags: --on <machine> --dry --check --no-apply --last <n> --all --json{s}\n", .{ c(DIM), c(RESET) });660}661662pub fn version() void {663 p("{s}nina v{s} zig 0.16 zero dependencies\n", .{ hdr(), nina_version.VERSION });664}665666667668pub fn searchResult(pkg: types.NixPackage) void {669 p(" {s}{s}{s} {s}{s}{s} {s}\n", .{ c(PINK), pkg.pname, c(RESET), c(DIM), pkg.version, c(RESET), pkg.description });670}671672pub fn searchHeader(query: []const u8, count: usize) void {673 p("{s}search nixpkgs {s} {s}{d} results{s}\n\n", .{ hdr(), query, c(DIM), count, c(RESET) });674}675676677678pub fn genCurrent(n: u32) void {679 p("{d}\n", .{n});680}681682pub fn done() void {683 p("{s}done\n", .{hdr()});684}685686pub fn runStart(pkg: []const u8) void {687 p("{s}running {s}{s}{s}\n", .{ hdr(), c(PINK), pkg, c(RESET) });688}689690pub fn buildStart(attr: []const u8) void {691 p("{s}building {s}\n", .{ hdr(), attr });692}693694pub fn buildDone() void {695 p("{s}done\n", .{hdr()});696}697698699700pub fn updateSelfStart() void {701 p("{s}checking for updates\n", .{hdr()});702}703704pub fn updateSelfCurrent(ver: []const u8) void {705 p("{s}{s}nina {s} is up to date{s}\n", .{ hdr(), c(GREEN), ver, c(RESET) });706}707708pub fn updateSelfAvailable(current: []const u8, latest: []const u8) void {709 p("{s}current {s}\n", .{ step(), current });710 p("{s}latest {s}{s}{s}\n", .{ step(), c(BOLD), latest, c(RESET) });711}712713pub fn updateSelfDownloading(ver: []const u8, platform: []const u8) void {714 p("{s}downloading nina {s} for {s}\n", .{ step(), ver, platform });715}716717pub fn updateSelfVerifying() void {718 p("{s}verifying checksum\n", .{step()});719}720721pub fn updateSelfInstalling(install_path: []const u8) void {722 p("{s}installing to {s}\n", .{ step(), install_path });723}724725pub fn updateSelfDone(old_ver: []const u8, new_ver: []const u8) void {726 p("{s}updated {s} {s}→{s} {s}\n", .{ hdr(), old_ver, c(DIM), c(RESET), new_ver });727}728729pub fn updateSelfNoPlatform(platform: []const u8) void {730 p("{s}no pre-built binary for {s}\n", .{ hdr(), platform });731 p("{s}check kepr.uk/nina/releases for available platforms\n", .{step()});732}733734pub fn updateSelfNetworkError() void {735 p("{s}{s}\n", .{ if (color_enabled) WARN_C else WARN_P, "could not reach kepr.uk — check your connection" });736}737738pub fn updateSelfChecksumFailed() void {739 p("{s}checksum mismatch — download may be corrupt\n", .{if (color_enabled) ERR_C else ERR_P});740 p("{s}try again or download manually from kepr.uk/nina/releases\n", .{step()});741}742743pub fn updateSelfNixManaged(new_ver: []const u8) void {744 p("{s}upgrading to {s}{s}{s} via nix profile\n", .{ step(), c(BOLD), new_ver, c(RESET) });745}746747pub fn updateSelfNixFailed() void {748 p("{s}nix profile upgrade failed\n", .{if (color_enabled) ERR_C else ERR_P});749 p("{s}try manually: nix profile upgrade '.*nina.*'\n", .{step()});750}751752pub fn updateSelfNixSystemManaged() void {753 p("{s}nina appears to be managed by your NixOS system configuration\n", .{hdr()});754 p("{s}to update: sudo nixos-rebuild switch\n", .{step()});755 p("{s}to reinstall as a profile package: curl -fsSL kepr.uk/nina/install.sh | sh\n", .{step()});756}757758759760pub fn goodbyeStart() void {761 p("{s}uninstalling nina\n", .{hdr()});762}763764pub fn goodbyeFile(path: []const u8) void {765 p("{s}will remove {s}\n", .{ step(), path });766}767768pub fn goodbyeNix() void {769 p("{s}will remove nina from nix profile\n", .{step()});770 p("{s}command: nix profile remove '.*nina.*'\n", .{step()});771}772773pub fn goodbyeNixSystemManaged() void {774 p("{s}nina is managed by your NixOS system configuration\n", .{hdr()});775 p("{s}to remove: delete ~/nina.nix, then run sudo nixos-rebuild switch\n", .{step()});776 p("{s}or remove the nina import from /etc/nixos/configuration.nix directly\n", .{step()});777}778779pub fn goodbyeNixFileFound(path: []const u8) void {780 p("{s}found {s} (NixOS config snippet from the installer)\n", .{ step(), path });781}782783pub fn goodbyeDone() void {784 p("{s}goodbye! reinstall anytime: curl -fsSL kepr.uk/nina/install.sh | sh\n", .{hdr()});785}786787pub fn goodbyeFailed(msg: []const u8) void {788 p("{s}{s}\n", .{ if (color_enabled) ERR_C else ERR_P, msg });789}790791792793pub fn setupCheck() void {794 p("{s}checking nix features\n", .{hdr()});795}796797pub fn setupFeatures(nix_command: bool, flakes: bool) void {798 p("{s}nix-command {s}{s}{s}\n", .{799 step(),800 if (nix_command) c(GREEN) else "",801 if (nix_command) "enabled" else "not enabled",802 if (nix_command) c(RESET) else "",803 });804 p("{s}flakes {s}{s}{s}\n", .{805 step(),806 if (flakes) c(GREEN) else "",807 if (flakes) "enabled" else "not enabled",808 if (flakes) c(RESET) else "",809 });810}811812pub fn setupAllSet() void {813 p("{s}all set\n", .{hdr()});814}815816817818pub fn pinningRegistry() void {819 p("{s}pinning nixpkgs for fast local search...\n", .{hdr()});820 flush();821}822823824825826827pub fn searchPlainHeader(mode_str: []const u8, query: []const u8, count: u64) void {828 p("{s}search {s} {s} {s}{d} results{s}\n", .{ hdr(), mode_str, query, c(DIM), count, c(RESET) });829}830831pub fn searchPlainNoResults() void {832 p(" no results\n", .{});833}834835pub fn searchPlainPackage(pname: []const u8, pkg_version: []const u8, description: []const u8, unfree: bool) void {836 if (unfree) {837 p(" {s} {s}{s}{s} {s}unfree{s} {s}\n", .{ pname, c(CYAN), pkg_version, c(RESET), c(YELLOW), c(RESET), description });838 } else {839 p(" {s} {s}{s}{s} {s}\n", .{ pname, c(CYAN), pkg_version, c(RESET), description });840 }841}842843pub fn searchPlainOption(name: []const u8, type_str: []const u8) void {844 p(" {s} {s}{s}{s}\n", .{ name, c(DIM), type_str, c(RESET) });845}846847pub fn searchEmptyQuery() void {848 p("{s}search needs a query {s}e.g. nina search firefox{s}\n", .{ hdr(), c(DIM), c(RESET) });849}850851pub fn setupEnabling() void {852 p("{s}enabling experimental features\n", .{hdr()});853}854855pub fn setupDone(path: []const u8, is_nixos: bool) void {856 p("{s}wrote {s}\n", .{ step(), path });857 p("{s}done open a new shell to pick up the change\n", .{hdr()});858 if (is_nixos) {859 printSubstep("to persist across nixos-rebuild, add to configuration.nix:", .{});860 printSubstep(" nix.settings.experimental-features = [ \"nix-command\" \"flakes\" ];", .{});861 }862}863864pub fn pinDone(input: []const u8, commit: []const u8) void {865 p("{s}pinned {s} -> {s}\n", .{ hdr(), input, commit });866}867868pub fn unpinDone(input: []const u8) void {869 p("{s}unpinned {s}\n", .{ hdr(), input });870}871872pub fn hashResult(hash: []const u8) void {873 p("{s}\n", .{hash});874}875876pub fn fetchResult(hash: []const u8, url: []const u8) void {877 _ = url;878 p("{s}\n", .{hash});879}880881pub fn storeRepairStart() void {882 p("{s}repairing store\n", .{hdr()});883}884885pub fn storeVerifyStart() void {886 p("{s}verifying store\n", .{hdr()});887}888889pub fn storeGcDone(freed: []const u8) void {890 p("{s}freed {s}\n", .{ hdr(), freed });891}892893pub fn storePath(path: []const u8) void {894 p("{s}\n", .{path});895}896897pub fn pkgResult(key: []const u8, val: []const u8) void {898 p(" {s:<16} {s}\n", .{ key, val });899}900901pub fn channelDone() void {902 p("{s}done\n", .{hdr()});903}904905pub fn flakeShowHeader(name: []const u8) void {906 p("{s}{s}\n\n", .{ hdr(), name });907}908909pub fn flakeShowEntry(kind: []const u8, name: []const u8, desc: []const u8) void {910 p(" {s:<12} {s:<24} {s}\n", .{ kind, name, desc });911}