def format_results
      main_width = @window_width - (!hide_info? || @show_info ? 42 : 4)
      buf = []

      if @kat.error
        return ["\rConnection failed".red]
      elsif !@kat.results[@page]
        return ["\rNo results    ".red]
      end

      buf << "\r#{ @kat.message[:message] }\n".red if @kat.message

      buf << ("\r%-#{ main_width + 5 }s#{ '      Size     Age      Seeds Leeches' if !hide_info? || @show_info }" %
        ["Page #{ page + 1 } of #{ @kat.pages }", nil]).yellow

      @kat.results[@page].each_with_index do |t, i|
        age = t[:age].split "\xC2\xA0"
        age = '%3d %-6s' % age
        # Filter out the crap that invariably infests torrent names
        title = t[:title].codepoints.map { |c| c > 31 && c < 127 ? c.chr : '?' }.join[0...main_width]
        buf << ("%2d. %-#{ main_width }s#{ ' %10s %10s %7d %7d' if !hide_info? or @show_info }" %
          [i + 1, title, t[:size], age, t[:seeds], t[:leeches]]).tap { |s| s.red! if t[:seeds] == 0 }
      end

      buf << nil
    end
def format_results
      main_width = @window_width - (!hide_info? || @show_info ? 42 : 4)
      buf = []

      if @kat.error
        return ["\rConnection failed".red]
      elsif !@kat.results[@page]
        return ["\rNo results    ".red]
      end

      buf << "\r#{ @kat.message[:message] }\n".red if @kat.message

      buf << ("\r%-#{ main_width + 5 }s#{ '      Size     Age      Seeds Leeches' if !hide_info? || @show_info }" %
        ["Page #{ page + 1 } of #{ @kat.pages }", nil]).yellow

      @kat.results[@page].each_with_index do |t, i|
        age = t[:age].split "\xC2\xA0"
        age = '%3d %-6s' % age
        # Filter out the crap that invariably infests torrent names
        title = t[:title].codepoints.map { |c| c > 31 && c < 127 ? c.chr : '?' }.join[0...main_width]
        buf << ("%2d. %-#{ main_width }s#{ ' %10s %10s %7d %7d' if !hide_info? or @show_info }" %
          [i + 1, title, t[:size], age, t[:seeds], t[:leeches]]).tap { |s| s.red! if t[:seeds] == 0 }
      end

      buf << nil
    end
Format the list of results with header information