const options = @import("options.zig"); const std = @import("std"); pub const StepType = enum(u8) { task = 'T', task_break = 'B', pub fn message(self: StepType) []const u8 { return switch (self) { StepType.task => "work", StepType.task_break => "break", }; } }; pub const Step = struct { step_type: StepType = StepType.task, pub fn next(self: Step) Step { return switch (self.step_type) { StepType.task => Step{ .step_type = StepType.task_break, }, StepType.task_break => Step{ .step_type = StepType.task, }, }; } pub fn length(self: Step, settings: options.Settings) u64 { const minutes: u64 = switch (self.step_type) { StepType.task => settings.task_length, StepType.task_break => settings.task_break, }; return minutes * std.time.ns_per_min; } pub fn render( self: Step, allocator: std.mem.Allocator, countdown: u64, ) ![]u8 { _ = self; const total_secs = countdown / std.time.ns_per_s; const mins = total_secs / std.time.s_per_min; const secs = total_secs % std.time.s_per_min; return try allocator.print( "{:0>2}:{:0>2}", .{ mins, secs, }, ); } };