<commit_before>class Whatsa::CLI

  def clear_screen
    50.times { puts "\n" }
    system('clear')
  end

  def welcome
    clear_screen
    puts "Whatsa is a quick-and-dirty lookup utility, powered by Wikipedia!"
    puts "-----------------------------------------------------------------"
  end

  def instructions
    puts "Enter a word (or phrase) to get a brief summary of that subject."
    puts "If you aren't satisfied, type 'more' to get a slightly longer"
    puts "description, or type 'other' to get a list of specific categories"
    puts "regarding that subject, which you can choose by number or name."
    puts "You can type 'exit' to close the program (or 'help' to receive"
    puts "these instructions again) at any time!"
  end

  def ask
    puts "What would you like to know about?"
    gets_command
  end

  def gets_command
    input = nil
    loop do
      print "> "
      input = gets.strip.downcase
      case input
      when "exit"
        exit
      when "help"
        instructions
      when "new"
        run
      else
        break
      end
    end
    input
  end

  def word_wrap(text)
    count = 0
    words = text.split(/ /)
    words.each_with_index do |word, index|
      count += word.length + 1
      if count > 80
        words.insert(index, "\n")
        count = 0
      elsif word.index("\n")
        count = word.length
      end
    end
    words.join(" ").gsub(/^ /, "")
  end

  def display_dmb(dmb)
    raise TypeError unless dmb.is_a?(Whatsa::Disambig)
    clear_screen
    stripped_title = dmb.title.gsub("(disambiguation)", "").strip
    puts word_wrap("Hmmm... #{stripped_title} could mean a few different things:\n")
    dmb.descriptions.each_with_index do |kvp, i|
      desc = kvp[1].empty? ? "" : " - #{kvp[1]}"
      puts word_wrap("#{i + 1}. #{kvp[0].to_s}" + desc)
    end
    puts "\nPlease select a choice, either by name or number."
  end

  def display_sections(text)
    text = text.article if text.is_a?(Whatsa::Section)
    clear_screen
    puts word_wrap("Here are some specific subjects about '#{text.title}':\n")
    text.section_titles.each_with_index { |title, i| puts word_wrap("#{i + 1}. #{title}") }
    puts "\nPlease select a choice, either by name or number."
  end<commit_msg>added optional indent to lines following first in #word_wrap, applied to dmb/sec lists<commit_after>class Whatsa::CLI

  def clear_screen
    50.times { puts "\n" }
    system('clear')
  end

  def welcome
    clear_screen
    puts "Whatsa is a quick-and-dirty lookup utility, powered by Wikipedia!"
    puts "-----------------------------------------------------------------"
  end

  def instructions
    puts "Enter a word (or phrase) to get a brief summary of that subject."
    puts "If you aren't satisfied, type 'more' to get a slightly longer"
    puts "description, or type 'other' to get a list of specific categories"
    puts "regarding that subject, which you can choose by number or name."
    puts "You can type 'exit' to close the program (or 'help' to receive"
    puts "these instructions again) at any time!"
  end

  def ask
    puts "What would you like to know about?"
    gets_command
  end

  def gets_command
    input = nil
    loop do
      print "> "
      input = gets.strip.downcase
      case input
      when "exit"
        exit
      when "help"
        instructions
      when "new"
        run
      else
        break
      end
    end
    input
  end

  # setting an indent will indent the lines AFTER the first line of a paragraph
  def word_wrap(text, indent=0)
    count = 0
    words = text.split(/ /)
    words.each_with_index do |word, index|
      count += word.length + 1
      if count > 80
        words.insert(index, "\n#{' ' * indent}")
        count = indent
      elsif word.index("\n")
        count = word.length
      end
    end
    words.join(" ").gsub(/^ /, "")
  end

  def display_dmb(dmb)
    raise TypeError unless dmb.is_a?(Whatsa::Disambig)
    clear_screen
    stripped_title = dmb.title.gsub("(disambiguation)", "").strip
    puts word_wrap("Hmmm... #{stripped_title} could mean a few different things:\n")
    dmb.descriptions.each_with_index do |kvp, i|
      num = "#{i + 1}. "
      item = "#{kvp[0].to_s}"
      desc = kvp[1].empty? ? "" : " - #{kvp[1]}"
      puts word_wrap(num + item + desc, num.length)
    end
    puts "\nPlease select a choice, either by name or number."
  end

  def display_sections(text)
    text = text.article if text.is_a?(Whatsa::Section)
    clear_screen
    puts word_wrap("Here are some specific subjects about '#{text.title}':\n")
    text.section_titles.each_with_index do |title, i|
      puts word_wrap("#{i + 1}. #{title}", "#{i + 1}. ".length)
    end
    puts "\nPlease select a choice, either by name or number."
  end
{'fraction_non_alphanumeric': 0.13277661795407097, 'fraction_numerical': 0.005219206680584551, 'mean_word_length': 2.2658486707566463, 'pattern_counts': {'":': 0, '<': 3, '<?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': '64059', 'n_tokens_mistral': 1508, 'n_tokens_neox': 1491, 'n_words': 517}