commit f029640c13af92f5832f49bd205e8facb8b40405
parent a02edcc457e61a081795b4cd6041d922ea1b7c38
Author: brookjeynes <me@brookjeynes.dev>
Date: Mon, 2 Nov 2026 10:16:20 +1000
widget: add locale widget
Signed-off-by: brookjeynes <me@brookjeynes.dev>
Diffstat:
3 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/config.ziggy-schema b/config.ziggy-schema
@@ -10,6 +10,7 @@ root = Config
battery,
cpu,
disk,
+ locale,
},
struct Config {
diff --git a/src/environment.zig b/src/environment.zig
@@ -12,6 +12,14 @@ pub fn getXdgConfigHomeDir(io: std.Io, env_map: *std.process.Environ.Map) !?std.
}, .{ .iterate = true });
}
+pub fn getLocale(env_map: *std.process.Environ.Map) ?[]const u8 {
+ if (env_map.get("LC_ALL")) |locale| return locale;
+ if (env_map.get("LC_CTYPE")) |locale| return locale;
+ if (env_map.get("LANG")) |locale| return locale;
+
+ return null;
+}
+
pub fn fileExists(dir: std.Io.Dir, io: std.Io, path: []const u8) bool {
const result = blk: {
_ = dir.openFile(io, path, .{}) catch |err| {
diff --git a/src/main.zig b/src/main.zig
@@ -20,6 +20,7 @@ const Widgets = enum {
battery,
cpu,
disk,
+ locale,
};
const Config = struct {
@@ -51,6 +52,7 @@ const default_config = Config{
.battery,
.cpu,
.disk,
+ .locale,
},
};
const help_menu =
@@ -260,6 +262,14 @@ pub fn main(init: std.process.Init) !void {
.{ .header = "disk", .stat = disk, .padding = padding },
);
},
+ .locale => {
+ if (environment.getLocale(init.environ_map)) |locale| {
+ try stdout_writer.print(
+ "{[header]s: <[padding]}{[stat]s}\n",
+ .{ .header = "locale", .stat = locale, .padding = padding },
+ );
+ }
+ },
}
}