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_READY = "( •̀ᴗ•́ ) "; 29const KAO_SAD = "(;ω;) "; 303132pub 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";424344const 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}74757677pub 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}969798pub fn raw(bytes: []const u8) void {99 _w.writeAll(bytes) catch {};100}101102103pub 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}114115116117pub 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 121 if (suggestion) |s| p(" {s}-> {s}{s}\n", .{ c(CYAN), s, c(RESET) });122}123124125126127pub 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}136137138pub fn configMigrated(path: []const u8) void {139 p("{s}{s}config migrated to {s}{s}\n", .{ step(), c(DIM), path, c(RESET) });140}141142pub fn printTeach(cmd: []const u8) void {143 if (teach_enabled) p("{s}{s}{s}\n", .{ teach_pfx(), cmd, c(RESET) });144}145146pub fn printSubstep(comptime fmt: []const u8, args: anytype) void {147 p("{s}", .{step()});148 p(fmt, args);149 p("\n", .{});150}151152153154pub fn confirm(prompt: []const u8) bool {155 p(" {s}continue? [Y/n] ", .{prompt});156 flush();157 var buf: [64]u8 = undefined;158 var i: usize = 0;159 while (i < buf.len) {160 const n = std.posix.read(std.posix.STDIN_FILENO, buf[i .. i + 1]) catch break;161 if (n == 0) break;162 if (buf[i] == '\n') break;163 i += 1;164 }165 const input = std.mem.trim(u8, buf[0..i], " \t");166 if (input.len == 0) return true;167 return input[0] != 'n' and input[0] != 'N';168}169170171172pub fn confirmDefaultNo(question: []const u8) bool {173 p(" {s} [y/N] ", .{question});174 flush();175 var buf: [64]u8 = undefined;176 var i: usize = 0;177 while (i < buf.len) {178 const n = std.posix.read(std.posix.STDIN_FILENO, buf[i .. i + 1]) catch break;179 if (n == 0) break;180 if (buf[i] == '\n') break;181 i += 1;182 }183 const input = std.mem.trim(u8, buf[0..i], " \t");184 if (input.len == 0) return false;185 return input[0] == 'y' or input[0] == 'Y';186}187188189190pub fn applyStart(machine: []const u8) void {191 p("{s}{s}rebuilding {s}...\n", .{ KAO_COZY, hdr(), machine });192}193194195196197pub fn applyDone(gen: u32, elapsed_ms: u64, after_failure: bool) void {198 const face = if (after_failure) KAO_EXCITED else "";199 const secs = @as(f64, @floatFromInt(elapsed_ms)) / 1000.0;200 if (elapsed_ms >= 1000) {201 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) });202 } else {203 p("{s}{s}generation {s}{d}{s}\n", .{ face, hdr(), c(BOLD), gen, c(RESET) });204 }205}206207pub fn applyFailed(translated: []const u8) void {208 p("{s}build failed\n", .{if (color_enabled) ERR_C else ERR_P});209 if (translated.len > 0) p(" {s}{s}{s}\n", .{ c(DIM), translated, c(RESET) });210 p(" {s}-> nina doctor{s}\n", .{ c(DIM), c(RESET) });211}212213pub fn applyDry(machine: []const u8) void {214 p("{s}dry run {s}\n", .{ hdr(), machine });215}216217pub fn applyDryDone() void {218 p("{s}no changes applied\n", .{hdr()});219}220221222223pub fn checkStart(machine: []const u8) void {224 p("{s}checking {s}...\n", .{ hdr(), machine });225}226227pub fn checkOk() void {228 p("{s}{s}ok{s}\n", .{ hdr(), c(GREEN), c(RESET) });229}230231pub fn checkFailed(msg: []const u8) void {232 p("{s}config invalid\n", .{if (color_enabled) ERR_C else ERR_P});233 if (msg.len > 0) p(" {s}{s}{s}\n", .{ c(DIM), msg, c(RESET) });234}235236237238pub fn backStart(machine: []const u8, from: u32, to: u32) void {239 p("{s}rolling back {s} gen {d} -> gen {d}\n", .{ hdr(), machine, from, to });240}241242pub fn goStart(machine: []const u8, current: u32, target: u32) void {243 p("{s}switching {s} gen {d} -> gen {d}\n", .{ hdr(), machine, current, target });244}245246pub fn generationDone(n: u32) void {247 p("{s}done gen {s}{d}{s}\n", .{ hdr(), c(BOLD), n, c(RESET) });248}249250251252253pub fn alreadyOldest() void {254 p("{s}already at the oldest generation\n", .{if (color_enabled) ERR_C else ERR_P});255}256257258259pub fn backDone(n: u32) void {260 p("{s}{s}done gen {s}{d}{s}\n", .{ KAO_GENTLE, hdr(), c(BOLD), n, c(RESET) });261}262263264265pub fn historyHeader(machine: []const u8) void {266 p("{s}generations {s}\n\n", .{ hdr(), machine });267}268269pub fn historyRow(gen: types.GenerationInfo) void {270 if (gen.current) {271 p(" {s}{d}{s} {s} {s} {s}current{s}\n", .{ c(BOLD), gen.number, c(RESET), gen.date, gen.time, c(BOLD), c(RESET) });272 } else {273 p(" {s}{d} {s} {s}{s}\n", .{ c(DIM), gen.number, gen.date, gen.time, c(RESET) });274 }275}276277278279pub fn cleanStart(machine: []const u8, keep: u32, total: u32) void {280 p("{s}cleaning {s} keeping {d} of {d}\n", .{ hdr(), machine, keep, total });281}282283284285pub fn cleanNothing(machine: []const u8, total: u32) void {286 p("{s}cleaning {s}\n\n", .{ hdr(), machine });287 p(" only {d} generation{s} — nothing to remove.\n", .{ total, if (total == 1) "" else "s" });288}289290pub fn cleanDone() void {291 p("{s}{s}done\n", .{ KAO_CONTENT, hdr() });292}293294295296pub fn statusHeader() void {297 p("{s}status\n\n", .{hdr()});298}299300pub fn statusRow(machine: []const u8, gen: u32, time: []const u8, size: []const u8, ok: bool) void {301 if (ok) {302 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) });303 } else {304 p(" {s}{s} {s}unreachable{s}\n", .{ c(RED), machine, "", c(RESET) });305 }306}307308309310pub fn statusHomeRow(gen: u32, detail: []const u8) void {311 if (detail.len > 0) {312 p(" {s} hm gen {d} {s}{s}\n", .{ c(DIM), gen, detail, c(RESET) });313 } else {314 p(" {s} hm gen {d}{s}\n", .{ c(DIM), gen, c(RESET) });315 }316}317318319320pub fn diffHeader(a: u32, b: u32, machine: []const u8) void {321 p("{s}gen {d} -> gen {d} {s}\n\n", .{ hdr(), a, b, machine });322}323324pub fn diffRow(entry: types.DiffEntry) void {325 switch (entry.op) {326 .add => p(" {s}+{s} {s} {s}\n", .{ c(GREEN), c(RESET), entry.package, entry.new_version orelse "" }),327 .remove => p(" {s}-{s} {s} {s}\n", .{ c(RED), c(RESET), entry.package, entry.old_version orelse "" }),328 .change => p(" {s}^{s} {s} {s} -> {s}\n", .{ c(CYAN), c(RESET), entry.package, entry.old_version orelse "", entry.new_version orelse "" }),329 }330}331332333334pub fn doctorHeader(machine: []const u8) void {335 p("{s}diagnosing {s}\n\n", .{ hdr(), machine });336}337338pub fn doctorRow(check: types.DoctorCheck) void {339 const status_str = switch (check.status) {340 .ok => if (color_enabled) GREEN ++ "ok" ++ RESET else "ok",341 .warn => if (color_enabled) YELLOW ++ "warn" ++ RESET else "warn",342 .fail => if (color_enabled) RED ++ "fail" ++ RESET else "fail",343 };344 const note_str = check.note orelse "";345 p(" {s:<16} {s} {s}\n", .{ check.name, status_str, note_str });346}347348pub fn doctorSummary(warnings: u32, failures: u32) void {349 if (failures > 0) {350 p("{s}{d} problems\n", .{ hdr(), failures });351 } else if (warnings > 0) {352 p("{s}{d} warnings\n", .{ hdr(), warnings });353 } else {354 p("{s}{s}{s}all good{s}\n", .{ KAO_HAPPY, hdr(), c(GREEN), c(RESET) });355 }356}357358359360pub fn updateStart(machine: []const u8) void {361 p("{s}updating channels {s}\n\n", .{ hdr(), machine });362}363364pub fn updateChannel(name: []const u8, old: ?[]const u8, new: ?[]const u8) void {365 if (old != null and new != null and !std.mem.eql(u8, old.?, new.?)) {366 p(" {s} {s} -> {s}\n", .{ name, old.?, new.? });367 } else {368 p(" {s} {s}no change{s}\n", .{ name, c(DIM), c(RESET) });369 }370}371372pub fn updateDone() void {373 p("\n{s}done\n", .{hdr()});374}375376377378pub fn upgradeStart(machine: []const u8) void {379 p("{s}upgrading {s}\n", .{ hdr(), machine });380}381382383384pub fn logHeader(machine: []const u8) void {385 p("{s}history {s}\n\n", .{ hdr(), machine });386}387388pub fn logRow(date: []const u8, time: []const u8, action: []const u8, detail: []const u8) void {389 p(" {s}{s} {s}{s} {s:<16} {s}\n", .{ c(DIM), date, time, c(RESET), action, detail });390}391392393394pub fn editOpen(path: []const u8, editor: []const u8) void {395 p("{s}opening {s}\n", .{ hdr(), path });396 printSubstep("{s}", .{editor});397 p("\n {s}run nina check to validate before applying{s}\n", .{ c(DIM), c(RESET) });398}399400401402pub fn fmtStart(path: []const u8) void {403 p("{s}formatting {s}\n", .{ hdr(), path });404}405406pub fn fmtDone() void {407 p("{s}done\n", .{hdr()});408}409410pub fn fmtNeedsFormat() void {411 p("{s}needs formatting {s}run nina fmt to fix{s}\n", .{ hdr(), c(DIM), c(RESET) });412}413414415416pub fn replStart() void {417 p("{s}nix repl {s}nixpkgs loaded{s} :q to exit\n", .{ hdr(), c(DIM), c(RESET) });418}419420421422pub fn developStart(pkgs: []const []const u8) void {423 p("{s}entering dev shell\n\n ", .{hdr()});424 for (pkgs, 0..) |pkg, i| {425 if (i > 0) p(" ", .{});426 p("{s}", .{pkg});427 }428 p("\n\n {s}-> press Ctrl+C or type 'exit' to return{s}\n\n", .{ c(DIM), c(RESET) });429}430431pub fn developDone() void {432 p("{s}{s}back\n", .{ KAO_SLEEPY, hdr() });433}434435436437pub fn infoHeader(machine: []const u8) void {438 p("{s}{s}\n\n", .{ hdr(), machine });439}440441pub fn infoRow(key: []const u8, val: []const u8) void {442 p(" {s:<12} {s}\n", .{ key, val });443}444445446447pub fn bootHeader(machine: []const u8) void {448 p("{s}boot entries {s}\n\n", .{ hdr(), machine });449}450451pub fn bootEntry(entry: types.BootEntry, idx: usize) void {452 if (entry.current) {453 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) });454 } else {455 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) });456 }457 _ = idx;458}459460461462pub fn serviceListHeader(machine: []const u8) void {463 p("{s}services {s}\n\n", .{ hdr(), machine });464}465466pub fn serviceRow(svc: types.ServiceInfo) void {467 const state_str = switch (svc.state) {468 .active => if (color_enabled) GREEN ++ "active" ++ RESET else "active",469 .failed => if (color_enabled) RED ++ "failed" ++ RESET else "failed",470 .inactive => "inactive",471 .unknown => "unknown",472 };473 const uptime = svc.uptime orelse "";474 p(" {s:<24} {s:<14} {s}\n", .{ svc.name, state_str, uptime });475}476477pub fn serviceVerb(verb: []const u8, name: []const u8, machine: []const u8) void {478 p("{s}{s} {s} {s}\n", .{ hdr(), verb, name, machine });479}480481pub fn serviceDone() void {482 p("{s}done\n", .{hdr()});483}484485pub fn serviceLogsHeader(name: []const u8, n: u32, machine: []const u8) void {486 p("{s}{s} last {d} lines {s}\n\n", .{ hdr(), name, n, machine });487}488489490491pub fn storeInfo(info: types.StoreInfo) void {492 p("{s}store\n\n", .{hdr()});493 p(" {s:<16} {s}\n", .{ "total", info.total_size });494 p(" {s:<16} {d} paths\n", .{ "live", info.live_paths });495 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) });496}497498499500pub fn channelListHeader(machine: []const u8) void {501 p("{s}channels {s}\n\n", .{ hdr(), machine });502}503504pub fn channelRow(ch: types.ChannelInfo) void {505 p(" {s:<16} {s}\n", .{ ch.name, ch.url });506}507508509510pub fn flakeUpdateStart() void {511 p("{s}updating inputs\n\n", .{hdr()});512}513514pub fn flakeInput(input: types.FlakeInput) void {515 if (input.changed) {516 const old = if (input.old_rev) |r| r[0..@min(7, r.len)] else "?";517 const new = if (input.new_rev) |r| r[0..@min(7, r.len)] else "?";518 p(" {s:<20} {s} -> {s}\n", .{ input.name, old, new });519 } else {520 p(" {s:<20} {s}no change{s}\n", .{ input.name, c(DIM), c(RESET) });521 }522}523524pub fn flakeLockWritten() void {525 p("\n{s}flake.lock written\n", .{hdr()});526}527528pub fn flakeValid() void {529 p("{s}{s}valid{s}\n", .{ hdr(), c(GREEN), c(RESET) });530}531532pub fn flakeCheckStart() void {533 p("{s}checking flake\n", .{hdr()});534}535536537538pub fn profileListHeader() void {539 p("{s}profile packages\n\n", .{hdr()});540}541542pub fn profileRow(attr: []const u8, pkg_version: []const u8, description: []const u8) void {543 p(" {s:<24} {s:<12} {s}\n", .{ attr, pkg_version, description });544}545546547548549550pub fn didYouMean(query: []const u8, suggestion: []const u8) void {551 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) });552}553554pub fn installStart(pkg: []const u8, path: types.InstallPath) void {555 const path_str = switch (path) {556 .profile => "profile",557 .system => "system",558 };559 p("{s}installing {s}{s}{s} {s}\n", .{ hdr(), c(PINK), pkg, c(RESET), path_str });560}561562pub fn installDone(pkg: []const u8) void {563 p("{s}{s}{s}{s} installed {s}available now{s}\n", .{ hdr(), c(PINK), pkg, c(RESET), c(DIM), c(RESET) });564}565566pub fn removeStart(pkg: []const u8) void {567 p("{s}removing {s}{s}{s}\n", .{ hdr(), c(PINK), pkg, c(RESET) });568}569570571pub fn mood(machine: []const u8, state: []const u8, gen: u32, age: []const u8, size: []const u8) void {572 const healthy = std.mem.eql(u8, state, "running");573 const verdict = if (healthy) "all good" else state;574 const color = if (healthy) GREEN else YELLOW;575 const face = if (healthy) KAO_HAPPY else "";576 p("{s}{s}{s} {s}{s}{s}\n", .{ face, hdr(), machine, c(color), verdict, c(RESET) });577 if (age.len > 0 or size.len > 0) {578 p(" generation {d}, last applied {s}, {s} system closure\n", .{ gen, age, size });579 } else {580 p(" generation {d}\n", .{gen});581 }582}583584pub fn installEditorPrompt(pkg: []const u8, config_path: []const u8, line: u32, editor: []const u8) void {585 p("{s}opening {s} add {s}{s}{s} to systemPackages\n", .{ hdr(), config_path, c(PINK), pkg, c(RESET) });586 const cmd = std.fmt.allocPrint(std.heap.page_allocator, "{s} {s} +{d}", .{ editor, config_path, line }) catch editor;587 printSubstep("{s}", .{cmd});588 p("\n {s}save and close when done{s}\n\n", .{ c(DIM), c(RESET) });589}590591pub fn installSelectPrompt(pkg: []const u8, pkg_version: []const u8) void {592 p("{s}{s}{s}{s} {s}\n\n", .{ hdr(), c(PINK), pkg, c(RESET), pkg_version });593 p(" [i] profile install {s}instant no rebuild{s}\n", .{ c(DIM), c(RESET) });594 p(" [s] system install {s}opens editor requires apply{s}\n", .{ c(DIM), c(RESET) });595 p(" [t] try now {s}exits when done{s}\n\n", .{ c(DIM), c(RESET) });596 p(" > ", .{});597 flush();598}599600pub fn tryStart(pkg: []const u8) void {601 p("{s}trying {s}{s}{s} exit when done\n", .{ hdr(), c(PINK), pkg, c(RESET) });602}603604pub fn tryExitHint() void {605 p(" {s}-> press Ctrl+C or type 'exit' to return{s}\n", .{ c(DIM), c(RESET) });606}607608pub fn tryDone() void {609 p("{s}{s}back\n", .{ KAO_SLEEPY, hdr() });610}611612613614pub fn listHeader(machine: []const u8) void {615 p("{s}packages {s}\n\n", .{ hdr(), machine });616}617618pub fn listSection(title: []const u8) void {619 p(" {s}{s}{s}\n", .{ c(DIM), title, c(RESET) });620}621622623pub fn listPkg(name: []const u8, pkg_version: []const u8) void {624 p(" {s}{s:<16}{s} {s}{s}{s}\n", .{ c(PINK), name, c(RESET), c(DIM), pkg_version, c(RESET) });625}626627pub fn blankLine() void {628 p("\n", .{});629}630631632633pub fn hello(machines: []const types.Machine) void {634 p("{s}{s}nina\n\n", .{ KAO_FACE, hdr() });635 for (machines) |m| {636 const kind = if (m.local) "local" else "ssh";637 const detail = if (m.local) "default" else m.host orelse "";638 p(" {s}{s}{s} {s} {s}\n", .{ c(DIM), m.name, c(RESET), kind, detail });639 }640 p("\n", .{});641 const quick = [_][2][]const u8{642 .{ "apply", "rebuild and switch" },643 .{ "search <q>", "find packages" },644 .{ "install <pkg>", "add to profile or system" },645 .{ "status", "machine health" },646 .{ "back", "roll back one generation" },647 .{ "home apply", "apply home config" },648 .{ "home back", "roll back home config" },649 .{ "home history", "list home generations" },650 .{ "home check", "validate home config" },651 .{ "home diff", "compare home generations" },652 .{ "home packages", "list managed packages" },653 };654 for (quick) |cmd| {655 p(" {s:<16} {s}{s}{s}\n", .{ cmd[0], c(DIM), cmd[1], c(RESET) });656 }657 p("\n", .{});658}659660661662pub fn help() void {663 p("{s}nina {s}NixOS Intuitive Navigation Assistant by Asha Software{s}\n\n", .{ hdr(), c(DIM), c(RESET) });664 const cmds = [_][2][]const u8{665 .{ "apply", "rebuild and switch" },666 .{ "back", "roll back one generation" },667 .{ "go <n>", "switch to generation n" },668 .{ "history", "list all generations" },669 .{ "clean", "remove old generations" },670 .{ "search <q>", "find packages" },671 .{ "install <pkg>", "add to profile or system" },672 .{ "remove <pkg>", "remove from profile or system" },673 .{ "try <pkg>", "test without installing" },674 .{ "list", "show installed packages" },675 .{ "edit", "open configuration.nix" },676 .{ "check", "validate config" },677 .{ "diff", "changes between generations" },678 .{ "status", "machine health" },679 .{ "update", "refresh channels" },680 .{ "upgrade", "update and rebuild" },681 .{ "log", "operation history" },682 .{ "doctor", "diagnose issues" },683 .{ "mood", "plain-language health" },684 .{ "develop", "enter dev shell" },685 .{ "flake", "flake management" },686 .{ "build", "build a package" },687 .{ "run", "run without installing" },688 .{ "service", "manage services" },689 .{ "store", "nix store tools" },690 .{ "channel", "manage channels" },691 .{ "profile", "user profile packages" },692 .{ "home", "home manager commands (apply/back/history/edit/check/diff/packages)" },693 .{ "info", "system information" },694 .{ "boot", "boot entries" },695 .{ "fmt", "format configuration.nix" },696 .{ "repl", "nix repl with nixpkgs" },697 .{ "option <q>", "search nixos options" },698 .{ "pkg", "inspect packages" },699 .{ "why <pkg>", "what pulled a package in" },700 .{ "pin", "pin flake inputs" },701 .{ "hash", "compute nix hash" },702 .{ "fetch", "fetch and hash a url" },703 .{ "goodbye", "uninstall nina" },704 .{ "hello", "list machines" },705 .{ "help", "this message" },706 };707 for (cmds) |cmd| {708 p(" {s:<18} {s}{s}{s}\n", .{ cmd[0], c(DIM), cmd[1], c(RESET) });709 }710 p("\n {s}flags: --on <machine> --dry --check --no-apply --last <n> --all --json --version{s}\n", .{ c(DIM), c(RESET) });711}712713714715pub fn subcommandHelp(group: []const u8, rows: []const [2][]const u8, footer: ?[]const u8) void {716 p("{s}{s} subcommands\n\n", .{ hdr(), group });717 for (rows) |row| {718 p(" {s:<16} {s}{s}{s}\n", .{ row[0], c(DIM), row[1], c(RESET) });719 }720 if (footer) |f| p("\n {s}{s}{s}\n", .{ c(DIM), f, c(RESET) });721 p("\n nina {s} help {s}for this message{s}\n", .{ group, c(DIM), c(RESET) });722}723724pub fn version() void {725 p("{s}nina v{s} zig 0.16 zero dependencies\n", .{ hdr(), nina_version.VERSION });726}727728729730pub fn searchResult(pkg: types.NixPackage) void {731 p(" {s}{s}{s} {s}{s}{s} {s}\n", .{ c(PINK), pkg.pname, c(RESET), c(DIM), pkg.version, c(RESET), pkg.description });732}733734pub fn searchHeader(query: []const u8, count: usize) void {735 p("{s}search nixpkgs {s} {s}{d} results{s}\n\n", .{ hdr(), query, c(DIM), count, c(RESET) });736}737738739740pub fn genCurrent(n: u32) void {741 p("{d}\n", .{n});742}743744pub fn done() void {745 p("{s}done\n", .{hdr()});746}747748pub fn runStart(pkg: []const u8) void {749 p("{s}running {s}{s}{s}\n", .{ hdr(), c(PINK), pkg, c(RESET) });750}751752pub fn buildStart(attr: []const u8) void {753 p("{s}building {s}\n", .{ hdr(), attr });754}755756pub fn buildDone() void {757 p("{s}done\n", .{hdr()});758}759760761762pub fn updateSelfStart() void {763 p("{s}{s}checking for updates\n", .{ KAO_READY, hdr() });764}765766pub fn updateSelfCurrent(ver: []const u8) void {767 p("{s}{s}nina {s} is up to date{s}\n", .{ hdr(), c(GREEN), ver, c(RESET) });768}769770pub fn updateSelfAvailable(current: []const u8, latest: []const u8) void {771 p("{s}update available\n", .{hdr()});772 p("{s}current {s}{s}{s}\n", .{ step(), c(DIM), current, c(RESET) });773 p("{s}latest {s}{s}{s}{s}\n", .{ step(), c(BOLD), c(GREEN), latest, c(RESET) });774}775776fn releaseNotesHeading(line: []const u8) []const u8 {777 var i: usize = 0;778 while (i < line.len and line[i] == '#') : (i += 1) {}779 return std.mem.trim(u8, line[i..], " \t");780}781782fn releaseNotesBullet(line: []const u8) ?[]const u8 {783 if (line.len < 2) return null;784 const marker = line[0];785 if ((marker == '-' or marker == '*' or marker == '+') and line[1] == ' ') return line[2..];786 if (std.ascii.isDigit(marker)) {787 var i: usize = 1;788 while (i < line.len and std.ascii.isDigit(line[i])) : (i += 1) {}789 if (i + 1 < line.len and line[i] == '.' and line[i + 1] == ' ') return line[i + 2 ..];790 }791 return null;792}793794pub fn updateSelfReleaseNotes(notes: []const u8) void {795 const trimmed = std.mem.trim(u8, notes, " \t\r\n");796 if (trimmed.len == 0) return;797798 p("{s}changelog\n", .{hdr()});799 var lines = std.mem.splitScalar(u8, trimmed, '\n');800 while (lines.next()) |raw_line| {801 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;802 const text = std.mem.trim(u8, line, " \t");803 if (text.len == 0) {804 p("\n", .{});805 continue;806 }807 if (text[0] == '#') {808 const title = releaseNotesHeading(text);809 if (title.len == 0) continue;810 p(" {s}{s}{s}{s}\n", .{ c(BOLD), c(CYAN), title, c(RESET) });811 continue;812 }813 if (releaseNotesBullet(text)) |item| {814 p(" {s}- {s}{s}\n", .{ c(CYAN), item, c(RESET) });815 continue;816 }817 p(" {s}\n", .{text});818 }819}820821pub fn updateSelfDownloading(ver: []const u8, platform: []const u8) void {822 p("{s}downloading nina {s} for {s}\n", .{ step(), ver, platform });823}824825pub fn updateSelfVerifying() void {826 p("{s}verifying checksum\n", .{step()});827}828829pub fn updateSelfInstalling(install_path: []const u8) void {830 p("{s}installing to {s}\n", .{ step(), install_path });831}832833pub fn updateSelfDone(old_ver: []const u8, new_ver: []const u8) void {834 p("{s}updated {s} {s}→{s} {s}\n", .{ hdr(), old_ver, c(DIM), c(RESET), new_ver });835}836837pub fn updateSelfNoPlatform(platform: []const u8) void {838 p("{s}no pre-built binary for {s}\n", .{ hdr(), platform });839 p("{s}check kepr.uk/nina/releases for available platforms\n", .{step()});840}841842pub fn updateSelfNetworkError() void {843 p("{s}{s}\n", .{ if (color_enabled) WARN_C else WARN_P, "could not reach kepr.uk — check your connection" });844}845846pub fn updateSelfChecksumFailed() void {847 p("{s}checksum mismatch — download may be corrupt\n", .{if (color_enabled) ERR_C else ERR_P});848 p("{s}try again or download manually from kepr.uk/nina/releases\n", .{step()});849}850851pub fn updateSelfNixManaged(new_ver: []const u8) void {852 p("{s}upgrading to {s}{s}{s} via nix profile\n", .{ step(), c(BOLD), new_ver, c(RESET) });853}854855pub fn updateSelfNixFailed() void {856 p("{s}nix profile upgrade failed\n", .{if (color_enabled) ERR_C else ERR_P});857 p("{s}try manually: nix profile upgrade '.*nina.*'\n", .{step()});858}859860pub fn updateSelfNotInProfile() void {861 p("{s}nina is in the nix store but not found as a profile element\n", .{hdr()});862 p("{s}reinstall via 'nix profile add' to enable self-update\n", .{step()});863}864865866867pub fn goodbyeStart() void {868 p("{s}uninstalling nina\n", .{hdr()});869}870871pub fn goodbyeFile(path: []const u8) void {872 p("{s}will remove {s}\n", .{ step(), path });873}874875pub fn goodbyeNix() void {876 p("{s}will remove nina from nix profile\n", .{step()});877 p("{s}command: nix profile remove nina\n", .{step()});878}879880pub fn goodbyeDone() void {881 p("{s}goodbye! see kepr.uk/nina to reinstall\n", .{hdr()});882}883884pub fn goodbyeFailed(msg: []const u8) void {885 p("{s}{s}\n", .{ if (color_enabled) ERR_C else ERR_P, msg });886}887888889890pub fn setupCheck() void {891 p("{s}checking nix features\n", .{hdr()});892}893894pub fn setupFeatures(nix_command: bool, flakes: bool) void {895 p("{s}nix-command {s}{s}{s}\n", .{896 step(),897 if (nix_command) c(GREEN) else "",898 if (nix_command) "enabled" else "not enabled",899 if (nix_command) c(RESET) else "",900 });901 p("{s}flakes {s}{s}{s}\n", .{902 step(),903 if (flakes) c(GREEN) else "",904 if (flakes) "enabled" else "not enabled",905 if (flakes) c(RESET) else "",906 });907}908909pub fn setupAllSet() void {910 p("{s}all set\n", .{hdr()});911}912913914915pub fn pinningRegistry() void {916 p("{s}pinning nixpkgs for fast local search...\n", .{hdr()});917 flush();918}919920921922923924pub fn searchPlainHeader(mode_str: []const u8, query: []const u8, count: u64) void {925 p("{s}search {s} {s} {s}{d} results{s}\n", .{ hdr(), mode_str, query, c(DIM), count, c(RESET) });926}927928pub fn searchPlainNoResults() void {929 p(" no results\n", .{});930}931932pub fn searchPlainPackage(pname: []const u8, pkg_version: []const u8, description: []const u8, unfree: bool) void {933 if (unfree) {934 p(" {s} {s}{s}{s} {s}unfree{s} {s}\n", .{ pname, c(CYAN), pkg_version, c(RESET), c(YELLOW), c(RESET), description });935 } else {936 p(" {s} {s}{s}{s} {s}\n", .{ pname, c(CYAN), pkg_version, c(RESET), description });937 }938}939940pub fn searchPlainOption(name: []const u8, type_str: []const u8) void {941 p(" {s} {s}{s}{s}\n", .{ name, c(DIM), type_str, c(RESET) });942}943944pub fn searchEmptyQuery() void {945 p("{s}search needs a query {s}e.g. nina search firefox{s}\n", .{ hdr(), c(DIM), c(RESET) });946}947948pub fn setupEnabling() void {949 p("{s}enabling experimental features\n", .{hdr()});950}951952pub fn setupDone(path: []const u8) void {953 p("{s}wrote {s}\n", .{ step(), path });954 p("{s}done open a new shell to pick up the change\n", .{hdr()});955}956957958959pub fn setupNixosOffer(features_line: []const u8, conf_path: []const u8) void {960 p("{s}on NixOS these go in your system config\n", .{hdr()});961 p(" nina can add this line to {s}{s}{s}:\n\n", .{ c(DIM), conf_path, c(RESET) });962 p(" {s}{s}{s}\n\n", .{ c(CYAN), features_line, c(RESET) });963}964965pub fn setupNixosWrote(conf_path: []const u8) void {966 p("{s}added the line to {s} {s}(backup: {s}.nina-bak){s}\n", .{ step(), conf_path, c(DIM), conf_path, c(RESET) });967 p("{s}now run {s}sudo nixos-rebuild switch{s} — then nina's ready\n", .{ hdr(), c(BOLD), c(RESET) });968}969970pub fn setupNixosManual(features_line: []const u8, conf_path: []const u8) void {971 p("{s}no problem — add this line inside the {s}{{ }}{s} in {s}:\n\n", .{ hdr(), c(DIM), c(RESET), conf_path });972 p(" {s}{s}{s}\n\n", .{ c(CYAN), features_line, c(RESET) });973 p(" then run {s}sudo nixos-rebuild switch{s} — then nina's ready\n", .{ c(BOLD), c(RESET) });974}975976pub fn setupNixosNeedsRebuild(conf_path: []const u8) void {977 p("{s}already declared in {s}\n", .{ hdr(), conf_path });978 p(" just run {s}sudo nixos-rebuild switch{s} to activate it\n", .{ c(BOLD), c(RESET) });979}980981pub fn pinDone(input: []const u8, commit: []const u8) void {982 p("{s}pinned {s} -> {s}\n", .{ hdr(), input, commit });983}984985pub fn unpinDone(input: []const u8) void {986 p("{s}unpinned {s}\n", .{ hdr(), input });987}988989pub fn hashResult(hash: []const u8) void {990 p("{s}\n", .{hash});991}992993pub fn fetchResult(hash: []const u8, url: []const u8) void {994 _ = url;995 p("{s}\n", .{hash});996}997998pub fn storeRepairStart() void {999 p("{s}repairing store\n", .{hdr()});1000}10011002pub fn storeVerifyStart() void {1003 p("{s}verifying store\n", .{hdr()});1004}10051006pub fn storeGcDone(freed: []const u8) void {1007 p("{s}freed {s}\n", .{ hdr(), freed });1008}10091010pub fn storePath(path: []const u8) void {1011 p("{s}\n", .{path});1012}10131014pub fn pkgResult(key: []const u8, val: []const u8) void {1015 p(" {s:<16} {s}\n", .{ key, val });1016}10171018pub fn channelDone() void {1019 p("{s}done\n", .{hdr()});1020}10211022pub fn flakeShowHeader(name: []const u8) void {1023 p("{s}{s}\n\n", .{ hdr(), name });1024}10251026pub fn flakeShowEntry(kind: []const u8, name: []const u8, desc: []const u8) void {1027 p(" {s:<12} {s:<24} {s}\n", .{ kind, name, desc });1028}1029103010311032pub fn homeNotInstalled() void {1033 p("{s}home manager not detected {s}nothing to do{s}\n", .{ hdr(), c(DIM), c(RESET) });1034}103510361037pub fn homeModuleManaged() void {1038 p("{s}home manager is managed by your system config\n", .{hdr()});1039 p(" {s}-> run {s}nina apply{s}{s} to rebuild both together{s}\n", .{ c(CYAN), c(BOLD), c(RESET), c(CYAN), c(RESET) });1040}10411042pub fn homeApplyStart(machine: []const u8) void {1043 p("{s}{s}applying home config {s}\n", .{ KAO_COZY, hdr(), machine });1044}10451046pub fn homeApplyDone(gen: u32, elapsed_ms: u64) void {1047 const secs = @as(f64, @floatFromInt(elapsed_ms)) / 1000.0;1048 1049 1050 if (gen == 0) {1051 if (elapsed_ms >= 1000) {1052 p("{s}done {s}[{d:.1}s]{s}\n", .{ hdr(), c(DIM), secs, c(RESET) });1053 } else {1054 p("{s}done\n", .{hdr()});1055 }1056 return;1057 }1058 if (elapsed_ms >= 1000) {1059 p("{s}generation {s}{d}{s} {s}[{d:.1}s]{s}\n", .{ hdr(), c(BOLD), gen, c(RESET), c(DIM), secs, c(RESET) });1060 } else {1061 p("{s}generation {s}{d}{s}\n", .{ hdr(), c(BOLD), gen, c(RESET) });1062 }1063}1064106510661067pub fn homeLocalOnly(machine: []const u8) void {1068 p("{s}home manager commands run on the local machine only\n", .{hdr()});1069 p(" {s}-> '{s}' is remote; run nina home on that machine directly{s}\n", .{ c(DIM), machine, c(RESET) });1070}10711072pub fn homeApplyDry(machine: []const u8) void {1073 p("{s}home dry run {s}\n", .{ hdr(), machine });1074}10751076pub fn homeApplyDryDone() void {1077 p("{s}{s}ok{s} no changes applied\n", .{ hdr(), c(GREEN), c(RESET) });1078}10791080pub fn homeBackStart(machine: []const u8, from: u32, to: u32) void {1081 p("{s}rolling back home config {s} gen {d} -> gen {d}\n", .{ hdr(), machine, from, to });1082}10831084pub fn homeBackDone(n: u32) void {1085 p("{s}{s}done gen {s}{d}{s}\n", .{ KAO_GENTLE, hdr(), c(BOLD), n, c(RESET) });1086}10871088pub fn homeHistoryHeader(machine: []const u8) void {1089 p("{s}home generations {s}\n\n", .{ hdr(), machine });1090}10911092pub fn homeHistoryRow(number: u32, date: []const u8, time: []const u8, current: bool) void {1093 if (current) {1094 p(" {s}{d}{s} {s} {s} {s}current{s}\n", .{ c(BOLD), number, c(RESET), date, time, c(BOLD), c(RESET) });1095 } else {1096 p(" {s}{d} {s} {s}{s}\n", .{ c(DIM), number, date, time, c(RESET) });1097 }1098}10991100pub fn homeEditOpen(path: []const u8, editor: []const u8) void {1101 p("{s}opening {s}\n", .{ hdr(), path });1102 printSubstep("{s}", .{editor});1103}11041105pub fn homeCheckStart(machine: []const u8) void {1106 p("{s}checking home config {s}\n", .{ hdr(), machine });1107}11081109pub fn homeCheckOk() void {1110 p("{s}{s}ok{s}\n", .{ hdr(), c(GREEN), c(RESET) });1111}11121113pub fn homeDiffHeader(a: u32, b: u32, machine: []const u8) void {1114 p("{s}home gen {d} -> gen {d} {s}\n\n", .{ hdr(), a, b, machine });1115}11161117pub fn homeNothingToDiff() void {1118 p("{s}only one home generation — nothing to diff yet\n", .{hdr()});1119}11201121pub fn homePackagesHeader(machine: []const u8) void {1122 p("{s}home packages {s}\n\n", .{ hdr(), machine });1123}1124112511261127pub fn firstRunBanner() void {1128 p("{s}{s}nina \u{2014} first run\n\n", .{ KAO_FACE, hdr() });1129}11301131pub fn firstRunNoConfig() void {1132 p(" no config found. let me get set up.\n\n", .{});1133}11341135113611371138pub fn firstRunPrompt(label: []const u8, default: []const u8, buf: []u8) []const u8 {1139 p(" {s:<14} {s}> {s}", .{ label, c(DIM), c(RESET) });1140 flush();1141 var i: usize = 0;1142 while (i < buf.len - 1) {1143 const n = std.posix.read(std.posix.STDIN_FILENO, buf[i .. i + 1]) catch break;1144 if (n == 0) break;1145 if (buf[i] == '\n') break;1146 i += 1;1147 }1148 const input = std.mem.trim(u8, buf[0..i], " \t\r");1149 if (input.len == 0) {1150 1151 p("{s}{s}{s}\n", .{ c(DIM), default, c(RESET) });1152 flush();1153 return default;1154 }1155 return input;1156}11571158pub fn firstRunScanning() void {1159 p("\n {s}:: scanning for config...{s}\n", .{ c(DIM), c(RESET) });1160}116111621163pub fn firstRunDetected(path: []const u8, is_flake: bool) void {1164 const kind = if (is_flake) "flake-based system" else "channel-based system";1165 p(" {s}-> found {s}{s} {s}({s}){s}\n\n", .{ c(CYAN), path, c(RESET), c(DIM), kind, c(RESET) });1166}11671168pub fn firstRunNoneFound() void {1169 p(" {s}-> nothing found at /etc/nixos{s}\n\n", .{ c(DIM), c(RESET) });1170}1171117211731174pub fn firstRunPromptDefault(label: []const u8, default: []const u8, detected: bool, buf: []u8) []const u8 {1175 if (default.len > 0) {1176 p(" {s:<14} {s}[{s}]{s} > ", .{ label, c(DIM), default, c(RESET) });1177 if (detected) p("{s}enter to confirm{s} ", .{ c(DIM), c(RESET) });1178 } else {1179 p(" {s:<14} {s}> {s}", .{ label, c(DIM), c(RESET) });1180 }1181 flush();1182 var i: usize = 0;1183 while (i < buf.len - 1) {1184 const n = std.posix.read(std.posix.STDIN_FILENO, buf[i .. i + 1]) catch break;1185 if (n == 0) break;1186 if (buf[i] == '\n') break;1187 i += 1;1188 }1189 const input = std.mem.trim(u8, buf[0..i], " \t\r");1190 if (input.len == 0) {1191 p("{s}{s}{s}\n", .{ c(DIM), default, c(RESET) });1192 flush();1193 return default;1194 }1195 return input;1196}1197119811991200pub fn flakeChannelNote() void {1201 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) });1202}12031204pub fn firstRunWritten(path: []const u8) void {1205 p("\n {s}written to {s}{s}\n\n", .{ c(DIM), path, c(RESET) });1206}12071208pub fn firstRunSkipped() void {1209 p("\n {s}skipping setup in non-interactive mode{s}\n", .{ c(DIM), c(RESET) });1210}