Add todo.txt pom and its dependencies
This commit is contained in:
parent
1e7adfa51c
commit
af5315c5b9
10 changed files with 403 additions and 0 deletions
39
.todo.actions.d/pom/lib/countdown.rb
Normal file
39
.todo.actions.d/pom/lib/countdown.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
class Countdown
|
||||
|
||||
def run seconds, options={}
|
||||
seconds.downto(0) do |current_seconds|
|
||||
sleep 1
|
||||
write_tmux(current_seconds) if (options[:services] || []).include?(:tmux)
|
||||
set_window_title(current_seconds) if (options[:services] || []).include?(:iterm2)
|
||||
STDOUT.write "[RUNNING] #{to_minutes(current_seconds)}\r"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def write_tmux(current_seconds)
|
||||
`echo #{to_minutes(current_seconds, :tmux)} > ~/.pomo.txt.tmux`
|
||||
end
|
||||
|
||||
def set_window_title(current_seconds)
|
||||
title = to_minutes(current_seconds, :tmux)
|
||||
`echo -ne "\e]1;#{title}\a"`
|
||||
end
|
||||
|
||||
def to_minutes seconds, format=:standard
|
||||
minutes = seconds / 60
|
||||
mins = sprintf("%02d", minutes)
|
||||
secs = sprintf("%02d", seconds % 60)
|
||||
if format == :standard
|
||||
"#{mins}:#{secs} [#{dots_for(minutes)}]"
|
||||
else
|
||||
"#{mins}:#{secs}"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def dots_for mins
|
||||
"#{'.' * (25 - mins)}#{' ' * mins}"
|
||||
end
|
||||
|
||||
end
|
29
.todo.actions.d/pom/lib/file_logger.rb
Normal file
29
.todo.actions.d/pom/lib/file_logger.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
require 'fileutils'
|
||||
|
||||
class FileLogger
|
||||
|
||||
attr_accessor :pomodoro_log_file
|
||||
|
||||
def initialize log_file_path
|
||||
@pomodoro_log_file = log_file_path
|
||||
FileUtils.touch pomodoro_log_file
|
||||
end
|
||||
|
||||
def notify_start task
|
||||
add_separator_if_new_day
|
||||
File.open(pomodoro_log_file, "a") { |file| file.puts "#{Time.now.strftime('%Y/%m/%d %H:%M')} Pomodoro nr. #{sprintf("% 2d", task.pomodori + 1)} started: #{task.text}" }
|
||||
end
|
||||
|
||||
def notify_completed task
|
||||
File.open(pomodoro_log_file, "a") { |file| file.puts "#{Time.now.strftime('%Y/%m/%d %H:%M')} Pomodoro nr. #{sprintf("% 2d", task.pomodori + 1)} completed: #{task.text}" }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def add_separator_if_new_day
|
||||
return if File.zero?(pomodoro_log_file)
|
||||
last_day = File.open(pomodoro_log_file, "r") { |file| file.readlines.last.split(" ")[0]}
|
||||
today = Time.now.strftime('%Y/%m/%d')
|
||||
File.open(pomodoro_log_file, "a") { |file| file.puts "\n-----------\n\n" } if last_day != today
|
||||
end
|
||||
end
|
19
.todo.actions.d/pom/lib/pomo_logger.rb
Normal file
19
.todo.actions.d/pom/lib/pomo_logger.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
class PomoLogger
|
||||
|
||||
attr_accessor :options
|
||||
|
||||
def initialize opts
|
||||
@options = opts
|
||||
end
|
||||
|
||||
def log_pomodoro_started task
|
||||
TerminalNotifierLogger.new.notify_start(task)
|
||||
FileLogger.new(options[:pomodoro_log_file]).notify_start(task)
|
||||
end
|
||||
|
||||
def log_pomodoro_completed task
|
||||
TerminalNotifierLogger.new.notify_completed(task)
|
||||
FileLogger.new(options[:pomodoro_log_file]).notify_completed(task)
|
||||
end
|
||||
|
||||
end
|
63
.todo.actions.d/pom/lib/task.rb
Normal file
63
.todo.actions.d/pom/lib/task.rb
Normal file
|
@ -0,0 +1,63 @@
|
|||
require 'rainbow'
|
||||
|
||||
class Task
|
||||
|
||||
attr_accessor :text
|
||||
attr_accessor :index
|
||||
attr_accessor :pomodori
|
||||
attr_accessor :planned
|
||||
|
||||
POMO_REGEXP = / \(#pomo: (\d+)\/(\d+)\)$/
|
||||
PRIORITY_REGEXP = /^\([A-Z]+\) /
|
||||
STATUS_COLORS = {
|
||||
new: :white,
|
||||
planned: :green,
|
||||
in_progress: :yellow,
|
||||
completed: :blue,
|
||||
underestimated: :red
|
||||
}
|
||||
|
||||
def initialize index, text
|
||||
@index = index.to_i
|
||||
if text =~ POMO_REGEXP
|
||||
@pomodori, @planned = text.match(POMO_REGEXP)[1].to_i, text.match(POMO_REGEXP)[2].to_i
|
||||
else
|
||||
@pomodori, @planned = 0, 0
|
||||
end
|
||||
@text = text.gsub(POMO_REGEXP, '').gsub(PRIORITY_REGEXP, '')
|
||||
end
|
||||
|
||||
def to_s
|
||||
"#{text} (#pomo: #{pomodori}/#{planned})"
|
||||
end
|
||||
|
||||
def add_pomo
|
||||
@pomodori += 1
|
||||
end
|
||||
|
||||
def plan planned
|
||||
@planned = planned.to_i
|
||||
end
|
||||
|
||||
def puts_highlighted
|
||||
return if blank?(text)
|
||||
print "#{index} #{text} "
|
||||
color = STATUS_COLORS[self.status]
|
||||
puts Rainbow("(#pomo: #{pomodori}/#{planned})").send(color)
|
||||
end
|
||||
|
||||
def status
|
||||
return :new if pomodori == 0 && planned == 0
|
||||
return :planned if pomodori == 0 && planned != 0
|
||||
return :completed if pomodori == planned
|
||||
return :in_progress if pomodori != 0 && planned != 0 && pomodori < planned
|
||||
return :underestimated if pomodori != 0 && pomodori > planned
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def blank?(string)
|
||||
string == nil || string == ""
|
||||
end
|
||||
|
||||
end
|
9
.todo.actions.d/pom/lib/terminal_notifier_logger.rb
Normal file
9
.todo.actions.d/pom/lib/terminal_notifier_logger.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
class TerminalNotifierLogger
|
||||
def notify_start task
|
||||
TerminalNotifier.notify('Pomodoro started', title: 'Pomotxt', sound: 'Glass')
|
||||
end
|
||||
|
||||
def notify_completed task
|
||||
TerminalNotifier.notify('Pomodoro completed!', title: 'Pomotxt', sound: 'Glass')
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue