From 5b0bd83bd7de62f026586752caa14d6f2ae586f5 Mon Sep 17 00:00:00 2001 From: Jeremie Fraeys Date: Wed, 4 Mar 2026 21:14:27 -0500 Subject: [PATCH] refactor(cli): remove logging.zig, consolidate into io.zig MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove redundant logging.zig (28 lines): - Functions moved to io.zig: printInfo, printSuccess, printWarning, printError, printProgress, confirm - All functionality preserved with re-exports in utils.zig Benefits: - Reduced file count (22 → 21 utils) - Single source of truth for I/O operations - No functional changes Build passes successfully. --- cli/src/utils/io.zig | 45 +++++++++++++++++++++++++++++++++++++++ cli/src/utils/logging.zig | 27 ----------------------- 2 files changed, 45 insertions(+), 27 deletions(-) delete mode 100644 cli/src/utils/logging.zig diff --git a/cli/src/utils/io.zig b/cli/src/utils/io.zig index 4b7d698..82800f0 100644 --- a/cli/src/utils/io.zig +++ b/cli/src/utils/io.zig @@ -243,3 +243,48 @@ pub fn jsonGetBool(obj: std.json.ObjectMap, key: []const u8) ?bool { if (v != .bool) return null; return v.bool; } + +// ============================================================================ +// Logging Utilities (consolidated from logging.zig) +// ============================================================================ + +fn printWithColor(comptime color_code: []const u8, comptime format: []const u8, args: anytype) void { + const stderr = std.io.getStdErr().writer(); + stderr.print(color_code ++ format ++ reset ++ "\n", args) catch {}; +} + +pub fn printInfo(comptime format: []const u8, args: anytype) void { + printWithColor(blue, format, args); +} + +pub fn printSuccess(comptime format: []const u8, args: anytype) void { + printWithColor(green, format, args); +} + +pub fn printWarning(comptime format: []const u8, args: anytype) void { + printWithColor(yellow, format, args); +} + +pub fn printError(comptime format: []const u8, args: anytype) void { + printWithColor(red, format, args); +} + +pub fn printProgress(comptime format: []const u8, args: anytype) void { + const stdout = std.io.getStdOut().writer(); + stdout.print(format ++ "\n", args) catch {}; +} + +pub fn confirm(comptime prompt: []const u8, args: anytype) bool { + const stdin = std.io.getStdIn().reader(); + const stdout = std.io.getStdOut().writer(); + + stdout.print(bold ++ prompt ++ reset ++ " [y/N] ", args) catch {}; + + var buf: [10]u8 = undefined; + if (stdin.readUntilDelimiterOrEof(&buf, '\n')) |input| { + if (input) |line| { + return line.len > 0 and (line[0] == 'y' or line[0] == 'Y'); + } + } else |_| {} + return false; +} diff --git a/cli/src/utils/logging.zig b/cli/src/utils/logging.zig deleted file mode 100644 index a6df7ea..0000000 --- a/cli/src/utils/logging.zig +++ /dev/null @@ -1,27 +0,0 @@ -const std = @import("std"); -const colors = @import("colors.zig"); - -/// Simple logging utility that wraps colors functionality -pub fn info(comptime format: []const u8, args: anytype) void { - colors.printInfo(format, args); -} - -pub fn success(comptime format: []const u8, args: anytype) void { - colors.printSuccess(format, args); -} - -pub fn warn(comptime format: []const u8, args: anytype) void { - colors.printWarning(format, args); -} - -pub fn err(comptime format: []const u8, args: anytype) void { - colors.printError(format, args); -} - -pub fn progress(comptime format: []const u8, args: anytype) void { - colors.printProgress(format, args); -} - -pub fn confirm(comptime prompt: []const u8, args: anytype) bool { - return colors.confirm(prompt, args); -}