diff --git a/src/bar/bar.zig b/src/bar/bar.zig
index 19235bd..67df130 100644
--- a/src/bar/bar.zig
+++ b/src/bar/bar.zig
@@ -159,7 +159,7 @@ pub const Bar = struct {
if (std.mem.eql(u8, line, "[")) continue;
// Prevention from crashing when running via `zig build run` when pressing enter key.
if (line.len == 0) continue;
- // Why do you even do this i3bar?
+ // Why do you even do this i3bar?
// Why cant you just send one single {} without a comma at start.
// This is stupid and I don't get it, maybe if you were streaming the data
// instead of looping and getting it, maybe then it would make more sense?
diff --git a/src/formatting/colour.zig b/src/formatting/colour.zig
index f21f000..29b2c26 100644
--- a/src/formatting/colour.zig
+++ b/src/formatting/colour.zig
@@ -28,85 +28,54 @@ const TerminalYellowColour = "\u{001b}[33m";
const TerminalGreenColour = "\u{001b}[32m";
const TerminalPurpleColour = "\u{001b}[35m";
+fn getColourFromColour(clr: []const u8) []const u8 {
+ if (clr[0] == '#' or clr[0] == '\u{001b}') {
+ return clr;
+ } else if (eql(u8, clr, "text")) {
+ return if (!terminal_version) TextColour else TerminalTextColour;
+ } else if (eql(u8, clr, "dark")) {
+ return if (!terminal_version) DarkerTextColour else TerminalDarkerTextColour;
+ } else if (eql(u8, clr, "darkest")) {
+ return if (!terminal_version) DarkestTextColour else TerminalDarkestTextColour;
+ } else if (eql(u8, clr, "accentlight")) {
+ return if (!terminal_version) AccentLightColour else TerminalAccentLightColour;
+ } else if (eql(u8, clr, "accentmedium")) {
+ return if (!terminal_version) AccentMediumColour else TerminalAccentMediumColour;
+ } else if (eql(u8, clr, "accentdark")) {
+ return if (!terminal_version) AccentDarkColour else TerminalAccentDarkColour;
+ } else if (eql(u8, clr, "red")) {
+ return if (!terminal_version) RedColour else TerminalRedColour;
+ } else if (eql(u8, clr, "orange")) {
+ return if (!terminal_version) OrangeColour else TerminalOrangeColour;
+ } else if (eql(u8, clr, "yellow")) {
+ return if (!terminal_version) YellowColour else TerminalYellowColour;
+ } else if (eql(u8, clr, "green")) {
+ return if (!terminal_version) GreenColour else TerminalGreenColour;
+ } else if (eql(u8, clr, "purple")) {
+ return if (!terminal_version) PurpleColour else TerminalPurpleColour;
+ } else {
+ unreachable;
+ }
+}
/// This colours a string but at comptime.
pub fn comptimeColour(comptime clr: []const u8, comptime str: []const u8) []const u8 {
if (disable_colour) return str;
- if (clr[0] == '#' or clr[0] == '\u{001b}') {
- if (terminal_version) {
- return crl ++ str ++ TerminalResetColour;
- } else {
- return "" ++ str ++ "";
- }
+ const proper_colour = comptime getColourFromColour(clr);
+ if (terminal_version) {
+ return proper_colour ++ str ++ TerminalResetColour;
} else {
- comptime var colourText: []const u8 = "";
- if (eql(u8, clr, "text")) {
- colourText = if (!terminal_version) TextColour else TerminalTextColour;
- } else if (eql(u8, clr, "dark")) {
- colourText = if (!terminal_version) DarkerTextColour else TerminalDarkerTextColour;
- } else if (eql(u8, clr, "darkest")) {
- colourText = if (!terminal_version) DarkestTextColour else TerminalDarkestTextColour;
- } else if (eql(u8, clr, "accentlight")) {
- colourText = if (!terminal_version) AccentLightColour else TerminalAccentLightColour;
- } else if (eql(u8, clr, "accentmedium")) {
- colourText = if (!terminal_version) AccentMediumColour else TerminalAccentMediumColour;
- } else if (eql(u8, clr, "accentdark")) {
- colourText = if (!terminal_version) AccentDarkColour else TerminalAccentDarkColour;
- } else if (eql(u8, clr, "red")) {
- colourText = if (!terminal_version) RedColour else TerminalRedColour;
- } else if (eql(u8, clr, "orange")) {
- colourText = if (!terminal_version) OrangeColour else TerminalOrangeColour;
- } else if (eql(u8, clr, "yellow")) {
- colourText = if (!terminal_version) YellowColour else TerminalYellowColour;
- } else if (eql(u8, clr, "green")) {
- colourText = if (!terminal_version) GreenColour else TerminalGreenColour;
- } else if (eql(u8, clr, "purple")) {
- colourText = if (!terminal_version) PurpleColour else TerminalPurpleColour;
- }
- if (colourText.len == 0) {
- unreachable;
- }
- return comptimeColour(colourText, str);
+ return "" ++ str ++ "";
}
}
/// This colours a dynamic string at runtime.
-/// It may make more than one allocation,
-/// so put it on a ArenaAllocator so you can free what else it allocates.
pub fn colour(alloc: *std.mem.Allocator, clr: []const u8, str: []const u8) ![]const u8 {
if (disable_colour) return str;
-
- if (clr[0] == '#' or clr[0] == '\u{001b}') {
- if (terminal_version) {
- return try std.fmt.allocPrint(alloc, "{}{}" ++ TerminalResetColour, .{ clr, str });
- } else {
- return try std.fmt.allocPrint(alloc, "{}", .{ clr, str });
- }
+ const proper_colour = getColourFromColour(clr);
+ if (terminal_version) {
+ return try std.fmt.allocPrint(alloc, "{}{}" ++ TerminalResetColour, .{ proper_colour, str });
} else {
- var colourText: []const u8 = "";
- if (eql(u8, clr, "text")) {
- colourText = if (!terminal_version) TextColour else TerminalTextColour;
- } else if (eql(u8, clr, "dark")) {
- colourText = if (!terminal_version) DarkerTextColour else TerminalDarkerTextColour;
- } else if (eql(u8, clr, "darkest")) {
- colourText = if (!terminal_version) DarkestTextColour else TerminalDarkestTextColour;
- } else if (eql(u8, clr, "accentlight")) {
- colourText = if (!terminal_version) AccentLightColour else TerminalAccentLightColour;
- } else if (eql(u8, clr, "accentmedium")) {
- colourText = if (!terminal_version) AccentMediumColour else TerminalAccentMediumColour;
- } else if (eql(u8, clr, "accentdark")) {
- colourText = if (!terminal_version) AccentDarkColour else TerminalAccentDarkColour;
- } else if (eql(u8, clr, "red")) {
- colourText = if (!terminal_version) RedColour else TerminalRedColour;
- } else if (eql(u8, clr, "orange")) {
- colourText = if (!terminal_version) OrangeColour else TerminalOrangeColour;
- } else if (eql(u8, clr, "yellow")) {
- colourText = if (!terminal_version) YellowColour else TerminalYellowColour;
- } else if (eql(u8, clr, "green")) {
- colourText = if (!terminal_version) GreenColour else TerminalGreenColour;
- } else if (eql(u8, clr, "purple")) {
- colourText = if (!terminal_version) PurpleColour else TerminalPurpleColour;
- }
- return colour(alloc, colourText, str);
+ return try std.fmt.allocPrint(alloc, "{}", .{ proper_colour, str });
}
}
diff --git a/src/types/loopingcounter.zig b/src/types/loopingcounter.zig
index 2a18c7c..7f9053d 100644
--- a/src/types/loopingcounter.zig
+++ b/src/types/loopingcounter.zig
@@ -1,7 +1,7 @@
const std = @import("std");
const testing = std.testing;
-/// A LoopingCounter is *extremely* helpful when making clickable widgets
+/// A LoopingCounter is *extremely* helpful when making clickable widgets
/// that have different data to show and loops around.
pub fn LoopingCounter(
comptime max_number: comptime_int,
diff --git a/src/widgets/time/time.zig b/src/widgets/time/time.zig
index 7ca18e5..b936c71 100644
--- a/src/widgets/time/time.zig
+++ b/src/widgets/time/time.zig
@@ -25,7 +25,6 @@ pub const TimeWidget = struct {
pub fn start(self: *TimeWidget) anyerror!void {
// TODO: find a god damn decent time library thats better than this bullshit.
-
while (self.bar.keep_running()) {
var arena = std.heap.ArenaAllocator.init(self.allocator);
defer arena.deinit();
diff --git a/src/widgets/weather/weather.zig b/src/widgets/weather/weather.zig
index 0c16e2f..bc2aac9 100644
--- a/src/widgets/weather/weather.zig
+++ b/src/widgets/weather/weather.zig
@@ -62,7 +62,6 @@ pub const WeatherWidget = struct {
var main: []const u8 = "";
var message: []const u8 = "";
-
// This parser is clunky, it may be worth a rewrite but it seems like it optimizes decently.
while (try client.readEvent()) |event| {
switch (event) {
@@ -173,7 +172,6 @@ pub const WeatherWidget = struct {
var temp = inf.temp;
var main = inf.main;
-
// Please note that these are *my* personal temp preferences.
// TODO: it may be worth making a way for the user to change this with a function on init.
// If you happen to read this and you plan on inviting me round your house one day,