From 9e8b663694e50b0da7ac9afcc0a37e291fa74cf8 Mon Sep 17 00:00:00 2001 From: Jeeves Date: Mon, 18 Mar 2024 15:59:34 -0600 Subject: [PATCH] volume: fix 1 digit error --- src/modules/volume.zig | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/modules/volume.zig b/src/modules/volume.zig index 0645fa6..168161c 100644 --- a/src/modules/volume.zig +++ b/src/modules/volume.zig @@ -22,11 +22,11 @@ pub fn getJson(module: *const Module) !Module.JSON { }); if (std.mem.indexOfScalar(u8, child.stdout, '[')) |volume_idx| { - const volume = try std.fmt.parseInt(u8, child.stdout[volume_idx + 1 .. volume_idx + 3], 10); - return .{ - .full_text = try std.fmt.allocPrint(self.module.allocator, "{d:0>2}%", .{volume}), - }; - } else return .{ - .full_text = "?", - }; + if (std.mem.indexOfScalarPos(u8, child.stdout, volume_idx, '%')) |percent_idx| { + const volume = try std.fmt.parseInt(u8, child.stdout[volume_idx + 1 .. percent_idx], 10); + return .{ + .full_text = try std.fmt.allocPrint(self.module.allocator, "{d: >2}%", .{volume}), + }; + } else return .{ .full_text = "?" }; + } else return .{ .full_text = "?" }; }