Sha256: 79a7496000836fa8d2540befab310e6ecf16218aca9b9ae168d605d46a244cff

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 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])

def batch_mode
    results = @search.more.get_results
    results.each do |r|
      puts "o #{r.name}"
      puts "#{r.link}"
      puts
    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)
cursor = 1

curses_mode do
  #TODO: Gracefully handle window resizing
  #Signal.trap('SIGWINCH', nyaa.status("Window size changed!", :failure))
  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 '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
end

exit

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nyaa-1.0.4 bin/nyaa