ytodo/ytodo.rb

151 lines
4.4 KiB
Ruby
Raw Permalink Normal View History

2009-06-08 12:47:00 +00:00
#!/usr/bin/env ruby
require "todolist.rb"
require 'readline'
2009-06-08 12:47:00 +00:00
# this file run the minimal GUI
#
# it lacks a read config from config file
listeEnvVariables=[]
2009-06-08 12:47:00 +00:00
autosave=true
listeEnvVariables<<='autosave'
saveFile="TODO"
listeEnvVariables<<='saveFile'
2009-06-08 12:47:00 +00:00
2009-06-16 11:28:29 +00:00
doneFile="DONE"
listeEnvVariables<<='doneFile'
# Print help message
def putsHelpMessage
# Vim tips not to loose any command
# :r!grep when ytodo.rb
puts '
COMMANDS
a,+,add <entry> add an entry
cmd,! <cmd> launch external command
h,help show this message
l,list list the tasks
load,=> [filename] load the tasks from file filename
q,quit quit
s,save [filename] save the tasks to file filename
show [conf key] show the value of a configuration variable
TIPS
If your entrie is longer than 10 character long and the first
word is not a command. The entrie is added to task.
REMINDER
@Context [project] (a note) {tag}
Priority: (higher) !! ! "nothing" ? ?? (lower)
Date: #due_date, #start_date,due_date
example: #tomorrow,"in 4 days"
'
2009-06-08 12:47:00 +00:00
end
if __FILE__ == $0:
# trap the ^C
trap('INT'){
if not autosave:
answer=Readline.readline('Do you want to save your changes? (y/n)',false)
if not answer =~ /^no?$/:
puts "Changes saved in #{saveFile}"
todoList.save saveFile
end
end
puts "\nGood Bye... See you later for another safe and productive day"
exit 0
}
2009-06-08 12:47:00 +00:00
todoList=TodoList.new
todoList.load saveFile
while entry = Readline.readline('> ',true):
2009-06-08 12:47:00 +00:00
case entry
2009-06-16 11:28:29 +00:00
when /^(a|\+|add) /
# Add en entry
2009-06-08 12:47:00 +00:00
todoList.addTask( Task.new(entry.sub(/^(a|\+|add) /,"")) )
if autosave:
todoList.save saveFile
2009-06-08 12:47:00 +00:00
end
when /^(l|list)( ?(\d*))?/
2009-06-16 11:28:29 +00:00
# list the entries
2009-06-08 12:47:00 +00:00
if $3.length>0: print "number "+$3 end
print todoList.to_s
2009-06-16 11:28:29 +00:00
when /^(done|archive) (\d*)/
# archive task
taskNumber=$2
when /^q(uit)?$/
# Quit
break
2009-06-08 12:47:00 +00:00
when /^(s|save)( (.*))?$/
2009-06-16 11:28:29 +00:00
# save to file
2009-06-08 12:47:00 +00:00
if $3 and $3.length>0:
filename=$3
else
filename=saveFile
2009-06-08 12:47:00 +00:00
end
puts "saving to " + filename
todoList.save filename
when /^(load|=>) (.*)/
2009-06-16 11:28:29 +00:00
# load from file
2009-06-08 12:47:00 +00:00
if $2.length>0:
filename = $2
else
filename = saveFile
2009-06-08 12:47:00 +00:00
end
todoList.load filename
when /^h(elp)?$/
2009-06-16 11:28:29 +00:00
putsHelpMessage
# show help message
2009-06-08 12:47:00 +00:00
when /^(show)( (.*))?$/
varname=$3
if varname and (varname.length>0):
if listeEnvVariables.include?(varname):
printf '%20s = ', varname
eval "puts "+varname
else
found=false
listeEnvVariables.grep(Regexp.new(varname)).each do |elem|
printf '%20s = ', elem
eval "puts "+elem
found=true
end
if not found:
puts 'unknown variable name: '+varname
puts 'please select one of: '+listeEnvVariables.join(', ')
end
end
else
listeEnvVariables.each do |key|
printf '%20s = ', key
eval "puts "+key
end
end
when /^set ([^= ]*)(=|\s*)(.*)$/
# default all variable are strings
begin
eval $1+"="+$3
end
when /^(!|cmd )(.+)$/
system( $2 )
2009-06-16 11:28:29 +00:00
# DEV # must be the last two entries # DEV #
when /^$/
2009-06-16 11:28:29 +00:00
# do nothing when there is no entry
when /^.{1,10}$/
# if the entry is not
# recognized and less than 10 characters
# long then we output an error
2009-06-16 11:28:29 +00:00
print "/!\\ Unknown command /!\\\n"
else
# if the entry is more than 10 characters long
# and not recognized then it is a new entry
todoList.addTask( Task.new(entry) )
if autosave:
todoList.save saveFile
end
2009-06-08 12:47:00 +00:00
end
end
end