wmiirc-rumai

git clone git://oldgit.suckless.org/wmiirc-rumai/
Log | Files | Refs | README | LICENSE

wmiirc (1653B)


      1 #!/usr/bin/env ruby
      2 # Bootloader for wmii configuration.
      3 #--
      4 # Copyright protects this work.
      5 # See LICENSE file for details.
      6 #++
      7 
      8 # create a logger to aid debugging
      9 require 'logger'
     10 LOG = Logger.new(__FILE__ + '.log', 5)
     11 
     12 class << LOG
     13   # emulate IO.write
     14   alias write <<
     15 
     16   def flush
     17     # ignore
     18   end
     19 end
     20 
     21 # capture standard output in logger
     22 $stdout = $stderr = LOG
     23 
     24 begin
     25   LOG.info 'birth'
     26 
     27   # load configuration library
     28     config_home = File.dirname(__FILE__)
     29     config_libs = File.join(config_home, 'config.rb')
     30     config_file = File.join(config_home, 'config.yaml')
     31 
     32     require config_libs
     33 
     34   # terminate any existing wmiirc
     35     fs.event.write 'Start wmiirc'
     36 
     37     event 'Start' do |arg|
     38       exit if arg == 'wmiirc'
     39     end
     40 
     41   # apply user configuration
     42     load_config config_file
     43 
     44   # setup tag bar (buttons that correspond to views)
     45     fs.lbar.clear
     46     tags.each {|t| event 'CreateTag', t }
     47     event 'FocusTag', curr_tag
     48 
     49   # register key bindings
     50     fs.keys.write keys.join("\n")
     51     event('Key') {|*a| key(*a) }
     52 
     53   # the main event loop
     54     fs.event.each_line do |line|
     55       line.split("\n").each do |call|
     56         name, args = call.split(' ', 2)
     57 
     58         argv = args.to_s.split(' ')
     59         event name, *argv
     60       end
     61     end
     62 
     63 rescue SystemExit
     64   # ignore it; the program wants to terminate
     65 
     66 rescue Exception => e
     67   LOG.error e
     68 
     69   # allow the user to rescue themselves
     70   system 'xterm &'
     71 
     72   IO.popen('xmessage -nearmouse -file - -buttons Recover,Ignore -print', 'w+') do |f|
     73     f.puts e.inspect, e.backtrace
     74     f.close_write
     75 
     76     if f.read.chomp == 'Recover'
     77       reload_config
     78     end
     79   end
     80 
     81 ensure
     82   LOG.info 'death'
     83 end