Move to Apache License
[amazing.git] / lib / amazing / cli / initializers.rb
blob0fc96a567f7b7130b47cfb7eedfb0cfa23497400
1 # Copyright 2008 Dag Odenhall <dag.odenhall@gmail.com>
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 #    http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 module Amazing
16   class CLI
17     module Initializers
18       private
20       def initialize_threads
21         @threads = []
22       end
24       def initialize_encoding
25         $KCODE = "utf-8"
26       end
28       def initialize_logger
29         @log = Logger.new(STDOUT)
30       end
32       def initialize_options
33         @options = Options.new(@args)
34       end
36       def initialize_display
37         begin
38           @display = X11::DisplayName.new
40         rescue X11::EmptyDisplayName => e
41           @log.warn("#{e.message}, falling back on :0")
42           @display = X11::DisplayName.new(":0")
44         rescue X11::InvalidDisplayName => e
45           @log.fatal("#{e.message}, exiting")
47           exit 1
48         end
49       end
51       def initialize_awesome
52         @awesome = Awesome.new(@display.display)
53       end
55       def initialize_exit
56         at_exit { Thread.list.each {|t| t.exit } }
57       end
58     end
59   end
60 end