| 1 |
bluedwarf |
1 |
#!/usr/bin/ruby |
| 2 |
bluedwarf |
10 |
# |
| 3 |
bluedwarf |
12 |
# edmaru.rb: the main program of Edmaru. |
| 4 |
|
|
# |
| 5 |
bluedwarf |
10 |
# Copyright (C) 2007 Takashi Nakamoto |
| 6 |
|
|
# |
| 7 |
|
|
# This program is free software; you can redistribute it and/or modify |
| 8 |
|
|
# it under the terms of the GNU General Public License version 2 as |
| 9 |
|
|
# published by the Free Software Foundation. |
| 10 |
|
|
# |
| 11 |
|
|
# This program is distributed in the hope that it will be useful, but |
| 12 |
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
|
|
# General Public License for more details. |
| 15 |
|
|
# |
| 16 |
|
|
# You should have received a copy of the GNU General Public License |
| 17 |
|
|
# along with this program; if not, write to the Free Software |
| 18 |
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 19 |
|
|
# 02110-1301 USA. |
| 20 |
|
|
# |
| 21 |
bluedwarf |
1 |
|
| 22 |
bluedwarf |
5 |
require "view.rb" |
| 23 |
bluedwarf |
22 |
require "config/config_manager.rb" |
| 24 |
bluedwarf |
2 |
require "buffer_manager.rb" |
| 25 |
|
|
require "action_manager.rb" |
| 26 |
|
|
require "event_manager.rb" |
| 27 |
bluedwarf |
28 |
require "event_handler/all_event_handlers.rb" |
| 28 |
bluedwarf |
1 |
|
| 29 |
|
|
# System selection |
| 30 |
bluedwarf |
2 |
system = ARGV.shift |
| 31 |
|
|
if system == nil || system == "" |
| 32 |
|
|
system = "ncurses" |
| 33 |
|
|
end |
| 34 |
bluedwarf |
1 |
|
| 35 |
|
|
# System specific environment configuration. |
| 36 |
|
|
case system |
| 37 |
|
|
when "ncurses" |
| 38 |
|
|
require "ncurses/ncurses_env.rb" |
| 39 |
bluedwarf |
2 |
when "gtk" |
| 40 |
|
|
require "gtk/gtk_env.rb" |
| 41 |
bluedwarf |
1 |
end |
| 42 |
|
|
|
| 43 |
|
|
begin |
| 44 |
bluedwarf |
22 |
config = Edmaru::Config::ConfigManager.new |
| 45 |
bluedwarf |
20 |
|
| 46 |
|
|
#Load user configuration. |
| 47 |
|
|
begin |
| 48 |
|
|
f = open("#{ENV['HOME']}/.edmaru.rb", "r") |
| 49 |
bluedwarf |
22 |
begin |
| 50 |
bluedwarf |
27 |
eval(f.read) |
| 51 |
bluedwarf |
22 |
rescue => e |
| 52 |
|
|
puts e |
| 53 |
|
|
exit(1) |
| 54 |
|
|
ensure |
| 55 |
|
|
f.close |
| 56 |
|
|
end |
| 57 |
|
|
rescue |
| 58 |
|
|
puts "Couldn't open #{ENV['HOME']}/.edmaru.rb" |
| 59 |
bluedwarf |
20 |
end |
| 60 |
|
|
|
| 61 |
bluedwarf |
2 |
action_mgr = Edmaru::ActionManager.new |
| 62 |
bluedwarf |
28 |
|
| 63 |
bluedwarf |
2 |
event_mgr = Edmaru::EventManager.new |
| 64 |
|
|
fundamental_event_handler = |
| 65 |
|
|
Edmaru::FundamentalEventHandler.new(action_mgr) |
| 66 |
|
|
event_mgr.set_current_handler(fundamental_event_handler) |
| 67 |
bluedwarf |
28 |
action_mgr.event_manager = event_mgr |
| 68 |
bluedwarf |
1 |
|
| 69 |
|
|
buffer_mgr = Edmaru::BufferManager.new |
| 70 |
bluedwarf |
2 |
action_mgr.buffer_manager = buffer_mgr |
| 71 |
|
|
|
| 72 |
bluedwarf |
20 |
view = Edmaru::SYSTEM_VIEW.new(config, event_mgr, buffer_mgr) |
| 73 |
bluedwarf |
2 |
action_mgr.view = view |
| 74 |
|
|
|
| 75 |
bluedwarf |
18 |
view.focused_window.buffer = buffer_mgr.get("*scratch*") |
| 76 |
bluedwarf |
19 |
view.mini_window.buffer = buffer_mgr.get("*mini buffer*") |
| 77 |
bluedwarf |
12 |
default_text = <<EOT |
| 78 |
|
|
# This buffer is for notes you don't want to save. |
| 79 |
bluedwarf |
30 |
# If you want to exit Edmaru, type C-x C-c. |
| 80 |
bluedwarf |
12 |
EOT |
| 81 |
bluedwarf |
18 |
view.focused_window.buffer.append(default_text) |
| 82 |
bluedwarf |
12 |
|
| 83 |
bluedwarf |
2 |
view.main_loop |
| 84 |
bluedwarf |
1 |
ensure |
| 85 |
|
|
if view != nil |
| 86 |
|
|
view.terminate |
| 87 |
|
|
end |
| 88 |
|
|
end |