require 'time'

pomo = ARGV[0].to_i # 1 pomodoro durations
interval = ARGV[1].to_i # rest durations
long_rest = ARGV[2].to_i # long rest durations

one_set = pomo*4 + interval*3 + long_rest # min
puts one_set # min

tempotime_0 = Time.new
tempotime = Time.new
mission_finish_time = tempotime_0 + one_set*60 # sec
fh = mission_finish_time.hour.to_s

fm = mission_finish_time.min

if fm < 10
  fm = "0" + fm.to_s
end

fs = mission_finish_time.sec

if fs < 10
  fs = "0" + fs.to_s
end

count_i = 0
ii = 0
rest = false

pomodoro = 1
resttimes = interval

while count_i < one_set do
  now = Time.new
  if now > mission_finish_time
    now = nil
    break
  end
  now = nil
  seconds = 0

  if pomodoro < 4
    if ii == pomo && resttimes == interval # 25min work , 5min rest
      rest = true
      ii = 0
    end
    if rest == true && ii > interval - 1 # 5min rest
      pomodoro += 1
      ii = 0 # reset 
      rest = false
    end
  elsif pomodoro > 3
    if ii == pomo
      rest = true # 10min long rest
      resttimes = long_rest
    end
  end

  while seconds < 60 do
    t = Time.new

    if (t - tempotime > 1)
      system("clear")
      tempotime = t
      seconds += 1

      puts "end time #{fh}:#{fm}:#{fs}"

      puts

      puts "1 pomodoro = #{pomo} min, rest = #{interval} min"
      puts "long rest = #{long_rest} min"
      puts
      puts " 1 pomodoro #{pomo} min -> rest #{interval} min -> 1 pomodoro #{pomo} min -> rest #{interval} min"
      puts " 1 pomodoro #{pomo} min -> rest #{interval} min -> 1 pomodoro #{pomo} min -> long rest #{long_rest} min"
      puts
      puts "total #{one_set} min"
      puts

      if rest == true
        puts "rest"
      else
        puts "pomodoro: #{pomodoro}"
      end

      puts "total time: " + count_i.to_s + " min"
      if rest == true
        puts "remain: #{(resttimes - ii)} min"
      else
#        puts "remain: #{(pomo - ii)} min"
        puts "remain: #{(((tempotime_0 + pomo*60)-t).to_i).div(60)} min #{(((tempotime_0 + pomo*60)-t).to_i).modulo(60)} sec"
      end

      h = t.hour
      m = t.min
      s = t.sec

      if m < 10
        m = "0" + m.to_s
      end
      if s < 10
        s = "0" + s.to_s
      end

      puts
      puts("#{h}:#{m}:#{s}")
    end
    t = nil
  end
  ii += 1
  count_i += 1
end

puts "4 pomodoro completed."
Edit
Pub: 26 Nov 2022 03:26 UTC
Edit: 26 Nov 2022 09:30 UTC
Views: 89