<commit_before>require 'remedy'

class Menu
  include Remedy

  def listen
    Console.set_console_resized_hook! do
      display
    end

    interaction = Interaction.new

    display
    interaction.loop do |key|
      handle key, interaction
      display
    end
  end

  def handle key, interaction
    @last_key = key
    if key == "q" then
      interaction.quit!
    end
  end

  def display
    Viewport.new.draw content, Size([0,0]), header, footer
  end

  def content
    Partial.new.tap{|c| c << <<-CONTENT

    1. Do the thing
    2. Do other thing
    3. Do the third thing
    Q. Quit the thing

    CONTENT
    }
  end

  def header
    Header.new << "The time is: #{Time.now}"
  end

  def footer
    Footer.new << "You pressed: #{@last_key}"
  end
end

Menu.new.listen<commit_msg>Add comments and simply example.<commit_after>require 'remedy'

class Menu
  include Remedy

  # will do basic setup and then loop over user input
  def listen
    # if the user resizes the screen we redraw it to fit the new dimensions
    Console.set_console_resized_hook! do
      draw
    end

    # create an interaction object to handle user input
    interaction = Interaction.new

    # call draw here because interaction blocks until it gets input
    draw

    # loop over user input (individual keypresses)
    interaction.loop do |key|
      @last_key = key
      if key == "q" then
        interaction.quit!
      end
      draw
    end
  end

  # this tells the Viewport to draw to the screen
  def draw
    Viewport.new.draw content, Size([0,0]), header, footer
  end

  # this is the body of our menu, it will be squished if the terminal is too small
  def content
    c = Partial.new
    c << <<-CONTENT

    1. Do the thing
    2. Do other thing
    3. Do the third thing
    Q. Quit the thing

    CONTENT
    c
  end

  # headers are displayed the top of the viewport
  def header
    Header.new << "The time is: #{Time.now}"
  end

  # footers are displayed the bottom of the viewport
  def footer
    Footer.new << "You pressed: #{@last_key}"
  end
end

# display menu and accept user input
Menu.new.listen
{'fraction_non_alphanumeric': 0.0686412787964269, 'fraction_numerical': 0.004701457451810061, 'mean_word_length': 2.383147853736089, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 3, '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': '1510291', 'n_tokens_mistral': 675, 'n_tokens_neox': 648, 'n_words': 265}