Permalink
Browse files

Centering and colouring.

  • Loading branch information...
1 parent 1ede092 commit 16a23e6eb683feabf215f585b807954f4a7192ed @knaveofdiamonds committed May 9, 2012
Showing with 39 additions and 4 deletions.
  1. +3 −1 bin/pompom
  2. +36 −3 lib/pompom.rb
View
@@ -7,9 +7,11 @@ opts = Trollop.options do
opt :message, "What you're working on this pomodoro", :type => :string
opt :time, "The time in seconds", :default => 1500, :type => :int
opt :log, "Where to log work", :default => "~/.pompom/worklog", :type => :string
- opt :no_log, "Do not log work"
end
+if opts[:message].nil?
+ opts[:no_log] = true
+end
application = Pompom::Application.new(opts)
trap("SIGINT") do
View
@@ -152,10 +152,24 @@ def run(&block)
end
def update(pomodoro)
- @screen.display format_for_screen(pomodoro.time_remaining)
+ @screen.display format_for_screen(pomodoro.time_remaining), color(pomodoro), blink(pomodoro)
end
private
+
+ def color(pomodoro)
+ if pomodoro.time_remaining > 60
+ :green
+ elsif pomodoro.time_remaining > 15
+ :yellow
+ else
+ :red
+ end
+ end
+
+ def blink(pomodoro)
+ pomodoro.time_remaining < 5
+ end
def format_for_screen(time)
@asciifier.asciify(Pompom.format_time(time))
@@ -184,17 +198,36 @@ def run
initscr
cbreak
noecho
+ start_color
+ init_pair(1, COLOR_GREEN, COLOR_BLACK)
+ init_pair(2, COLOR_YELLOW, COLOR_BLACK)
+ init_pair(3, COLOR_RED, COLOR_BLACK)
curs_set 0
yield
ensure
endwin
end
end
- def display(str)
+ def display(str, color=:green, blinking=false)
clear
- addstr(str)
+ text_style = blinking ? A_BLINK : A_NORMAL
+ attr_set text_style, color_pair_mapping[color], nil
+
+ y, x = getmaxyx(stdscr)
+
+ lines = str.split("\n")
+ padding = (x - lines.first.size) / 2
+ ((y - lines.size - 1) / 2).times { addstr("\n") }
+ lines.each do |line|
+ addstr(" " * padding)
+ addstr(line + "\n")
+ end
refresh
end
+
+ def color_pair_mapping
+ {:green => 1,:yellow => 2,:red => 3 }
+ end
end
end

0 comments on commit 16a23e6

Please sign in to comment.