123const std = @import("std");4const types = @import("types.zig");5const nina_version = @import("version.zig");6const errors = @import("errors.zig");7const Io = std.Io;8910const PINK = "\x1b[38;2;255;183;197m";11const BOLD = "\x1b[1m";12const GREEN = "\x1b[32m";13const YELLOW = "\x1b[33m";14const RED = "\x1b[31m";15const CYAN = "\x1b[36m";16const DIM = "\x1b[2m";17const RESET = "\x1b[0m";1819202122const KAO_FACE = "(˶ᵔ ᵕ ᵔ˶) "; 23const KAO_COZY = "(っ˘ω˘ς) "; 24const KAO_EXCITED = "╰(*°▽°*)╯ "; 25const KAO_GENTLE = "( ˘ᵕ˘ ) "; 26const KAO_CONTENT = "( ´ ∀ ` ) "; 27const KAO_HAPPY = "( ´ ▽ ` ) "; 28const KAO_SLEEPY = "(˘ω˘ ) "; 29const KAO_READY = "( •̀ᴗ•́ ) "; 30const KAO_SAD = "(;ω;) "; 313233pub const C_PINK = PINK;34pub const C_BOLD = BOLD;35pub const C_GREEN = GREEN;36pub const C_YELLOW = YELLOW;37pub const C_RED = RED;38pub const C_CYAN = CYAN;39pub const C_DIM = DIM;40pub const C_RESET = RESET;41pub const C_CLEAR_EOL = "\x1b[K";42pub const C_CURSOR_UP_FMT = "\x1b[{d}A";434445const HDR_C = PINK ++ ":: " ++ RESET;46const HDR_P = ":: ";47const STEP_C = " " ++ DIM ++ "-> " ++ RESET;48const STEP_P = " -> ";49const TEACH_C = " " ++ DIM ++ "= " ++ RESET;50const TEACH_P = " = ";51const ERR_C = PINK ++ ":: " ++ RED ++ "error:" ++ RESET ++ " ";52const ERR_P = ":: error: ";53const WARN_C = PINK ++ ":: " ++ YELLOW ++ "warning:" ++ RESET ++ " ";54const WARN_P = ":: warning: ";5556var _fw: Io.File.Writer = undefined;57var _w: *Io.Writer = undefined;58var color_enabled: bool = true;59var teach_enabled: bool = false;6061pub fn init(writer: *Io.Writer, io: std.Io, environ: *const std.process.Environ.Map, color_config: bool) void {62 _w = writer;63 color_enabled = color_config and64 (std.Io.File.stdout().isTty(io) catch false) and65 !environ.contains("NO_COLOR");66}6768pub fn setTeach(enabled: bool) void {69 teach_enabled = enabled;70}7172pub fn flush() void {73 _w.flush() catch {};74}75767778pub fn colorEnabled() bool {79 return color_enabled;80}8182fn c(code: []const u8) []const u8 {83 return if (color_enabled) code else "";84}8586fn hdr() []const u8 {87 return if (color_enabled) HDR_C else HDR_P;88}8990fn step() []const u8 {91 return if (color_enabled) STEP_C else STEP_P;92}9394fn teach_pfx() []const u8 {95 return if (color_enabled) TEACH_C else TEACH_P;96}979899pub fn raw(bytes: []const u8) void {100 _w.writeAll(bytes) catch {};101}102103104pub fn p(comptime fmt: []const u8, args: anytype) void {105 _w.print(fmt, args) catch {};106}107108pub fn cursorUp(n: usize) void {109 if (n > 0) p("\x1b[{d}A", .{n});110}111112pub fn clearLine() void {113 p("\r\x1b[K", .{});114}115116117118pub fn printError(message: []const u8, detail: ?[]const u8, suggestion: ?[]const u8) void {119 p("{s}{s}\n", .{ if (color_enabled) ERR_C else ERR_P, message });120 if (detail) |d| p(" {s}{s}{s}\n", .{ c(DIM), d, c(RESET) });121 122 if (suggestion) |s| p(" {s}-> {s}{s}\n", .{ c(CYAN), s, c(RESET) });123}124125126127128pub fn printSystemError(message: []const u8, detail: ?[]const u8, suggestion: ?[]const u8) void {129 p("{s}{s}{s}\n", .{ KAO_SAD, if (color_enabled) ERR_C else ERR_P, message });130 if (detail) |d| p(" {s}{s}{s}\n", .{ c(DIM), d, c(RESET) });131 if (suggestion) |s| p(" {s}-> {s}{s}\n", .{ c(CYAN), s, c(RESET) });132}133134pub fn printWarning(message: []const u8) void {135 p("{s}{s}\n", .{ if (color_enabled) WARN_C else WARN_P, message });136}137138139140141142pub fn buildError(err: errors.TranslatedError) void {143 if (err.is_system) {144 145 p("{s}{s}{s}\n\n", .{ KAO_SAD, if (color_enabled) ERR_C else ERR_P, err.title });146 } else {147 p("{s}{s}\n\n", .{ if (color_enabled) ERR_C else ERR_P, err.title });148 }149150 var body_lines = std.mem.splitScalar(u8, err.body, '\n');151 while (body_lines.next()) |line| {152 if (line.len == 0) continue;153 p(" {s}\n", .{line});154 }155156 if (err.location) |loc| {157 p("{s} {s}{s}\n", .{ c(DIM), loc, c(RESET) });158 }159160 p("\n", .{});161162 var sug_lines = std.mem.splitScalar(u8, err.suggestion, '\n');163 var first = true;164 while (sug_lines.next()) |line| {165 if (line.len == 0) continue;166 if (first) {167 p("{s} -> {s}{s}\n", .{ c(CYAN), line, c(RESET) });168 first = false;169 } else {170 p("{s} {s}{s}\n", .{ c(DIM), line, c(RESET) });171 }172 }173}174175176177pub fn buildWarnings(warnings: []const []const u8) void {178 for (warnings) |w| {179 p("{s} \u{26a0} {s}{s}\n", .{ c(YELLOW), w, c(RESET) });180 }181}182183pub fn aborted() void {184 p("{s}aborted\n", .{hdr()});185}186187188pub fn configMigrated(path: []const u8) void {189 p("{s}{s}config migrated to {s}{s}\n", .{ step(), c(DIM), path, c(RESET) });190}191192pub fn printTeach(cmd: []const u8) void {193 if (teach_enabled) p("{s}{s}{s}\n", .{ teach_pfx(), cmd, c(RESET) });194}195196pub fn printSubstep(comptime fmt: []const u8, args: anytype) void {197 p("{s}", .{step()});198 p(fmt, args);199 p("\n", .{});200}201202pub fn hookFailed(name: []const u8, code: u8, hook_output: []const u8) void {203 p("{s}{s} hook exited with code {d}{s}\n\n", .{ hdr(), name, code, c(RESET) });204205 if (hook_output.len > 0) {206 var lines = std.mem.splitScalar(u8, hook_output, '\n');207 var shown: [5][]const u8 = undefined;208 var count: usize = 0;209 while (lines.next()) |line| {210 const trimmed = std.mem.trim(u8, line, " \t\r");211 if (trimmed.len == 0) continue;212 shown[count % shown.len] = trimmed;213 count += 1;214 }215216 const display_count = @min(count, shown.len);217 const start = count - display_count;218 for (0..display_count) |i| {219 const line = shown[(start + i) % shown.len];220 p(" {s}{s}{s}\n", .{ c(DIM), line, c(RESET) });221 }222 p("\n", .{});223 }224}225226pub fn hookWarning(name: []const u8, code: u8, hook_output: []const u8) void {227 _ = hook_output;228 p("{s} warning: {s} hook exited with code {d}{s}\n", .{ c(YELLOW), name, code, c(RESET) });229}230231232233pub fn confirm(prompt: []const u8) bool {234 p(" {s}continue? [Y/n] ", .{prompt});235 flush();236 var buf: [64]u8 = undefined;237 var i: usize = 0;238 while (i < buf.len) {239 const n = std.posix.read(std.posix.STDIN_FILENO, buf[i .. i + 1]) catch break;240 if (n == 0) break;241 if (buf[i] == '\n') break;242 i += 1;243 }244 const input = std.mem.trim(u8, buf[0..i], " \t");245 if (input.len == 0) return true;246 return input[0] != 'n' and input[0] != 'N';247}248249250251pub fn confirmDefaultNo(question: []const u8) bool {252 p(" {s} [y/N] ", .{question});253 flush();254 var buf: [64]u8 = undefined;255 var i: usize = 0;256 while (i < buf.len) {257 const n = std.posix.read(std.posix.STDIN_FILENO, buf[i .. i + 1]) catch break;258 if (n == 0) break;259 if (buf[i] == '\n') break;260 i += 1;261 }262 const input = std.mem.trim(u8, buf[0..i], " \t");263 if (input.len == 0) return false;264 return input[0] == 'y' or input[0] == 'Y';265}266267268269pub fn applyStart(machine: []const u8) void {270 p("{s}{s}rebuilding {s}...\n", .{ KAO_COZY, hdr(), machine });271}272273274275276pub fn applyDone(gen: u32, elapsed_ms: u64, after_failure: bool) void {277 const face = if (after_failure) KAO_EXCITED else "";278 const secs = @as(f64, @floatFromInt(elapsed_ms)) / 1000.0;279 if (elapsed_ms >= 1000) {280 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) });281 } else {282 p("{s}{s}generation {s}{d}{s}\n", .{ face, hdr(), c(BOLD), gen, c(RESET) });283 }284}285286pub fn applyFailed(translated: []const u8) void {287 p("{s}build failed\n", .{if (color_enabled) ERR_C else ERR_P});288 if (translated.len > 0) p(" {s}{s}{s}\n", .{ c(DIM), translated, c(RESET) });289 p(" {s}-> nina doctor{s}\n", .{ c(DIM), c(RESET) });290}291292pub fn applyDry(machine: []const u8) void {293 p("{s}dry run {s}\n", .{ hdr(), machine });294}295296pub fn applyDryDone() void {297 p("{s}no changes applied\n", .{hdr()});298}299300301302pub fn checkStart(machine: []const u8) void {303 p("{s}checking {s}...\n", .{ hdr(), machine });304}305306pub fn checkOk() void {307 p("{s}{s}ok{s}\n", .{ hdr(), c(GREEN), c(RESET) });308}309310pub fn checkFailed(msg: []const u8) void {311 p("{s}config invalid\n", .{if (color_enabled) ERR_C else ERR_P});312 if (msg.len > 0) p(" {s}{s}{s}\n", .{ c(DIM), msg, c(RESET) });313}314315316317pub fn backStart(machine: []const u8, from: u32, to: u32) void {318 p("{s}rolling back {s} gen {d} -> gen {d}\n", .{ hdr(), machine, from, to });319}320321pub fn goStart(machine: []const u8, current: u32, target: u32) void {322 p("{s}switching {s} gen {d} -> gen {d}\n", .{ hdr(), machine, current, target });323}324325pub fn generationDone(n: u32) void {326 p("{s}done gen {s}{d}{s}\n", .{ hdr(), c(BOLD), n, c(RESET) });327}328329330331332pub fn alreadyOldest() void {333 p("{s}already at the oldest generation\n", .{if (color_enabled) ERR_C else ERR_P});334}335336337338pub fn backDone(n: u32) void {339 p("{s}{s}done gen {s}{d}{s}\n", .{ KAO_GENTLE, hdr(), c(BOLD), n, c(RESET) });340}341342343344pub fn historyHeader(machine: []const u8) void {345 p("{s}generations {s}\n\n", .{ hdr(), machine });346}347348pub fn historyRow(gen: types.GenerationInfo) void {349 if (gen.current) {350 p(" {s}{d}{s} {s} {s} {s}current{s}\n", .{ c(BOLD), gen.number, c(RESET), gen.date, gen.time, c(BOLD), c(RESET) });351 } else {352 p(" {s}{d} {s} {s}{s}\n", .{ c(DIM), gen.number, gen.date, gen.time, c(RESET) });353 }354}355356357358pub fn cleanStart(machine: []const u8, keep: u32, total: u32) void {359 p("{s}cleaning {s} keeping {d} of {d}\n", .{ hdr(), machine, keep, total });360}361362363364pub fn cleanNothing(machine: []const u8, total: u32) void {365 p("{s}cleaning {s}\n\n", .{ hdr(), machine });366 p(" only {d} generation{s} — nothing to remove.\n", .{ total, if (total == 1) "" else "s" });367}368369pub fn cleanDone() void {370 p("{s}{s}done\n", .{ KAO_CONTENT, hdr() });371}372373374375pub fn statusHeader() void {376 p("{s}status\n\n", .{hdr()});377}378379pub fn statusRow(machine: []const u8, gen: u32, time: []const u8, size: []const u8, ok: bool) void {380 if (ok) {381 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) });382 } else {383 p(" {s}{s} {s}unreachable{s}\n", .{ c(RED), machine, "", c(RESET) });384 }385}386387388389pub fn statusHomeRow(gen: u32, detail: []const u8) void {390 if (detail.len > 0) {391 p(" {s} hm gen {d} {s}{s}\n", .{ c(DIM), gen, detail, c(RESET) });392 } else {393 p(" {s} hm gen {d}{s}\n", .{ c(DIM), gen, c(RESET) });394 }395}396397398399pub fn diffHeader(a: u32, b: u32, machine: []const u8) void {400 p("{s}gen {d} -> gen {d} {s}\n\n", .{ hdr(), a, b, machine });401}402403pub fn diffRow(entry: types.DiffEntry) void {404 switch (entry.op) {405 .add => p(" {s}+{s} {s} {s}\n", .{ c(GREEN), c(RESET), entry.package, entry.new_version orelse "" }),406 .remove => p(" {s}-{s} {s} {s}\n", .{ c(RED), c(RESET), entry.package, entry.old_version orelse "" }),407 .change => p(" {s}^{s} {s} {s} -> {s}\n", .{ c(CYAN), c(RESET), entry.package, entry.old_version orelse "", entry.new_version orelse "" }),408 }409}410411412413pub fn doctorHeader(machine: []const u8) void {414 p("{s}diagnosing {s}\n\n", .{ hdr(), machine });415}416417pub fn doctorRow(check: types.DoctorCheck) void {418 const status_str = switch (check.status) {419 .ok => if (color_enabled) GREEN ++ "ok" ++ RESET else "ok",420 .warn => if (color_enabled) YELLOW ++ "warn" ++ RESET else "warn",421 .fail => if (color_enabled) RED ++ "fail" ++ RESET else "fail",422 };423 const note_str = check.note orelse "";424 p(" {s:<16} {s} {s}\n", .{ check.name, status_str, note_str });425}426427pub fn doctorSummary(warnings: u32, failures: u32) void {428 if (failures > 0) {429 p("{s}{d} problems\n", .{ hdr(), failures });430 } else if (warnings > 0) {431 p("{s}{d} warnings\n", .{ hdr(), warnings });432 } else {433 p("{s}{s}{s}all good{s}\n", .{ KAO_HAPPY, hdr(), c(GREEN), c(RESET) });434 }435}436437438439pub fn updateStart(machine: []const u8) void {440 p("{s}updating channels {s}\n\n", .{ hdr(), machine });441}442443pub fn updateChannel(name: []const u8, old: ?[]const u8, new: ?[]const u8) void {444 if (old != null and new != null and !std.mem.eql(u8, old.?, new.?)) {445 p(" {s} {s} -> {s}\n", .{ name, old.?, new.? });446 } else {447 p(" {s} {s}no change{s}\n", .{ name, c(DIM), c(RESET) });448 }449}450451pub fn updateDone() void {452 p("\n{s}done\n", .{hdr()});453}454455456457pub fn upgradeStart(machine: []const u8) void {458 p("{s}upgrading {s}\n", .{ hdr(), machine });459}460461462463pub fn logHeader(machine: []const u8) void {464 p("{s}history {s}\n\n", .{ hdr(), machine });465}466467pub fn logRow(date: []const u8, time: []const u8, action: []const u8, detail: []const u8) void {468 p(" {s}{s} {s}{s} {s:<16} {s}\n", .{ c(DIM), date, time, c(RESET), action, detail });469}470471472473pub fn editOpen(path: []const u8, editor: []const u8) void {474 p("{s}opening {s}\n", .{ hdr(), path });475 printSubstep("{s}", .{editor});476 p("\n {s}run nina check to validate before applying{s}\n", .{ c(DIM), c(RESET) });477}478479480481pub fn fmtStart(path: []const u8) void {482 p("{s}formatting {s}\n", .{ hdr(), path });483}484485pub fn fmtDone() void {486 p("{s}done\n", .{hdr()});487}488489pub fn fmtNeedsFormat() void {490 p("{s}needs formatting {s}run nina fmt to fix{s}\n", .{ hdr(), c(DIM), c(RESET) });491}492493494495pub fn replStart() void {496 p("{s}nix repl {s}nixpkgs loaded{s} :q to exit\n", .{ hdr(), c(DIM), c(RESET) });497}498499500501pub fn developStart(pkgs: []const []const u8) void {502 p("{s}entering dev shell\n\n ", .{hdr()});503 for (pkgs, 0..) |pkg, i| {504 if (i > 0) p(" ", .{});505 p("{s}", .{pkg});506 }507 p("\n\n {s}-> press Ctrl+C or type 'exit' to return{s}\n\n", .{ c(DIM), c(RESET) });508}509510pub fn developDone() void {511 p("{s}{s}back\n", .{ KAO_SLEEPY, hdr() });512}513514515516pub fn infoHeader(machine: []const u8) void {517 p("{s}{s}\n\n", .{ hdr(), machine });518}519520pub fn infoRow(key: []const u8, val: []const u8) void {521 p(" {s:<12} {s}\n", .{ key, val });522}523524525526pub fn bootHeader(machine: []const u8) void {527 p("{s}boot entries {s}\n\n", .{ hdr(), machine });528}529530pub fn bootEntry(entry: types.BootEntry, idx: usize) void {531 if (entry.current) {532 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) });533 } else {534 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) });535 }536 _ = idx;537}538539540541pub fn serviceListHeader(machine: []const u8) void {542 p("{s}services {s}\n\n", .{ hdr(), machine });543}544545pub fn serviceRow(svc: types.ServiceInfo) void {546 const state_str = switch (svc.state) {547 .active => if (color_enabled) GREEN ++ "active" ++ RESET else "active",548 .failed => if (color_enabled) RED ++ "failed" ++ RESET else "failed",549 .inactive => "inactive",550 .unknown => "unknown",551 };552 const uptime = svc.uptime orelse "";553 p(" {s:<24} {s:<14} {s}\n", .{ svc.name, state_str, uptime });554}555556pub fn serviceVerb(verb: []const u8, name: []const u8, machine: []const u8) void {557 p("{s}{s} {s} {s}\n", .{ hdr(), verb, name, machine });558}559560pub fn serviceDone() void {561 p("{s}done\n", .{hdr()});562}563564pub fn serviceLogsHeader(name: []const u8, n: u32, machine: []const u8) void {565 p("{s}{s} last {d} lines {s}\n\n", .{ hdr(), name, n, machine });566}567568569570pub fn storeInfo(info: types.StoreInfo) void {571 p("{s}store\n\n", .{hdr()});572 p(" {s:<16} {s}\n", .{ "total", info.total_size });573 p(" {s:<16} {d} paths\n", .{ "live", info.live_paths });574 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) });575}576577578579pub fn channelListHeader(machine: []const u8) void {580 p("{s}channels {s}\n\n", .{ hdr(), machine });581}582583pub fn channelRow(ch: types.ChannelInfo) void {584 p(" {s:<16} {s}\n", .{ ch.name, ch.url });585}586587588589pub fn flakeUpdateStart() void {590 p("{s}updating inputs\n\n", .{hdr()});591}592593pub fn flakeInput(input: types.FlakeInput) void {594 if (input.changed) {595 const old = if (input.old_rev) |r| r[0..@min(7, r.len)] else "?";596 const new = if (input.new_rev) |r| r[0..@min(7, r.len)] else "?";597 p(" {s:<20} {s} -> {s}\n", .{ input.name, old, new });598 } else {599 p(" {s:<20} {s}no change{s}\n", .{ input.name, c(DIM), c(RESET) });600 }601}602603pub fn flakeLockWritten() void {604 p("\n{s}flake.lock written\n", .{hdr()});605}606607pub fn flakeValid() void {608 p("{s}{s}valid{s}\n", .{ hdr(), c(GREEN), c(RESET) });609}610611pub fn flakeCheckStart() void {612 p("{s}checking flake\n", .{hdr()});613}614615616617pub fn profileListHeader() void {618 p("{s}profile packages\n\n", .{hdr()});619}620621pub fn profileRow(attr: []const u8, pkg_version: []const u8, description: []const u8) void {622 p(" {s:<24} {s:<12} {s}\n", .{ attr, pkg_version, description });623}624625626627628629pub fn didYouMean(query: []const u8, suggestion: []const u8) void {630 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) });631}632633pub fn installStart(pkg: []const u8, path: types.InstallPath) void {634 const path_str = switch (path) {635 .profile => "profile",636 .system => "system",637 };638 p("{s}installing {s}{s}{s} {s}\n", .{ hdr(), c(PINK), pkg, c(RESET), path_str });639}640641pub fn installDone(pkg: []const u8) void {642 p("{s}{s}{s}{s} installed {s}available now{s}\n", .{ hdr(), c(PINK), pkg, c(RESET), c(DIM), c(RESET) });643}644645pub fn removeStart(pkg: []const u8) void {646 p("{s}removing {s}{s}{s}\n", .{ hdr(), c(PINK), pkg, c(RESET) });647}648649650pub fn mood(machine: []const u8, state: []const u8, gen: u32, age: []const u8, size: []const u8) void {651 const healthy = std.mem.eql(u8, state, "running");652 const verdict = if (healthy) "all good" else state;653 const color = if (healthy) GREEN else YELLOW;654 const face = if (healthy) KAO_HAPPY else "";655 p("{s}{s}{s} {s}{s}{s}\n", .{ face, hdr(), machine, c(color), verdict, c(RESET) });656 if (age.len > 0 or size.len > 0) {657 p(" generation {d}, last applied {s}, {s} system closure\n", .{ gen, age, size });658 } else {659 p(" generation {d}\n", .{gen});660 }661}662663pub fn installEditorPrompt(pkg: []const u8, config_path: []const u8, line: u32, editor: []const u8) void {664 p("{s}opening {s} add {s}{s}{s} to systemPackages\n", .{ hdr(), config_path, c(PINK), pkg, c(RESET) });665 const cmd = std.fmt.allocPrint(std.heap.page_allocator, "{s} {s} +{d}", .{ editor, config_path, line }) catch editor;666 printSubstep("{s}", .{cmd});667 p("\n {s}save and close when done{s}\n\n", .{ c(DIM), c(RESET) });668}669670pub fn installSelectPrompt(pkg: []const u8, pkg_version: []const u8) void {671 p("{s}{s}{s}{s} {s}\n\n", .{ hdr(), c(PINK), pkg, c(RESET), pkg_version });672 p(" [i] profile install {s}instant no rebuild{s}\n", .{ c(DIM), c(RESET) });673 p(" [s] system install {s}opens editor requires apply{s}\n", .{ c(DIM), c(RESET) });674 p(" [t] try now {s}exits when done{s}\n\n", .{ c(DIM), c(RESET) });675 p(" > ", .{});676 flush();677}678679pub fn tryStart(pkg: []const u8) void {680 p("{s}trying {s}{s}{s} exit when done\n", .{ hdr(), c(PINK), pkg, c(RESET) });681}682683pub fn tryExitHint() void {684 p(" {s}-> press Ctrl+C or type 'exit' to return{s}\n", .{ c(DIM), c(RESET) });685}686687pub fn tryDone() void {688 p("{s}{s}back\n", .{ KAO_SLEEPY, hdr() });689}690691692693pub fn listHeader(machine: []const u8) void {694 p("{s}packages {s}\n\n", .{ hdr(), machine });695}696697pub fn listSection(title: []const u8) void {698 p(" {s}{s}{s}\n", .{ c(DIM), title, c(RESET) });699}700701702pub fn listPkg(name: []const u8, pkg_version: []const u8) void {703 p(" {s}{s:<16}{s} {s}{s}{s}\n", .{ c(PINK), name, c(RESET), c(DIM), pkg_version, c(RESET) });704}705706pub fn blankLine() void {707 p("\n", .{});708}709710711712pub fn hello(machines: []const types.Machine) void {713 p("{s}{s}nina\n\n", .{ KAO_FACE, hdr() });714 for (machines) |m| {715 const kind = if (m.local) "local" else "ssh";716 const detail = if (m.local) "default" else m.host orelse "";717 p(" {s}{s}{s} {s} {s}\n", .{ c(DIM), m.name, c(RESET), kind, detail });718 }719 p("\n", .{});720 const quick = [_][2][]const u8{721 .{ "apply", "rebuild and switch" },722 .{ "search <q>", "find packages" },723 .{ "install <pkg>", "add to profile or system" },724 .{ "status", "machine health" },725 .{ "back", "roll back one generation" },726 .{ "home apply", "apply home config" },727 .{ "home back", "roll back home config" },728 .{ "home history", "list home generations" },729 .{ "home check", "validate home config" },730 .{ "home diff", "compare home generations" },731 .{ "home packages", "list managed packages" },732 };733 for (quick) |cmd| {734 p(" {s:<16} {s}{s}{s}\n", .{ cmd[0], c(DIM), cmd[1], c(RESET) });735 }736 p("\n", .{});737}738739740741pub fn help() void {742 p("{s}nina {s}NixOS Intuitive Navigation Assistant by Asha Software{s}\n\n", .{ hdr(), c(DIM), c(RESET) });743 const cmds = [_][2][]const u8{744 .{ "apply", "rebuild and switch" },745 .{ "back", "roll back one generation" },746 .{ "go <n>", "switch to generation n" },747 .{ "history", "list all generations" },748 .{ "clean", "remove old generations" },749 .{ "search <q>", "find packages" },750 .{ "install <pkg>", "add to profile or system" },751 .{ "remove <pkg>", "remove from profile or system" },752 .{ "try <pkg>", "test without installing" },753 .{ "list", "show installed packages" },754 .{ "edit", "open configuration.nix" },755 .{ "check", "validate config" },756 .{ "diff", "changes between generations" },757 .{ "status", "machine health" },758 .{ "update", "refresh channels" },759 .{ "upgrade", "update and rebuild" },760 .{ "log", "operation history" },761 .{ "doctor", "diagnose issues" },762 .{ "mood", "plain-language health" },763 .{ "develop", "enter dev shell" },764 .{ "flake", "flake management" },765 .{ "build", "build a package" },766 .{ "run", "run without installing" },767 .{ "service", "manage services" },768 .{ "store", "nix store tools" },769 .{ "channel", "manage channels" },770 .{ "profile", "user profile packages" },771 .{ "home", "home manager commands (apply/back/history/edit/check/diff/packages)" },772 .{ "info", "system information" },773 .{ "boot", "boot entries" },774 .{ "fmt", "format configuration.nix" },775 .{ "repl", "nix repl with nixpkgs" },776 .{ "option <q>", "search nixos options" },777 .{ "pkg", "inspect packages" },778 .{ "why <pkg>", "what pulled a package in" },779 .{ "pin", "pin flake inputs" },780 .{ "hash", "compute nix hash" },781 .{ "fetch", "fetch and hash a url" },782 .{ "goodbye", "uninstall nina" },783 .{ "hello", "list machines" },784 .{ "help", "this message" },785 };786 for (cmds) |cmd| {787 p(" {s:<18} {s}{s}{s}\n", .{ cmd[0], c(DIM), cmd[1], c(RESET) });788 }789 p("\n {s}flags: --on <machine> --dry --check --no-apply --last <n> --all --json --version{s}\n", .{ c(DIM), c(RESET) });790}791792793794pub fn subcommandHelp(group: []const u8, rows: []const [2][]const u8, footer: ?[]const u8) void {795 p("{s}{s} subcommands\n\n", .{ hdr(), group });796 for (rows) |row| {797 p(" {s:<16} {s}{s}{s}\n", .{ row[0], c(DIM), row[1], c(RESET) });798 }799 if (footer) |f| p("\n {s}{s}{s}\n", .{ c(DIM), f, c(RESET) });800 p("\n nina {s} help {s}for this message{s}\n", .{ group, c(DIM), c(RESET) });801}802803pub fn version() void {804 p("{s}nina v{s} zig 0.16 zero dependencies\n", .{ hdr(), nina_version.VERSION });805}806807808809pub fn searchResult(pkg: types.NixPackage) void {810 p(" {s}{s}{s} {s}{s}{s} {s}\n", .{ c(PINK), pkg.pname, c(RESET), c(DIM), pkg.version, c(RESET), pkg.description });811}812813pub fn searchHeader(query: []const u8, count: usize) void {814 p("{s}search nixpkgs {s} {s}{d} results{s}\n\n", .{ hdr(), query, c(DIM), count, c(RESET) });815}816817818819pub fn genCurrent(n: u32) void {820 p("{d}\n", .{n});821}822823pub fn done() void {824 p("{s}done\n", .{hdr()});825}826827pub fn runStart(pkg: []const u8) void {828 p("{s}running {s}{s}{s}\n", .{ hdr(), c(PINK), pkg, c(RESET) });829}830831pub fn buildStart(attr: []const u8) void {832 p("{s}building {s}\n", .{ hdr(), attr });833}834835pub fn buildDone() void {836 p("{s}done\n", .{hdr()});837}838839840841pub fn updateSelfStart() void {842 p("{s}{s}checking for updates\n", .{ KAO_READY, hdr() });843}844845pub fn updateSelfCurrent(ver: []const u8) void {846 p("{s}{s}nina {s} is up to date{s}\n", .{ hdr(), c(GREEN), ver, c(RESET) });847}848849pub fn updateSelfAvailable(current: []const u8, latest: []const u8) void {850 p("{s}update available\n", .{hdr()});851 p("{s}current {s}{s}{s}\n", .{ step(), c(DIM), current, c(RESET) });852 p("{s}latest {s}{s}{s}{s}\n", .{ step(), c(BOLD), c(GREEN), latest, c(RESET) });853}854855fn releaseNotesHeading(line: []const u8) []const u8 {856 var i: usize = 0;857 while (i < line.len and line[i] == '#') : (i += 1) {}858 return std.mem.trim(u8, line[i..], " \t");859}860861fn releaseNotesBullet(line: []const u8) ?[]const u8 {862 if (line.len < 2) return null;863 const marker = line[0];864 if ((marker == '-' or marker == '*' or marker == '+') and line[1] == ' ') return line[2..];865 if (std.ascii.isDigit(marker)) {866 var i: usize = 1;867 while (i < line.len and std.ascii.isDigit(line[i])) : (i += 1) {}868 if (i + 1 < line.len and line[i] == '.' and line[i + 1] == ' ') return line[i + 2 ..];869 }870 return null;871}872873pub fn updateSelfReleaseNotes(notes: []const u8) void {874 const trimmed = std.mem.trim(u8, notes, " \t\r\n");875 if (trimmed.len == 0) return;876877 p("{s}changelog\n", .{hdr()});878 var lines = std.mem.splitScalar(u8, trimmed, '\n');879 while (lines.next()) |raw_line| {880 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;881 const text = std.mem.trim(u8, line, " \t");882 if (text.len == 0) {883 p("\n", .{});884 continue;885 }886 if (text[0] == '#') {887 const title = releaseNotesHeading(text);888 if (title.len == 0) continue;889 p(" {s}{s}{s}{s}\n", .{ c(BOLD), c(CYAN), title, c(RESET) });890 continue;891 }892 if (releaseNotesBullet(text)) |item| {893 p(" {s}- {s}{s}\n", .{ c(CYAN), item, c(RESET) });894 continue;895 }896 p(" {s}\n", .{text});897 }898}899900pub fn updateSelfDownloading(ver: []const u8, platform: []const u8) void {901 p("{s}downloading nina {s} for {s}\n", .{ step(), ver, platform });902}903904pub fn updateSelfVerifying() void {905 p("{s}verifying checksum\n", .{step()});906}907908pub fn updateSelfInstalling(install_path: []const u8) void {909 p("{s}installing to {s}\n", .{ step(), install_path });910}911912pub fn updateSelfDone(old_ver: []const u8, new_ver: []const u8) void {913 p("{s}updated {s} {s}→{s} {s}\n", .{ hdr(), old_ver, c(DIM), c(RESET), new_ver });914}915916pub fn updateSelfNoPlatform(platform: []const u8) void {917 p("{s}no pre-built binary for {s}\n", .{ hdr(), platform });918 p("{s}check kepr.uk/nina/releases for available platforms\n", .{step()});919}920921pub fn updateSelfNetworkError() void {922 p("{s}{s}\n", .{ if (color_enabled) WARN_C else WARN_P, "could not reach kepr.uk — check your connection" });923}924925pub fn updateSelfChecksumFailed() void {926 p("{s}checksum mismatch — download may be corrupt\n", .{if (color_enabled) ERR_C else ERR_P});927 p("{s}try again or download manually from kepr.uk/nina/releases\n", .{step()});928}929930pub fn updateSelfNixManaged(new_ver: []const u8) void {931 p("{s}upgrading to {s}{s}{s} via nix profile\n", .{ step(), c(BOLD), new_ver, c(RESET) });932}933934pub fn updateSelfNixFailed() void {935 p("{s}nix profile upgrade failed\n", .{if (color_enabled) ERR_C else ERR_P});936 p("{s}try manually: nix profile upgrade '.*nina.*'\n", .{step()});937}938939pub fn updateSelfNotInProfile() void {940 p("{s}nina is in the nix store but not found as a profile element\n", .{hdr()});941 p("{s}reinstall via 'nix profile add' to enable self-update\n", .{step()});942}943944945946pub fn goodbyeStart() void {947 p("{s}uninstalling nina\n", .{hdr()});948}949950pub fn goodbyeFile(path: []const u8) void {951 p("{s}will remove {s}\n", .{ step(), path });952}953954pub fn goodbyeNix() void {955 p("{s}will remove nina from nix profile\n", .{step()});956 p("{s}command: nix profile remove nina\n", .{step()});957}958959pub fn goodbyeDone() void {960 p("{s}goodbye! see kepr.uk/nina to reinstall\n", .{hdr()});961}962963pub fn goodbyeFailed(msg: []const u8) void {964 p("{s}{s}\n", .{ if (color_enabled) ERR_C else ERR_P, msg });965}966967968969pub fn setupCheck() void {970 p("{s}checking nix features\n", .{hdr()});971}972973pub fn setupFeatures(nix_command: bool, flakes: bool) void {974 p("{s}nix-command {s}{s}{s}\n", .{975 step(),976 if (nix_command) c(GREEN) else "",977 if (nix_command) "enabled" else "not enabled",978 if (nix_command) c(RESET) else "",979 });980 p("{s}flakes {s}{s}{s}\n", .{981 step(),982 if (flakes) c(GREEN) else "",983 if (flakes) "enabled" else "not enabled",984 if (flakes) c(RESET) else "",985 });986}987988pub fn setupAllSet() void {989 p("{s}all set\n", .{hdr()});990}991992993994pub fn pinningRegistry() void {995 p("{s}pinning nixpkgs for fast local search...\n", .{hdr()});996 flush();997}9989991000100110021003pub fn searchPlainHeader(mode_str: []const u8, query: []const u8, count: u64) void {1004 p("{s}search {s} {s} {s}{d} results{s}\n", .{ hdr(), mode_str, query, c(DIM), count, c(RESET) });1005}10061007pub fn searchPlainNoResults() void {1008 p(" no results\n", .{});1009}10101011pub fn searchPlainPackage(pname: []const u8, pkg_version: []const u8, description: []const u8, unfree: bool) void {1012 if (unfree) {1013 p(" {s} {s}{s}{s} {s}unfree{s} {s}\n", .{ pname, c(CYAN), pkg_version, c(RESET), c(YELLOW), c(RESET), description });1014 } else {1015 p(" {s} {s}{s}{s} {s}\n", .{ pname, c(CYAN), pkg_version, c(RESET), description });1016 }1017}10181019pub fn searchPlainOption(name: []const u8, type_str: []const u8) void {1020 p(" {s} {s}{s}{s}\n", .{ name, c(DIM), type_str, c(RESET) });1021}10221023pub fn searchEmptyQuery() void {1024 p("{s}search needs a query {s}e.g. nina search firefox{s}\n", .{ hdr(), c(DIM), c(RESET) });1025}10261027pub fn setupEnabling() void {1028 p("{s}enabling experimental features\n", .{hdr()});1029}10301031pub fn setupDone(path: []const u8) void {1032 p("{s}wrote {s}\n", .{ step(), path });1033 p("{s}done open a new shell to pick up the change\n", .{hdr()});1034}1035103610371038pub fn setupNixosOffer(features_line: []const u8, conf_path: []const u8) void {1039 p("{s}on NixOS these go in your system config\n", .{hdr()});1040 p(" nina can add this line to {s}{s}{s}:\n\n", .{ c(DIM), conf_path, c(RESET) });1041 p(" {s}{s}{s}\n\n", .{ c(CYAN), features_line, c(RESET) });1042}10431044pub fn setupNixosWrote(conf_path: []const u8) void {1045 p("{s}added the line to {s} {s}(backup: {s}.nina-bak){s}\n", .{ step(), conf_path, c(DIM), conf_path, c(RESET) });1046 p("{s}now run {s}sudo nixos-rebuild switch{s} — then nina's ready\n", .{ hdr(), c(BOLD), c(RESET) });1047}10481049pub fn setupNixosManual(features_line: []const u8, conf_path: []const u8) void {1050 p("{s}no problem — add this line inside the {s}{{ }}{s} in {s}:\n\n", .{ hdr(), c(DIM), c(RESET), conf_path });1051 p(" {s}{s}{s}\n\n", .{ c(CYAN), features_line, c(RESET) });1052 p(" then run {s}sudo nixos-rebuild switch{s} — then nina's ready\n", .{ c(BOLD), c(RESET) });1053}10541055pub fn setupNixosNeedsRebuild(conf_path: []const u8) void {1056 p("{s}already declared in {s}\n", .{ hdr(), conf_path });1057 p(" just run {s}sudo nixos-rebuild switch{s} to activate it\n", .{ c(BOLD), c(RESET) });1058}10591060pub fn pinDone(input: []const u8, commit: []const u8) void {1061 p("{s}pinned {s} -> {s}\n", .{ hdr(), input, commit });1062}10631064pub fn unpinDone(input: []const u8) void {1065 p("{s}unpinned {s}\n", .{ hdr(), input });1066}10671068pub fn hashResult(hash: []const u8) void {1069 p("{s}\n", .{hash});1070}10711072pub fn fetchResult(hash: []const u8, url: []const u8) void {1073 _ = url;1074 p("{s}\n", .{hash});1075}10761077pub fn storeRepairStart() void {1078 p("{s}repairing store\n", .{hdr()});1079}10801081pub fn storeVerifyStart() void {1082 p("{s}verifying store\n", .{hdr()});1083}10841085pub fn storeGcDone(freed: []const u8) void {1086 p("{s}freed {s}\n", .{ hdr(), freed });1087}10881089pub fn storePath(path: []const u8) void {1090 p("{s}\n", .{path});1091}10921093pub fn pkgResult(key: []const u8, val: []const u8) void {1094 p(" {s:<16} {s}\n", .{ key, val });1095}10961097pub fn channelDone() void {1098 p("{s}done\n", .{hdr()});1099}11001101pub fn flakeShowHeader(name: []const u8) void {1102 p("{s}{s}\n\n", .{ hdr(), name });1103}11041105pub fn flakeShowEntry(kind: []const u8, name: []const u8, desc: []const u8) void {1106 p(" {s:<12} {s:<24} {s}\n", .{ kind, name, desc });1107}1108110911101111pub fn homeNotInstalled() void {1112 p("{s}home manager not detected {s}nothing to do{s}\n", .{ hdr(), c(DIM), c(RESET) });1113}111411151116pub fn homeModuleManaged() void {1117 p("{s}home manager is managed by your system config\n", .{hdr()});1118 p(" {s}-> run {s}nina apply{s}{s} to rebuild both together{s}\n", .{ c(CYAN), c(BOLD), c(RESET), c(CYAN), c(RESET) });1119}11201121pub fn homeApplyStart(machine: []const u8) void {1122 p("{s}{s}applying home config {s}\n", .{ KAO_COZY, hdr(), machine });1123}11241125pub fn homeApplyDone(gen: u32, elapsed_ms: u64) void {1126 const secs = @as(f64, @floatFromInt(elapsed_ms)) / 1000.0;1127 1128 1129 if (gen == 0) {1130 if (elapsed_ms >= 1000) {1131 p("{s}done {s}[{d:.1}s]{s}\n", .{ hdr(), c(DIM), secs, c(RESET) });1132 } else {1133 p("{s}done\n", .{hdr()});1134 }1135 return;1136 }1137 if (elapsed_ms >= 1000) {1138 p("{s}generation {s}{d}{s} {s}[{d:.1}s]{s}\n", .{ hdr(), c(BOLD), gen, c(RESET), c(DIM), secs, c(RESET) });1139 } else {1140 p("{s}generation {s}{d}{s}\n", .{ hdr(), c(BOLD), gen, c(RESET) });1141 }1142}1143114411451146pub fn homeLocalOnly(machine: []const u8) void {1147 p("{s}home manager commands run on the local machine only\n", .{hdr()});1148 p(" {s}-> '{s}' is remote; run nina home on that machine directly{s}\n", .{ c(DIM), machine, c(RESET) });1149}11501151pub fn homeApplyDry(machine: []const u8) void {1152 p("{s}home dry run {s}\n", .{ hdr(), machine });1153}11541155pub fn homeApplyDryDone() void {1156 p("{s}{s}ok{s} no changes applied\n", .{ hdr(), c(GREEN), c(RESET) });1157}11581159pub fn homeBackStart(machine: []const u8, from: u32, to: u32) void {1160 p("{s}rolling back home config {s} gen {d} -> gen {d}\n", .{ hdr(), machine, from, to });1161}11621163pub fn homeBackDone(n: u32) void {1164 p("{s}{s}done gen {s}{d}{s}\n", .{ KAO_GENTLE, hdr(), c(BOLD), n, c(RESET) });1165}11661167pub fn homeHistoryHeader(machine: []const u8) void {1168 p("{s}home generations {s}\n\n", .{ hdr(), machine });1169}11701171pub fn homeHistoryRow(number: u32, date: []const u8, time: []const u8, current: bool) void {1172 if (current) {1173 p(" {s}{d}{s} {s} {s} {s}current{s}\n", .{ c(BOLD), number, c(RESET), date, time, c(BOLD), c(RESET) });1174 } else {1175 p(" {s}{d} {s} {s}{s}\n", .{ c(DIM), number, date, time, c(RESET) });1176 }1177}11781179pub fn homeEditOpen(path: []const u8, editor: []const u8) void {1180 p("{s}opening {s}\n", .{ hdr(), path });1181 printSubstep("{s}", .{editor});1182}11831184pub fn homeCheckStart(machine: []const u8) void {1185 p("{s}checking home config {s}\n", .{ hdr(), machine });1186}11871188pub fn homeCheckOk() void {1189 p("{s}{s}ok{s}\n", .{ hdr(), c(GREEN), c(RESET) });1190}11911192pub fn homeDiffHeader(a: u32, b: u32, machine: []const u8) void {1193 p("{s}home gen {d} -> gen {d} {s}\n\n", .{ hdr(), a, b, machine });1194}11951196pub fn homeNothingToDiff() void {1197 p("{s}only one home generation — nothing to diff yet\n", .{hdr()});1198}11991200pub fn homePackagesHeader(machine: []const u8) void {1201 p("{s}home packages {s}\n\n", .{ hdr(), machine });1202}1203120412051206pub fn firstRunBanner() void {1207 p("{s}{s}nina \u{2014} first run\n\n", .{ KAO_FACE, hdr() });1208}12091210pub fn firstRunNoConfig() void {1211 p(" no config found. let me get set up.\n\n", .{});1212}12131214121512161217pub fn firstRunPrompt(label: []const u8, default: []const u8, buf: []u8) []const u8 {1218 p(" {s:<14} {s}> {s}", .{ label, c(DIM), c(RESET) });1219 flush();1220 var i: usize = 0;1221 while (i < buf.len - 1) {1222 const n = std.posix.read(std.posix.STDIN_FILENO, buf[i .. i + 1]) catch break;1223 if (n == 0) break;1224 if (buf[i] == '\n') break;1225 i += 1;1226 }1227 const input = std.mem.trim(u8, buf[0..i], " \t\r");1228 if (input.len == 0) {1229 1230 p("{s}{s}{s}\n", .{ c(DIM), default, c(RESET) });1231 flush();1232 return default;1233 }1234 return input;1235}12361237pub fn firstRunScanning() void {1238 p("\n {s}:: scanning for config...{s}\n", .{ c(DIM), c(RESET) });1239}124012411242pub fn firstRunDetected(path: []const u8, is_flake: bool) void {1243 const kind = if (is_flake) "flake-based system" else "channel-based system";1244 p(" {s}-> found {s}{s} {s}({s}){s}\n\n", .{ c(CYAN), path, c(RESET), c(DIM), kind, c(RESET) });1245}12461247pub fn firstRunNoneFound() void {1248 p(" {s}-> nothing found at /etc/nixos{s}\n\n", .{ c(DIM), c(RESET) });1249}1250125112521253pub fn firstRunPromptDefault(label: []const u8, default: []const u8, detected: bool, buf: []u8) []const u8 {1254 if (default.len > 0) {1255 p(" {s:<14} {s}[{s}]{s} > ", .{ label, c(DIM), default, c(RESET) });1256 if (detected) p("{s}enter to confirm{s} ", .{ c(DIM), c(RESET) });1257 } else {1258 p(" {s:<14} {s}> {s}", .{ label, c(DIM), c(RESET) });1259 }1260 flush();1261 var i: usize = 0;1262 while (i < buf.len - 1) {1263 const n = std.posix.read(std.posix.STDIN_FILENO, buf[i .. i + 1]) catch break;1264 if (n == 0) break;1265 if (buf[i] == '\n') break;1266 i += 1;1267 }1268 const input = std.mem.trim(u8, buf[0..i], " \t\r");1269 if (input.len == 0) {1270 p("{s}{s}{s}\n", .{ c(DIM), default, c(RESET) });1271 flush();1272 return default;1273 }1274 return input;1275}1276127712781279pub fn flakeChannelNote() void {1280 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) });1281}12821283pub fn firstRunWritten(path: []const u8) void {1284 p("\n {s}written to {s}{s}\n\n", .{ c(DIM), path, c(RESET) });1285}12861287pub fn firstRunSkipped() void {1288 p("\n {s}skipping setup in non-interactive mode{s}\n", .{ c(DIM), c(RESET) });1289}