<commit_before>require "curses"

module Feedcellar
  module CursesView
    module_function
    def run(feeds)
      Curses.init_screen
      Curses.noecho
      Curses.nonl

      # TODO
      feeds = feeds.to_a
      feeds.reject! {|feed| feed.title.nil? }

      feeds.each_with_index do |feed, i|
        Curses.setpos(i, 0)
        title = feed.title.gsub(/\n/, " ")
        date = feed.date.strftime("%Y/%m/%d")
        Curses.addstr("#{date} #{title}")
      end
      Curses.setpos(0, 0)

      pos = 0
      begin
        loop do
          case Curses.getch
          when "j"
            pos += 1 if pos < Curses.lines - 1
            Curses.setpos(pos, 0)
          when "k"
            pos -= 1 if pos > 0
            Curses.setpos(pos, 0)
          when "f", 13
            spawn("firefox",
                  feeds[pos].link,
                  [:out, :err] => "/dev/null")
          when "q"
            break
          end
        end
      ensure
        Curses.close_screen
      end
    end
  end
end
<commit_msg>Add description keybind to curses_view<commit_after>require "curses"

module Feedcellar
  module CursesView
    module_function
    def run(feeds)
      Curses.init_screen
      Curses.noecho
      Curses.nonl

      # TODO
      feeds = feeds.to_a
      feeds.reject! {|feed| feed.title.nil? }

      feeds.each_with_index do |feed, i|
        Curses.setpos(i, 0)
        title = feed.title.gsub(/\n/, " ")
        date = feed.date.strftime("%Y/%m/%d")
        Curses.addstr("#{date} #{title}")
      end
      Curses.setpos(0, 0)

      pos = 0
      begin
        loop do
          case Curses.getch
          when "j"
            pos += 1 if pos < Curses.lines - 1
            Curses.setpos(pos, 0)
          when "k"
            pos -= 1 if pos > 0
            Curses.setpos(pos, 0)
          when "f", 13
            spawn("firefox",
                  feeds[pos].link,
                  [:out, :err] => "/dev/null")
          when "d"
            mainwin = Curses.stdscr
            mainwin.clear
            subwin = mainwin.subwin(mainwin.maxy, mainwin.maxx, 0, 0)
            subwin.setpos(0, 0)
            subwin.addstr(feeds[pos].title)
            subwin.setpos(3, 0)
            subwin.addstr(feeds[pos].resource.title)
            subwin.setpos(6, 0)
            subwin.addstr(feeds[pos].description)
            subwin.refresh
            Curses.getch
            subwin.clear
            subwin.close
            feeds.each_with_index do |feed, i|
              Curses.setpos(i, 0)
              title = feed.title.gsub(/\n/, " ")
              date = feed.date.strftime("%Y/%m/%d")
              Curses.addstr("#{date} #{title}")
            end
            Curses.setpos(pos, 0)
          when "q"
            break
          end
        end
      ensure
        Curses.close_screen
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.11437565582371459, 'fraction_numerical': 0.011892270024484085, 'mean_word_length': 1.3308883455582723, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3840872', 'n_tokens_mistral': 1005, 'n_tokens_neox': 961, 'n_words': 198}