lib/day/presenter.rb in dayrb-2.0.3 vs lib/day/presenter.rb in dayrb-2.0.4
- old
+ new
@@ -52,43 +52,74 @@
Commands:
(no command) Prints out task list for the day
(nonexisting task) Creates a new task
(existing task) Start tracking time for named task.
delete (task) Remove a task
+ rm (task) (Synonym for delete.)
info Print all descriptions
info (task) Print a specific description
+ i (task) (Synonym for info.)
clear Clear fulfillment for all tasks.
clear (task) Clear fulfillment for a specific task.
+ c (task) (Synonym for clear.)
-Refer to a task either by its name or index.
+Flags:
+ -a Print all tasks, including those not enabled today.
+
+Tips:
+ Refer to a task either by its name or index.
+ Jump directly between tasks.
+ Include "vim" or your editor constant when creating new task to add a description.
+
See readme.md for a more detailed overview.
eos
end
# Prints out the VERSION constant
def print_version
puts "Day.rb v#{VERSION}"
end
- # Announces task has been deleted and prints its description if applicable.
- #
- # @param task [String] Name of task to be deleted
- # @param description [String] Description of task (optional)
- def announce_deletion(task, description)
- puts "Deleted #{task}".color_text
- puts "Description was: #{description}".color_text if description
- end
+ # Asks whether the user is sure that they want to delete something.
+ #
+ # @param task [String] Name of task
+ # @param description [String] Description of task (optional)
+ def confirm_deletion(task, description)
+ puts "Are you sure you want to delete '#{task}'?: (Y/N)"
+ puts "It's description was #{description}: (Y/N)" if description
+ case confirmation = get_confirmation
+ when true
+ puts "Deleted #{task}".color_text
+ puts "Description was: #{description}".color_text if description
+ when false
+ puts "Didn't delete '#{task}.'".color_text
+ end
+ return confirmation
+ end
- # Announces that either a task or all tasks have had fulfillment cleared.
+ # Asks the user whether they're sure they want to clear fulfillment.
#
# @param task [String] Name of task to be cleared
- def announce_clear(task)
- if task
- puts "Cleared fulfillment for #{task}".color_text
- else
- puts "Cleared fulfillment for all tasks".color_text
- end
+ def confirm_clear(task)
+ if task
+ puts "Are you sure you want to clear fulfillment for #{task}?"
+ else
+ puts "Are you sure you want to clear all fulfillment data?"
+ end
+
+ case answer = get_confirmation
+ when true
+ if task
+ puts "Cleared fulfillment for #{task}".color_text
+ else
+ puts "Cleared fulfillment for all tasks".color_text
+ end
+ when false
+ puts "Didn't clear fulfillment."
+ end
+
+ return answer
end
# Announces a switch to a new task...
# also prints the amount of time spent on the old one.
#
@@ -119,10 +150,24 @@
puts "Added new task, #{task}"
end
private
+ def get_confirmation
+ loop do
+ print " (Y/N) -->: "
+ case input = $stdin.gets
+ when /y/i, /yes/i
+ return true
+ when /n/i, /no/i
+ return false
+ else
+ p "Sorry, didn't catch that. Try 'yes' or 'no'."
+ end
+ end
+ end
+
# Iterate through tasklist, printing index, name, description flag and fulfillment/estimate data.
#
# @param tasks [Hash] Collection of task_name => task_object pairs
def print_task_list(tasks)
ii = 0
@@ -218,6 +263,6 @@
# Print unknown error.
def print_error_unknown()
puts "Sorry, that command is not known. Try 'help'."
end
end
-end
\ No newline at end of file
+end