improve writeFiglet function

This commit is contained in:
LordMZTE 2022-09-09 20:46:28 +02:00
parent debaff88c6
commit fee780cff7
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6

View file

@ -12,18 +12,18 @@ const figlet =
pub fn writeFiglet(writer: anytype) !void { pub fn writeFiglet(writer: anytype) !void {
var style: ?at.style.Style = null; var style: ?at.style.Style = null;
var iter = std.mem.split(u8, figlet, "\n"); for (figlet) |char| {
while (iter.next()) |line| { switch (char) {
for (line) |char| { 'r' => {
if (char == 'r') {
try at.format.updateStyle(writer, .{ .foreground = .Red }, style); try at.format.updateStyle(writer, .{ .foreground = .Red }, style);
style = .{ .foreground = .Red }; style = .{ .foreground = .Red };
} else { },
try writer.writeByte(char); '\n' => {
} try at.format.updateStyle(writer, .{ .foreground = .Default }, style);
style = .{ .foreground = .Default };
try writer.writeByte('\n');
},
else => try writer.writeByte(char),
} }
try at.format.updateStyle(writer, .{ .foreground = .Default }, style);
style = .{ .foreground = .Default };
try writer.writeByte('\n');
} }
} }