2 ## Nyuron: dynamic notepad & calendar
6 ## boot up --------------------------------------
8 ## find the path of this script
10 MYDIR = File.dirname(Pathname.new(__FILE__).realpath)
13 require 'modules/boot'
19 if ARGV.include? '-v' or ARGV.include? '--version'
20 abort "nyuron #{version}"
21 elsif ARGV.include? '--help'
22 abort "usage: nyuron [--version] [--help]"
26 ## set up & load --------------------------------
31 ## predefine some variables to set their scope
32 dbfile, editor, loglevel, logfile, colorscheme, stfu = nil
36 unless stfu or ("1.8"..."1.9").include? RUBY_VERSION
37 puts "note that this program was designed for Ruby 1.8.7"
38 puts "you are running: #{RUBY_VERSION}, so you might encounter some errors."
39 puts "write stfu = true into your .nyurc to supress this message"
43 dbfile, places = get_database_path_and_places(dbfile)
46 puts "error: I can't find a database. without it I cannot run,"
47 puts "since all commands are stored there. I searched at this places:"
48 puts places.select {|x| x.is_a? String}
50 puts "if you have a database, please put it there. if not, download the"
51 puts "newest Nyuron release and copy the default database from there."
56 ## require all files in modules/ and classes/
58 for file in Dir[File.join(MYDIR, '{modules,classes}', '**', '*.rb')]
60 require file [MYDIR.size + 1..-4]
62 cant_find << $!.backtrace.join("\n")
66 unless cant_find.empty?
67 puts "While I was loading the required files, i ran into these errors:"
68 cant_find.each {|x| puts x}
70 puts "Please make sure you have ruby-sqlite3 and ruby-ncurses installed"
71 puts "and inside of one of those directories:"
73 $LOAD_PATH.each {|x| puts x}
77 ## require colorscheme
78 colorscheme = find_first_existing_file(
79 File.join(MYDIR, "data", "colorscheme", "#{colorscheme}.rb"),
80 File.join(MYDIR, "data", "colorscheme", "snow.rb")
83 load colorscheme if colorscheme
87 ## initialize the Info object which contains basic information
88 Info = OpenStruct.new()
89 Info.editor = (editor || "vim '+set ft=ruby' '+set noendofline' '+map q ZZ' '%s'")
90 Info.loglevel = (loglevel || 1)
91 Info.logfile = File.expand_path(logfile || '/tmp/errorlog')
94 Info.version = version
96 Info.request_draw = true
97 Info.request_filter = true
98 Info.request_sort = true
100 debug_log_stream = File.open(Info.logfile, 'a')
101 debug_log_stream.sync = true
104 :stream => debug_log_stream,
105 :level => Info.loglevel
108 ## Initialize Cache object, which caches parts of the database
109 ## for quicker access
110 Cache = CacheClass.new( *%w(cmd map opt) )
114 ## let's nyu! -----------------------------------
120 UserInterface.meta_loop
122 rescue SystemExit, Interrupt
126 logwrite_fatal "Fatal exception: "
131 log "---- the end ----"