class Superterm

Constants

CONFIG

Public Class Methods

const_missing(name) click to toggle source
# File lib/superterm.rb, line 20
def self.const_missing(name)
  require "#{File.dirname(__FILE__)}/superterm_#{name.to_s.downcase}.rb"
  raise "Still not defined: '#{name}'." if !Superterm.const_defined?(name)
  return Superterm.const_get(name)
end
start() click to toggle source
# File lib/superterm.rb, line 26
def self.start
  do_start = false
  FileUtils.touch(CONFIG[:run_path]) if !File.exists?(CONFIG[:run_path])
  
  File.open(CONFIG[:run_path]) do |fp|
    fp.flock(File::LOCK_EX)
    pid = File.read(CONFIG[:run_path]).to_i
    
    if pid <= 0 or !Knj::Unix_proc.pid_running?(pid)
      do_start = true
      File.open(CONFIG[:run_path], "w") do |fp_w|
        fp_w.write Process.pid
      end
      
      Kernel.at_exit do
        File.unlink(CONFIG[:run_path])
      end
    end
  end
  
  if do_start
    win_main = Superterm::Gui::Win_main.new
    Superterm::Unix_socket.new(:win_main => win_main)
    
    Gtk.main
  else
    cmd = nil
    ARGV.each do |val|
      if match = val.match(/^--cmd=(.+)$/)
        cmd = match[1]
        break
      else
        $stderr.puts "Unknown argument: '#{val}'."
        exit
      end
    end
    
    if cmd
      puts "Executing command through sock: #{cmd}"
      
      require "socket"
      UNIXSocket.open(CONFIG[:sock_path]) do |sock|
        sock.puts(cmd)
      end
    end
  end
end