code review

- Default to 100 if the value can't be parsed as an integer or
  is missing entirely.
This commit is contained in:
Damien Mehala
2025-01-02 23:57:53 +01:00
parent c98d207eb9
commit 9d9fa60ece

View File

@ -809,8 +809,7 @@ pub const Parser = struct {
}, },
.conemu_sleep_value => switch (c) { .conemu_sleep_value => switch (c) {
'0'...'9' => {}, else => self.complete = true,
else => self.state = .invalid,
}, },
.conemu_progress_prestate => switch (c) { .conemu_progress_prestate => switch (c) {
@ -1174,14 +1173,14 @@ pub const Parser = struct {
fn endConEmuSleepValue(self: *Parser) void { fn endConEmuSleepValue(self: *Parser) void {
switch (self.command) { switch (self.command) {
.sleep => |*v| { .sleep => |*v| v.duration_ms = value: {
const str = self.buf[self.buf_start..self.buf_idx]; const str = self.buf[self.buf_start..self.buf_idx];
if (str.len != 0) { if (str.len == 0) break :value 100;
if (std.fmt.parseUnsigned(u16, str, 10)) |num| {
v.duration_ms = @min(num, 10_000); if (std.fmt.parseUnsigned(u16, str, 10)) |num| {
} else |_| { break :value @min(num, 10_000);
v.duration_ms = 10_000; } else |_| {
} break :value 100;
} }
}, },
else => {}, else => {},
@ -1726,9 +1725,10 @@ test "OSC: conemu sleep invalid input" {
const input = "9;1;foo"; const input = "9;1;foo";
for (input) |ch| p.next(ch); for (input) |ch| p.next(ch);
const cmd = p.end('\x1b'); const cmd = p.end('\x1b').?;
try testing.expect(cmd == null); try testing.expect(cmd == .sleep);
try testing.expectEqual(100, cmd.sleep.duration_ms);
} }
test "OSC: show desktop notification" { test "OSC: show desktop notification" {