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 658B

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