Last active
June 25, 2019 12:50
-
-
Save vestige/aa46cf7d0baa35a8a3cb8bb6e48906cc to your computer and use it in GitHub Desktop.
LT Timer Curses
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "curses" | |
def finishRestart(win, limit) | |
str = win.getch | |
if (str == 'r') | |
win.clear | |
win.refresh | |
timer_start(limit) | |
elsif (str == 'q') | |
win.close | |
else | |
win.clear | |
win.refresh | |
win.box("|", "-") | |
win.setpos(2, 3) | |
win.addstr("again.") | |
win.setpos(5, 3) | |
win.addstr("r > restart") | |
win.setpos(6, 3) | |
win.addstr("q > quit") | |
finishRestart(win, limit) | |
end | |
end | |
def timer_start(limit) | |
height = 5 | |
width = 15 | |
top = (Curses.lines - height) / 2 | |
left = (Curses.cols - width) / 2 | |
win = Curses::Window.new(height, width, top, left) | |
start = Time.now | |
loop do | |
remain = Time.now - start | |
sleep 0.2 | |
break if limit < remain | |
win.clear | |
win.box("|", "-") | |
win.setpos(2, 7) | |
win.addstr(remain.ceil.to_s) | |
win.refresh | |
end | |
win.clear | |
height = 11 | |
width = 16 | |
top = (Curses.lines - height) / 2 | |
left = (Curses.cols - width) / 2 | |
win2 = Curses::Window.new(height, width, top, left) | |
win2.box("*", "*") | |
win2.setpos(4, 3) | |
win2.attrset(Curses.color_pair(1)) | |
win2.addstr("Finish!!!") | |
win2.setpos(5, 3) | |
win2.addstr("Finish!!!") | |
win2.setpos(6, 3) | |
win2.addstr("Finish!!!") | |
win2.refresh | |
finishRestart(win2, limit); | |
end | |
Curses.init_screen | |
begin | |
Curses.start_color | |
Curses.init_pair 1, Curses::COLOR_RED, Curses::COLOR_WHITE | |
Curses.crmode | |
Curses.setpos((Curses.lines - 1) / 2, (Curses.cols - 11) / 2) | |
Curses.addstr("Hit any key") | |
Curses.refresh | |
Curses.getch | |
# timer_start(2 * 60) | |
timer_start(10) | |
ensure | |
Curses.close_screen | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment