From c5e6d64235d7f0c6c6589f8d78f1d7f11ec03b10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20T=C3=A1mara?= Date: Sun, 16 Nov 2025 19:54:17 -0500 Subject: [PATCH] refactor: make available write_padding function to other modules --- build.zig | 2 ++ src/list_languages.zig | 12 +++--------- src/text_manip.zig | 9 +++++++++ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/build.zig b/build.zig index 1b194ed..1b3a01f 100644 --- a/build.zig +++ b/build.zig @@ -668,6 +668,7 @@ pub fn build_exe( exe.root_module.addImport("flags", flags_dep.module("flags")); exe.root_module.addImport("cbor", cbor_mod); exe.root_module.addImport("config", config_mod); + exe.root_module.addImport("text_manip", text_manip_mod); exe.root_module.addImport("Buffer", Buffer_mod); exe.root_module.addImport("tui", tui_mod); exe.root_module.addImport("thespian", thespian_mod); @@ -717,6 +718,7 @@ pub fn build_exe( check_exe.root_module.addImport("flags", flags_dep.module("flags")); check_exe.root_module.addImport("cbor", cbor_mod); check_exe.root_module.addImport("config", config_mod); + check_exe.root_module.addImport("text_manip", text_manip_mod); check_exe.root_module.addImport("Buffer", Buffer_mod); check_exe.root_module.addImport("tui", tui_mod); check_exe.root_module.addImport("thespian", thespian_mod); diff --git a/src/list_languages.zig b/src/list_languages.zig index 376424c..7e42190 100644 --- a/src/list_languages.zig +++ b/src/list_languages.zig @@ -1,5 +1,8 @@ const std = @import("std"); const file_type_config = @import("file_type_config"); +const text_manip = @import("text_manip"); +const write_string = text_manip.write_string; +const write_padding = text_manip.write_padding; const builtin = @import("builtin"); const RGB = @import("color").RGB; @@ -66,11 +69,6 @@ fn args_string_length(args_: ?[]const []const u8) usize { return len; } -fn write_string(writer: anytype, string: []const u8, pad: ?usize) !void { - try writer.writeAll(string); - if (pad) |pad_| try write_padding(writer, string.len, pad_); -} - fn write_checkmark(writer: anytype, success: bool, tty_config: std.io.tty.Config) !void { try tty_config.setColor(writer, if (success) .green else .red); if (success) try writer.writeAll(success_mark) else try writer.writeAll(fail_mark); @@ -98,10 +96,6 @@ fn write_segmented( if (pad) |pad_| try write_padding(writer, len, pad_); } -fn write_padding(writer: anytype, len: usize, pad_len: usize) !void { - for (0..pad_len - len) |_| try writer.writeAll(" "); -} - fn can_execute(allocator: std.mem.Allocator, binary_name: []const u8) bool { const resolved_binary_path = bin_path.find_binary_in_path(allocator, binary_name) catch return false; defer if (resolved_binary_path) |path| allocator.free(path); diff --git a/src/text_manip.zig b/src/text_manip.zig index 1202095..2197315 100644 --- a/src/text_manip.zig +++ b/src/text_manip.zig @@ -89,3 +89,12 @@ pub fn toggle_prefix_in_text(prefix: []const u8, text: []const u8, allocator: st } return result.toOwnedSlice(allocator); } + +pub fn write_string(writer: anytype, string: []const u8, pad: ?usize) !void { + try writer.writeAll(string); + if (pad) |pad_| try write_padding(writer, string.len, pad_); +} + +pub fn write_padding(writer: anytype, len: usize, pad_len: usize) !void { + for (0..pad_len - len) |_| try writer.writeAll(" "); +}