You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

timer.elv 723B

1234567891011121314151617181920212223242526272829303132
  1. use util
  2. start = (date +%s)
  3. delta = 0
  4. s = 0
  5. m = 0
  6. h = 0
  7. composed = ''
  8. fn pad [a]{ if (< $a 10) { put '0'$a } }
  9. util:add-after-readline [_]{ start = (date +%s) }
  10. util:add-before-readline {
  11. delta = (- (date +%s) $start)
  12. h = 0
  13. m = 0
  14. s = $delta
  15. if (> $delta 3600) {
  16. s = (% $delta 60)
  17. m = (/ (- (% $delta 3600) $s) 60)
  18. h = (/ (- $delta (* $m 60) $s) 3600)
  19. composed = (edit:styled ' ⏱'$h':'(util:pad $m 2 &with=0)':'(util:pad $s 2 &with=0) bold)
  20. } elif (> $delta 60) {
  21. s = (% $delta 60)
  22. m = (/ (- $delta $s) 60)
  23. composed = (edit:styled ' ⏱'$m':'(util:pad $s 2 &with=0) bold)
  24. } elif (> $delta 5) {
  25. composed = (edit:styled ' ⏱'$delta bold)
  26. } else {
  27. composed = ''
  28. }
  29. }