class Mireru::Command

Constants

USAGE

Public Class Methods

new() click to toggle source
# File lib/mireru/command.rb, line 32
def initialize
  @logger = Logger.new
end
run(*arguments) click to toggle source
# File lib/mireru/command.rb, line 27
def run(*arguments)
  new.run(arguments)
end

Public Instance Methods

run(arguments) click to toggle source
# File lib/mireru/command.rb, line 36
def run(arguments)
  options = parse_options(arguments)

  files = files_from_arguments(arguments)

  window = Window.new(files, options)

  window.run
end

Private Instance Methods

files_from_arguments(arguments) click to toggle source
# File lib/mireru/command.rb, line 86
def files_from_arguments(arguments)
  if arguments.empty?
    files = [Dir.pwd]
  else
    files = arguments
  end
  files
end
parse_options(arguments) click to toggle source
# File lib/mireru/command.rb, line 47
def parse_options(arguments)
  options = {}

  parser = OptionParser.new
  parser.on("-h", "--help",
            "Show help message") do
    write_help_message
    exit(true)
  end
  parser.on("-v", "--version",
            "Show version number") do
    write_version_message
    exit(true)
  end
  parser.on("-f", "--font=NAME",
            "Set a font such as \"Monospace 16\"") do |name|
    options[:font] = name
  end
  parser.on("--regexp=PATTERN",
            "Select file name by regular expression pattern") do |pattern|
    options[:regexp] = pattern
  end
  parser.on("--compact",
            "Hide empty directory") do |boolean|
    options[:compact] = boolean
  end
  parser.on("--width=WIDTH",
            "Set window width", Integer) do |width|
    options[:width] = width
  end
  parser.on("--height=HEIGHT",
            "Set window height", Integer) do |height|
    options[:height] = height
  end
  parser.parse!(arguments)

  options
end
write_help_message() click to toggle source
# File lib/mireru/command.rb, line 95
    def write_help_message
      message = <<-EOM
#{USAGE}
  If no argument, then open the current directory.

Options:
  -h, --help
      show this help message

  -f, --font NAME
      set a font such as "Monospace 16"

  --regexp "PATTERN"
      select file name by regular expression

  --compact
      hide empty directory

Key bindings:
  n: next
  p: prev
  e: expand/collapse
  r: reload
  q: quit

  E: extract text using ChupaText

  Control key mask:
    Ctrl+n: 10 tiles next
    Ctrl+p: 10 tiles prev
    Ctrl+e: expand all / collapse even if cursor on file
    Ctrl+h: move position of partition to left
    Ctrl+l: move position of partition to right
    Ctrl+Enter: run selected file (only supports Windows and OS X)

  scroll:
    h: left
    j: down
    k: up
    l: right

    H: 100 times left
    J: 100 times down
    K: 100 times up
    L: 100 times right

    G: down to bottom

  scale:
    +: larger
    -: smaller

  image:
    f: fit window size
    o: scale to the original size

  text:
    f: change font (at random)

  video:
    space: play/pause

  PDF:
    j: next page
    k: prev page
      EOM
      @logger.info(message)
    end
write_version_message() click to toggle source
# File lib/mireru/command.rb, line 164
    def write_version_message
      message = <<-EOM
#{VERSION}
      EOM
      @logger.info(message)
    end