draw_a_clock.sf 856 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/ruby
  2. STDOUT.autoflush(true)
  3. var (rows, cols) = `stty size`.nums...
  4. var x = (rows/2 - 1 -> int)
  5. var y = (cols/2 - 16 -> int)
  6. var chars = [
  7. "┌─┐ ╷╶─┐╶─┐╷ ╷┌─╴┌─╴╶─┐┌─┐┌─┐ ",
  8. "│ │ │┌─┘╶─┤└─┤└─┐├─┐ │├─┤└─┤ : ",
  9. "└─┘ ╵└─╴╶─┘ ╵╶─┘└─┘ ╵└─┘╶─┘ "
  10. ].map {|s| s.split(3) }
  11. func position(i,j) {
  12. "\e[%d;%dH" % (i, j)
  13. }
  14. func indices {
  15. var t = Time.local
  16. "%02d:%02d:%02d" % (t.hour, t.min, t.sec) -> split(1).map{|c| c.ord - '0'.ord }
  17. }
  18. loop {
  19. print "\e[H\e[J"
  20. for i in ^chars {
  21. print position(x + i, y)
  22. print [chars[i][indices()]].join(' ')
  23. }
  24. print position(1, 1)
  25. Sys.sleep(0.1)
  26. }