Sha256: e13b95fd52d4f52062983f60236e1d30856f827232569e8352732a69836e2152

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

#!/usr/bin/env ruby

$:.unshift File.join(File.dirname(__FILE__),'..','lib')

require 'nyaa'
include Curses

@opts = Nyaa::CLI.parse(ARGV)
@search = Nyaa::Search.new(@opts[:query], @opts[:category], @opts[:filter], @opts[:sort], @opts[:order])

def batch_mode
    results = @search.more.get_results
    results.each do |r|
      puts "#{r.link}\t#{r.name}"
    end
    exit
end

def curses_mode
  begin
    yield
  ensure
    nocbreak
    close_screen
  end
end

# Batch mode
if @opts[:batch]
  batch_mode
end

nyaa = Nyaa::UI.new(@opts, @search);
Curses::timeout = 1000;
cursor = 1;

curses_mode do
  #TODO: Gracefully handle window resizing
  #Signal.trap('SIGWINCH', nyaa.status("Window size changed!", :failure))
  begin
    loop do
      nyaa.header
      nyaa.status
      nyaa.footer
      nyaa.menu(cursor)
      refresh

      case getch
      when *[Key::UP,'k']    then cursor = nyaa.move(cursor, -1)
      when *[Key::DOWN,'j']  then cursor = nyaa.move(cursor, 1)
      when *[Key::NPAGE,'n'] then nyaa.next_page
      when *[Key::PPAGE,'p'] then nyaa.prev_page
      when *[Key::ENTER,'g'] then nyaa.get(cursor)
      when 's' then nyaa.start(cursor);
      when 'i' then nyaa.open(cursor)
      when '?' then nyaa.help
      when 'q' then @search.purge && break
      #when Key::RESIZE then nyaa.status("Window size changed!", :failure)
      end
    end
  rescue Interrupt then end
end
exit

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nyaa-1.0.5 bin/nyaa