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";171819pub const C_PINK = PINK;20pub const C_BOLD = BOLD;21pub const C_GREEN = GREEN;22pub const C_YELLOW = YELLOW;23pub const C_RED = RED;24pub const C_CYAN = CYAN;25pub const C_DIM = DIM;26pub const C_RESET = RESET;27pub const C_CLEAR_EOL = "\x1b[K";28pub const C_CURSOR_UP_FMT = "\x1b[{d}A";293031const HDR_C = PINK ++ ":: " ++ RESET;32const HDR_P = ":: ";33const STEP_C = " " ++ DIM ++ "-> " ++ RESET;34const STEP_P = " -> ";35const TEACH_C = " " ++ DIM ++ "= " ++ RESET;36const TEACH_P = " = ";37const ERR_C = PINK ++ ":: " ++ RED ++ "error:" ++ RESET ++ " ";38const ERR_P = ":: error: ";39const WARN_C = PINK ++ ":: " ++ YELLOW ++ "warning:" ++ RESET ++ " ";40const WARN_P = ":: warning: ";4142var _fw: Io.File.Writer = undefined;43var _w: *Io.Writer = undefined;44var color_enabled: bool = true;45var teach_enabled: bool = false;4647pub fn init(writer: *Io.Writer, io: std.Io, environ: *const std.process.Environ.Map, color_config: bool) void {48 _w = writer;49 color_enabled = color_config and50 (std.Io.File.stdout().isTty(io) catch false) and51 !environ.contains("NO_COLOR");52}5354pub fn setTeach(enabled: bool) void {55 teach_enabled = enabled;56}5758pub fn flush() void {59 _w.flush() catch {};60}6162fn c(code: []const u8) []const u8 {63 return if (color_enabled) code else "";64}6566fn hdr() []const u8 {67 return if (color_enabled) HDR_C else HDR_P;68}6970fn step() []const u8 {71 return if (color_enabled) STEP_C else STEP_P;72}7374fn teach_pfx() []const u8 {75 return if (color_enabled) TEACH_C else TEACH_P;76}777879pub fn raw(bytes: []const u8) void {80 _w.writeAll(bytes) catch {};81}828384pub fn p(comptime fmt: []const u8, args: anytype) void {85 _w.print(fmt, args) catch {};86}8788pub fn cursorUp(n: usize) void {89 if (n > 0) p("\x1b[{d}A", .{n});90}9192pub fn clearLine() void {93 p("\r\x1b[K", .{});94}95969798pub fn printError(message: []const u8, detail: ?[]const u8, suggestion: ?[]const u8) void {99 p("{s}{s}\n", .{ if (color_enabled) ERR_C else ERR_P, message });100 if (detail) |d| p(" {s}{s}{s}\n", .{ c(DIM), d, c(RESET) });101 if (suggestion) |s| p(" {s}-> {s}{s}\n", .{ c(DIM), s, c(RESET) });102}103104pub fn printWarning(message: []const u8) void {105 p("{s}{s}\n", .{ if (color_enabled) WARN_C else WARN_P, message });106}107108pub fn printTeach(cmd: []const u8) void {109 if (teach_enabled) p("{s}{s}{s}\n", .{ teach_pfx(), cmd, c(RESET) });110}111112pub fn printSubstep(comptime fmt: []const u8, args: anytype) void {113 p("{s}", .{step()});114 p(fmt, args);115 p("\n", .{});116}117118119120pub fn confirm(prompt: []const u8) bool {121 p(" {s}continue? [Y/n] ", .{prompt});122 flush();123 var buf: [64]u8 = undefined;124 var i: usize = 0;125 while (i < buf.len) {126 const n = std.posix.read(std.posix.STDIN_FILENO, buf[i .. i + 1]) catch break;127 if (n == 0) break;128 if (buf[i] == '\n') break;129 i += 1;130 }131 const input = std.mem.trim(u8, buf[0..i], " \t");132 if (input.len == 0) return true;133 return input[0] != 'n' and input[0] != 'N';134}135136137138pub fn applyStart(machine: []const u8) void {139 p("{s}rebuilding {s}...\n", .{ hdr(), machine });140}141142pub fn applyDone(gen: u32, elapsed_ms: u64) void {143 const secs = @as(f64, @floatFromInt(elapsed_ms)) / 1000.0;144 if (elapsed_ms >= 1000) {145 p("{s}generation {s}{d}{s} {s}[{d:.1}s]{s}\n", .{ hdr(), c(BOLD), gen, c(RESET), c(DIM), secs, c(RESET) });146 } else {147 p("{s}generation {s}{d}{s}\n", .{ hdr(), c(BOLD), gen, c(RESET) });148 }149}150151pub fn applyFailed(translated: []const u8) void {152 p("{s}build failed\n", .{if (color_enabled) ERR_C else ERR_P});153 if (translated.len > 0) p(" {s}{s}{s}\n", .{ c(DIM), translated, c(RESET) });154 p(" {s}-> nina doctor{s}\n", .{ c(DIM), c(RESET) });155}156157pub fn applyDry(machine: []const u8) void {158 p("{s}dry run {s}\n", .{ hdr(), machine });159}160161pub fn applyDryDone() void {162 p("{s}no changes applied\n", .{hdr()});163}164165166167pub fn checkStart(machine: []const u8) void {168 p("{s}checking {s}...\n", .{ hdr(), machine });169}170171pub fn checkOk() void {172 p("{s}{s}ok{s}\n", .{ hdr(), c(GREEN), c(RESET) });173}174175pub fn checkFailed(msg: []const u8) void {176 p("{s}config invalid\n", .{if (color_enabled) ERR_C else ERR_P});177 if (msg.len > 0) p(" {s}{s}{s}\n", .{ c(DIM), msg, c(RESET) });178}179180181182pub fn backStart(machine: []const u8, from: u32, to: u32) void {183 p("{s}rolling back {s} gen {d} -> gen {d}\n", .{ hdr(), machine, from, to });184}185186pub fn goStart(machine: []const u8, current: u32, target: u32) void {187 p("{s}switching {s} gen {d} -> gen {d}\n", .{ hdr(), machine, current, target });188}189190pub fn generationDone(n: u32) void {191 p("{s}done gen {s}{d}{s}\n", .{ hdr(), c(BOLD), n, c(RESET) });192}193194195196pub fn historyHeader(machine: []const u8) void {197 p("{s}generations {s}\n\n", .{ hdr(), machine });198}199200pub fn historyRow(gen: types.GenerationInfo) void {201 if (gen.current) {202 p(" {s}{d}{s} {s} {s} {s}current{s}\n", .{ c(BOLD), gen.number, c(RESET), gen.date, gen.time, c(BOLD), c(RESET) });203 } else {204 p(" {s}{d} {s} {s}{s}\n", .{ c(DIM), gen.number, gen.date, gen.time, c(RESET) });205 }206}207208209210pub fn cleanStart(machine: []const u8, keep: u32, total: u32) void {211 p("{s}cleaning {s} keeping {d} of {d}\n", .{ hdr(), machine, keep, total });212}213214pub fn cleanDone(freed: []const u8) void {215 p("{s}freed {s}\n", .{ hdr(), freed });216}217218219220pub fn statusHeader() void {221 p("{s}status\n\n", .{hdr()});222}223224pub fn statusRow(machine: []const u8, gen: u32, time: []const u8, size: []const u8, ok: bool) void {225 if (ok) {226 p(" {s}{s} gen {d} {s} {s}{s}\n", .{ c(DIM), machine, gen, time, size, c(RESET) });227 } else {228 p(" {s}{s} {s}unreachable{s}\n", .{ c(RED), machine, "", c(RESET) });229 }230}231232233234pub fn diffHeader(a: u32, b: u32, machine: []const u8) void {235 p("{s}gen {d} -> gen {d} {s}\n\n", .{ hdr(), a, b, machine });236}237238pub fn diffRow(entry: types.DiffEntry) void {239 switch (entry.op) {240 .add => p(" {s}+{s} {s} {s}\n", .{ c(GREEN), c(RESET), entry.package, entry.new_version orelse "" }),241 .remove => p(" {s}-{s} {s} {s}\n", .{ c(RED), c(RESET), entry.package, entry.old_version orelse "" }),242 .change => p(" {s}^{s} {s} {s} -> {s}\n", .{ c(CYAN), c(RESET), entry.package, entry.old_version orelse "", entry.new_version orelse "" }),243 }244}245246247248pub fn doctorHeader(machine: []const u8) void {249 p("{s}diagnosing {s}\n\n", .{ hdr(), machine });250}251252pub fn doctorRow(check: types.DoctorCheck) void {253 const status_str = switch (check.status) {254 .ok => if (color_enabled) GREEN ++ "ok" ++ RESET else "ok",255 .warn => if (color_enabled) YELLOW ++ "warn" ++ RESET else "warn",256 .fail => if (color_enabled) RED ++ "fail" ++ RESET else "fail",257 };258 const note_str = check.note orelse "";259 p(" {s:<16} {s} {s}\n", .{ check.name, status_str, note_str });260}261262pub fn doctorSummary(warnings: u32, failures: u32) void {263 if (failures > 0) {264 p("{s}{d} problems\n", .{ hdr(), failures });265 } else if (warnings > 0) {266 p("{s}{d} warnings\n", .{ hdr(), warnings });267 } else {268 p("{s}{s}all good{s}\n", .{ hdr(), c(GREEN), c(RESET) });269 }270}271272273274pub fn updateStart(machine: []const u8) void {275 p("{s}updating channels {s}\n\n", .{ hdr(), machine });276}277278pub fn updateChannel(name: []const u8, old: ?[]const u8, new: ?[]const u8) void {279 if (old != null and new != null and !std.mem.eql(u8, old.?, new.?)) {280 p(" {s} {s} -> {s}\n", .{ name, old.?, new.? });281 } else {282 p(" {s} {s}no change{s}\n", .{ name, c(DIM), c(RESET) });283 }284}285286pub fn updateDone() void {287 p("\n{s}done\n", .{hdr()});288}289290291292pub fn upgradeStart(machine: []const u8) void {293 p("{s}upgrading {s}\n", .{ hdr(), machine });294}295296297298pub fn logHeader(machine: []const u8) void {299 p("{s}history {s}\n\n", .{ hdr(), machine });300}301302pub fn logRow(date: []const u8, time: []const u8, action: []const u8, detail: []const u8) void {303 p(" {s} {s} {s:<12} {s}\n", .{ date, time, action, detail });304}305306307308pub fn editOpen(path: []const u8, editor: []const u8) void {309 p("{s}opening {s}\n", .{ hdr(), path });310 printSubstep("{s}", .{editor});311 p("\n {s}run nina check to validate before applying{s}\n", .{ c(DIM), c(RESET) });312}313314315316pub fn fmtStart(path: []const u8) void {317 p("{s}formatting {s}\n", .{ hdr(), path });318}319320pub fn fmtDone() void {321 p("{s}done\n", .{hdr()});322}323324pub fn fmtNeedsFormat() void {325 p("{s}needs formatting {s}run nina fmt to fix{s}\n", .{ hdr(), c(DIM), c(RESET) });326}327328329330pub fn replStart() void {331 p("{s}nix repl {s}nixpkgs loaded{s} :q to exit\n", .{ hdr(), c(DIM), c(RESET) });332}333334335336pub fn developStart(pkgs: []const []const u8) void {337 p("{s}entering dev shell\n\n ", .{hdr()});338 for (pkgs, 0..) |pkg, i| {339 if (i > 0) p(" ", .{});340 p("{s}", .{pkg});341 }342 p("\n\n {s}exit to return{s}\n\n", .{ c(DIM), c(RESET) });343}344345pub fn developDone() void {346 p("{s}back\n", .{hdr()});347}348349350351pub fn infoHeader(machine: []const u8) void {352 p("{s}{s}\n\n", .{ hdr(), machine });353}354355pub fn infoRow(key: []const u8, val: []const u8) void {356 p(" {s:<12} {s}\n", .{ key, val });357}358359360361pub fn bootHeader(machine: []const u8) void {362 p("{s}boot entries {s}\n\n", .{ hdr(), machine });363}364365pub fn bootEntry(entry: types.BootEntry, idx: usize) void {366 if (entry.current) {367 p(" {s}> {s}{s}{s}\n", .{ c(BOLD), entry.title, if (entry.date) |d| std.fmt.allocPrint(std.heap.page_allocator, " {s}", .{d}) catch " " else "", c(RESET) });368 } else {369 p(" {s} {s}{s}{s}\n", .{ c(DIM), entry.title, if (entry.date) |d| std.fmt.allocPrint(std.heap.page_allocator, " {s}", .{d}) catch " " else "", c(RESET) });370 }371 _ = idx;372}373374375376pub fn serviceListHeader(machine: []const u8) void {377 p("{s}services {s}\n\n", .{ hdr(), machine });378}379380pub fn serviceRow(svc: types.ServiceInfo) void {381 const state_str = switch (svc.state) {382 .active => if (color_enabled) GREEN ++ "active" ++ RESET else "active",383 .failed => if (color_enabled) RED ++ "failed" ++ RESET else "failed",384 .inactive => "inactive",385 .unknown => "unknown",386 };387 const uptime = svc.uptime orelse "";388 p(" {s:<24} {s:<14} {s}\n", .{ svc.name, state_str, uptime });389}390391pub fn serviceVerb(verb: []const u8, name: []const u8, machine: []const u8) void {392 p("{s}{s} {s} {s}\n", .{ hdr(), verb, name, machine });393}394395pub fn serviceDone() void {396 p("{s}done\n", .{hdr()});397}398399pub fn serviceLogsHeader(name: []const u8, n: u32, machine: []const u8) void {400 p("{s}{s} last {d} lines {s}\n\n", .{ hdr(), name, n, machine });401}402403404405pub fn storeInfo(info: types.StoreInfo) void {406 p("{s}store\n\n", .{hdr()});407 p(" {s:<16} {s}\n", .{ "total", info.total_size });408 p(" {s:<16} {d} paths\n", .{ "live", info.live_paths });409 p(" {s:<16} {s}{d} paths{s} run nina clean\n", .{ "reclaimable", c(DIM), info.reclaimable_paths, c(RESET) });410}411412413414pub fn channelListHeader(machine: []const u8) void {415 p("{s}channels {s}\n\n", .{ hdr(), machine });416}417418pub fn channelRow(ch: types.ChannelInfo) void {419 p(" {s:<16} {s}\n", .{ ch.name, ch.url });420}421422423424pub fn flakeUpdateStart() void {425 p("{s}updating inputs\n\n", .{hdr()});426}427428pub fn flakeInput(input: types.FlakeInput) void {429 if (input.changed) {430 const old = if (input.old_rev) |r| r[0..@min(7, r.len)] else "?";431 const new = if (input.new_rev) |r| r[0..@min(7, r.len)] else "?";432 p(" {s:<20} {s} -> {s}\n", .{ input.name, old, new });433 } else {434 p(" {s:<20} {s}no change{s}\n", .{ input.name, c(DIM), c(RESET) });435 }436}437438pub fn flakeLockWritten() void {439 p("\n{s}flake.lock written\n", .{hdr()});440}441442pub fn flakeValid() void {443 p("{s}{s}valid{s}\n", .{ hdr(), c(GREEN), c(RESET) });444}445446pub fn flakeCheckStart() void {447 p("{s}checking flake\n", .{hdr()});448}449450451452pub fn profileListHeader() void {453 p("{s}profile packages\n\n", .{hdr()});454}455456pub fn profileRow(attr: []const u8, pkg_version: []const u8, description: []const u8) void {457 p(" {s:<24} {s:<12} {s}\n", .{ attr, pkg_version, description });458}459460461462pub fn installStart(pkg: []const u8, path: types.InstallPath) void {463 const path_str = switch (path) {464 .profile => "profile",465 .system => "system",466 };467 p("{s}installing {s}{s}{s} {s}\n", .{ hdr(), c(PINK), pkg, c(RESET), path_str });468}469470pub fn installDone(pkg: []const u8) void {471 p("{s}{s}{s}{s} installed {s}available now{s}\n", .{ hdr(), c(PINK), pkg, c(RESET), c(DIM), c(RESET) });472}473474pub fn removeStart(pkg: []const u8) void {475 p("{s}removing {s}{s}{s}\n", .{ hdr(), c(PINK), pkg, c(RESET) });476}477478pub fn installEditorPrompt(pkg: []const u8, config_path: []const u8, line: u32, editor: []const u8) void {479 p("{s}opening {s} add {s}{s}{s} to systemPackages\n", .{ hdr(), config_path, c(PINK), pkg, c(RESET) });480 const cmd = std.fmt.allocPrint(std.heap.page_allocator, "{s} {s} +{d}", .{ editor, config_path, line }) catch editor;481 printSubstep("{s}", .{cmd});482 p("\n {s}save and close when done{s}\n\n", .{ c(DIM), c(RESET) });483}484485pub fn installSelectPrompt(pkg: []const u8, pkg_version: []const u8) void {486 p("{s}{s}{s}{s} {s}\n\n", .{ hdr(), c(PINK), pkg, c(RESET), pkg_version });487 p(" [i] profile install {s}instant no rebuild{s}\n", .{ c(DIM), c(RESET) });488 p(" [s] system install {s}opens editor requires apply{s}\n", .{ c(DIM), c(RESET) });489 p(" [t] try now {s}exits when done{s}\n\n", .{ c(DIM), c(RESET) });490 p(" > ", .{});491 flush();492}493494pub fn tryStart(pkg: []const u8) void {495 p("{s}trying {s}{s}{s} exit when done\n", .{ hdr(), c(PINK), pkg, c(RESET) });496}497498pub fn tryDone() void {499 p("{s}back\n", .{hdr()});500}501502503504pub fn listHeader() void {505 p("{s}installed packages\n\n", .{hdr()});506}507508pub fn listSection(title: []const u8) void {509 p(" {s}{s}{s}\n", .{ c(DIM), title, c(RESET) });510}511512pub fn listPkg(name: []const u8, pkg_version: []const u8) void {513 p(" {s}{s}{s} {s}{s}{s}\n", .{ c(PINK), name, c(RESET), c(DIM), pkg_version, c(RESET) });514}515516517518pub fn hello(machines: []const types.Machine) void {519 p("{s}nina\n\n", .{hdr()});520 for (machines) |m| {521 const kind = if (m.local) "local" else "ssh";522 const detail = if (m.local) "default" else m.host orelse "";523 p(" {s}{s}{s} {s} {s}\n", .{ c(DIM), m.name, c(RESET), kind, detail });524 }525 p("\n", .{});526 const quick = [_][2][]const u8{527 .{ "apply", "rebuild and switch" },528 .{ "search <q>", "find packages" },529 .{ "install <pkg>", "add to profile or system" },530 .{ "status", "machine health" },531 .{ "back", "roll back one generation" },532 .{ "update", "refresh channels" },533 };534 for (quick) |cmd| {535 p(" {s:<16} {s}{s}{s}\n", .{ cmd[0], c(DIM), cmd[1], c(RESET) });536 }537 p("\n", .{});538}539540541542pub fn help() void {543 p("{s}nina {s}nixos helper{s}\n\n", .{ hdr(), c(DIM), c(RESET) });544 const cmds = [_][2][]const u8{545 .{ "apply", "rebuild and switch" },546 .{ "back", "roll back one generation" },547 .{ "go <n>", "switch to generation n" },548 .{ "history", "list all generations" },549 .{ "clean", "remove old generations" },550 .{ "search <q>", "find packages" },551 .{ "install <pkg>", "add to profile or system" },552 .{ "remove <pkg>", "remove from profile or system" },553 .{ "try <pkg>", "test without installing" },554 .{ "list", "show installed packages" },555 .{ "edit", "open configuration.nix" },556 .{ "check", "validate config" },557 .{ "diff", "changes between generations" },558 .{ "status", "machine health" },559 .{ "update", "refresh channels" },560 .{ "upgrade", "update and rebuild" },561 .{ "log", "operation history" },562 .{ "doctor", "diagnose issues" },563 .{ "develop", "enter dev shell" },564 .{ "flake", "flake management" },565 .{ "build", "build a package" },566 .{ "run", "run without installing" },567 .{ "service", "manage services" },568 .{ "store", "nix store tools" },569 .{ "channel", "manage channels" },570 .{ "profile", "user profile packages" },571 .{ "info", "system information" },572 .{ "boot", "boot entries" },573 .{ "fmt", "format configuration.nix" },574 .{ "repl", "nix repl with nixpkgs" },575 .{ "option <q>", "search nixos options" },576 .{ "pkg", "inspect packages" },577 .{ "pin", "pin flake inputs" },578 .{ "hash", "compute nix hash" },579 .{ "fetch", "fetch and hash a url" },580 .{ "goodbye", "uninstall nina" },581 .{ "hello", "list machines" },582 .{ "help", "this message" },583 };584 for (cmds) |cmd| {585 p(" {s:<18} {s}{s}{s}\n", .{ cmd[0], c(DIM), cmd[1], c(RESET) });586 }587 p("\n {s}flags: --on <machine> --dry --check --no-apply --last <n> --all --json{s}\n", .{ c(DIM), c(RESET) });588}589590pub fn version() void {591 p("{s}nina v{s} zig 0.16 zero dependencies\n", .{ hdr(), nina_version.VERSION });592}593594595596pub fn searchResult(pkg: types.NixPackage) void {597 p(" {s}{s}{s} {s}{s}{s} {s}\n", .{ c(PINK), pkg.pname, c(RESET), c(DIM), pkg.version, c(RESET), pkg.description });598}599600pub fn searchHeader(query: []const u8, count: usize) void {601 p("{s}search nixpkgs {s} {s}{d} results{s}\n\n", .{ hdr(), query, c(DIM), count, c(RESET) });602}603604605606pub fn genCurrent(n: u32) void {607 p("{d}\n", .{n});608}609610pub fn done() void {611 p("{s}done\n", .{hdr()});612}613614pub fn runStart(pkg: []const u8) void {615 p("{s}running {s}{s}{s}\n", .{ hdr(), c(PINK), pkg, c(RESET) });616}617618pub fn buildStart(attr: []const u8) void {619 p("{s}building {s}\n", .{ hdr(), attr });620}621622pub fn buildDone() void {623 p("{s}done\n", .{hdr()});624}625626627628pub fn updateSelfStart() void {629 p("{s}checking for updates\n", .{hdr()});630}631632pub fn updateSelfCurrent(ver: []const u8) void {633 p("{s}{s}nina {s} is up to date{s}\n", .{ hdr(), c(GREEN), ver, c(RESET) });634}635636pub fn updateSelfAvailable(current: []const u8, latest: []const u8) void {637 p("{s}current {s}\n", .{ step(), current });638 p("{s}latest {s}{s}{s}\n", .{ step(), c(BOLD), latest, c(RESET) });639}640641pub fn updateSelfDownloading(ver: []const u8, platform: []const u8) void {642 p("{s}downloading nina {s} for {s}\n", .{ step(), ver, platform });643}644645pub fn updateSelfVerifying() void {646 p("{s}verifying checksum\n", .{step()});647}648649pub fn updateSelfInstalling(install_path: []const u8) void {650 p("{s}installing to {s}\n", .{ step(), install_path });651}652653pub fn updateSelfDone(old_ver: []const u8, new_ver: []const u8) void {654 p("{s}updated {s} {s}→{s} {s}\n", .{ hdr(), old_ver, c(DIM), c(RESET), new_ver });655}656657pub fn updateSelfNoPlatform(platform: []const u8) void {658 p("{s}no pre-built binary for {s}\n", .{ hdr(), platform });659 p("{s}check kepr.uk/nina/releases for available platforms\n", .{step()});660}661662pub fn updateSelfNetworkError() void {663 p("{s}{s}\n", .{ if (color_enabled) WARN_C else WARN_P, "could not reach kepr.uk — check your connection" });664}665666pub fn updateSelfChecksumFailed() void {667 p("{s}checksum mismatch — download may be corrupt\n", .{if (color_enabled) ERR_C else ERR_P});668 p("{s}try again or download manually from kepr.uk/nina/releases\n", .{step()});669}670671pub fn updateSelfNixManaged(new_ver: []const u8) void {672 p("{s}upgrading to {s}{s}{s} via nix profile\n", .{ step(), c(BOLD), new_ver, c(RESET) });673}674675pub fn updateSelfNixFailed() void {676 p("{s}nix profile upgrade failed\n", .{if (color_enabled) ERR_C else ERR_P});677 p("{s}try manually: nix profile upgrade '.*nina.*'\n", .{step()});678}679680pub fn updateSelfNixSystemManaged() void {681 p("{s}nina appears to be managed by your NixOS system configuration\n", .{hdr()});682 p("{s}to update: sudo nixos-rebuild switch\n", .{step()});683 p("{s}to reinstall as a profile package: curl -fsSL kepr.uk/nina/install.sh | sh\n", .{step()});684}685686687688pub fn goodbyeStart() void {689 p("{s}uninstalling nina\n", .{hdr()});690}691692pub fn goodbyeFile(path: []const u8) void {693 p("{s}will remove {s}\n", .{ step(), path });694}695696pub fn goodbyeNix() void {697 p("{s}will remove nina from nix profile\n", .{step()});698 p("{s}command: nix profile remove '.*nina.*'\n", .{step()});699}700701pub fn goodbyeNixSystemManaged() void {702 p("{s}nina is managed by your NixOS system configuration\n", .{hdr()});703 p("{s}to remove: delete ~/nina.nix, then run sudo nixos-rebuild switch\n", .{step()});704 p("{s}or remove the nina import from /etc/nixos/configuration.nix directly\n", .{step()});705}706707pub fn goodbyeNixFileFound(path: []const u8) void {708 p("{s}found {s} (NixOS config snippet from the installer)\n", .{ step(), path });709}710711pub fn goodbyeDone() void {712 p("{s}goodbye! reinstall anytime: curl -fsSL kepr.uk/nina/install.sh | sh\n", .{hdr()});713}714715pub fn goodbyeFailed(msg: []const u8) void {716 p("{s}{s}\n", .{ if (color_enabled) ERR_C else ERR_P, msg });717}718719720721pub fn setupCheck() void {722 p("{s}checking nix features\n", .{hdr()});723}724725pub fn setupFeatures(nix_command: bool, flakes: bool) void {726 p("{s}nix-command {s}{s}{s}\n", .{727 step(),728 if (nix_command) c(GREEN) else "",729 if (nix_command) "enabled" else "not enabled",730 if (nix_command) c(RESET) else "",731 });732 p("{s}flakes {s}{s}{s}\n", .{733 step(),734 if (flakes) c(GREEN) else "",735 if (flakes) "enabled" else "not enabled",736 if (flakes) c(RESET) else "",737 });738}739740pub fn setupAllSet() void {741 p("{s}all set\n", .{hdr()});742}743744745746pub fn pinningRegistry() void {747 p("{s}pinning nixpkgs for fast local search...\n", .{hdr()});748 flush();749}750751752753754755pub fn searchPlainHeader(mode_str: []const u8, query: []const u8, count: u64) void {756 p("{s}search {s} {s} {s}{d} results{s}\n", .{ hdr(), mode_str, query, c(DIM), count, c(RESET) });757}758759pub fn searchPlainNoResults() void {760 p(" no results\n", .{});761}762763pub fn searchPlainPackage(pname: []const u8, pkg_version: []const u8, description: []const u8, unfree: bool) void {764 if (unfree) {765 p(" {s} {s}{s}{s} {s}unfree{s} {s}\n", .{ pname, c(DIM), pkg_version, c(RESET), c(YELLOW), c(RESET), description });766 } else {767 p(" {s} {s}{s}{s} {s}\n", .{ pname, c(DIM), pkg_version, c(RESET), description });768 }769}770771pub fn searchPlainOption(name: []const u8, type_str: []const u8) void {772 p(" {s} {s}{s}{s}\n", .{ name, c(DIM), type_str, c(RESET) });773}774775pub fn searchEmptyQuery() void {776 p("{s}search needs a query {s}e.g. nina search firefox{s}\n", .{ hdr(), c(DIM), c(RESET) });777}778779pub fn setupEnabling() void {780 p("{s}enabling experimental features\n", .{hdr()});781}782783pub fn setupDone(path: []const u8, is_nixos: bool) void {784 p("{s}wrote {s}\n", .{ step(), path });785 p("{s}done open a new shell to pick up the change\n", .{hdr()});786 if (is_nixos) {787 printSubstep("to persist across nixos-rebuild, add to configuration.nix:", .{});788 printSubstep(" nix.settings.experimental-features = [ \"nix-command\" \"flakes\" ];", .{});789 }790}791792pub fn pinDone(input: []const u8, commit: []const u8) void {793 p("{s}pinned {s} -> {s}\n", .{ hdr(), input, commit });794}795796pub fn unpinDone(input: []const u8) void {797 p("{s}unpinned {s}\n", .{ hdr(), input });798}799800pub fn hashResult(hash: []const u8) void {801 p("{s}\n", .{hash});802}803804pub fn fetchResult(hash: []const u8, url: []const u8) void {805 _ = url;806 p("{s}\n", .{hash});807}808809pub fn storeRepairStart() void {810 p("{s}repairing store\n", .{hdr()});811}812813pub fn storeVerifyStart() void {814 p("{s}verifying store\n", .{hdr()});815}816817pub fn storeGcDone(freed: []const u8) void {818 p("{s}freed {s}\n", .{ hdr(), freed });819}820821pub fn storePath(path: []const u8) void {822 p("{s}\n", .{path});823}824825pub fn pkgResult(key: []const u8, val: []const u8) void {826 p(" {s:<16} {s}\n", .{ key, val });827}828829pub fn channelDone() void {830 p("{s}done\n", .{hdr()});831}832833pub fn flakeShowHeader(name: []const u8) void {834 p("{s}{s}\n\n", .{ hdr(), name });835}836837pub fn flakeShowEntry(kind: []const u8, name: []const u8, desc: []const u8) void {838 p(" {s:<12} {s:<24} {s}\n", .{ kind, name, desc });839}