refactor: make available write_padding function to other modules

This commit is contained in:
Igor Támara 2025-11-16 19:54:17 -05:00 committed by CJ van den Berg
parent ced915fedc
commit c5e6d64235
3 changed files with 14 additions and 9 deletions

View file

@ -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(" ");
}