made it work, more or less, with ruby 1.9
[nyuron.git] / nyuron.rb
blob40455dc606755efe0cbd96c4c661eea71f29ed10
1 #!/usr/bin/env ruby
2 ## Nyuron: dynamic notepad & calendar
3 version = '4.1.4'
6 ## boot up --------------------------------------
8 ## find the path of this script
9 require 'pathname'
10 MYDIR = File.dirname(Pathname.new(__FILE__).realpath)
11 $LOAD_PATH << MYDIR
13 require 'modules/boot'
14 include Boot
17 ## check arguments
19 if ARGV.include? '-v' or ARGV.include? '--version'
20         abort "nyuron #{version}"
21 elsif ARGV.include? '--help'
22         abort "usage: nyuron [--version] [--help]"
23 end
26 ## set up & load --------------------------------
28 ## find & run rc file
29 fname = get_conf_path
31 ## predefine some variables to set their scope
32 dbfile, editor, loglevel, logfile, colorscheme, stfu = nil
34 load fname if fname
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"
40 end
42 remember = dbfile
43 dbfile, places = get_database_path_and_places(dbfile)
45 unless 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}
49         puts
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."
52         exit
53 end
56 ## require all files in modules/ and classes/
57 cant_find = []
58 for file in Dir[File.join(MYDIR, '{modules,classes}', '**', '*.rb')]
59         begin
60                 require file [MYDIR.size + 1..-4]
61         rescue LoadError
62                 cant_find << $!.backtrace.join("\n")
63         end
64 end
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}
69         puts
70         puts "Please make sure you have ruby-sqlite3 and ruby-ncurses installed"
71         puts "and inside of one of those directories:"
72         puts
73         $LOAD_PATH.each {|x| puts x}
74         exit
75 end
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
85 include Debug
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')
92 Info.dbfile = dbfile
94 Info.version = version
95 Info.where = :main
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
102 Debug.setup(
103         :name => 'nyuron',
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) )
111 Opt = Cache.opt
114 ## let's nyu! -----------------------------------
115 begin
116         $now = Time.now
117         CLI.initialize
118         Console.initialize
119         SQL.initialize
120         UserInterface.meta_loop
122 rescue SystemExit, Interrupt
123         ## quietly ignore
125 rescue Exception
126         logwrite_fatal "Fatal exception: "
127         lograise
128         raise
130 ensure
131         log "---- the end ----"
132         UserInterface.close