<commit_before>module Question
  class List
    def initialize(question, choices)
      @question = question
      @choices = choices
      @active_index = 0
      @finished = false
    end

    def ask
      TTY.interactive do
        while !@finished
          render
          handle_input
        end
        render # render the results a final time and clear the screen
      end

      @choices[@active_index]
    end

    def handle_input
      case TTY.input
      when TTY::CODE::SIGINT
        exit 130
      when TTY::CODE::RETURN, TTY::CODE::SPACE
        @finished = true
      when TTY::CODE::DOWN
        @active_index += 1
        @active_index = 0 if @active_index >= @choices.length
      when TTY::CODE::UP
        @active_index -= 1
        @active_index = @choices.length - 1 if @active_index < 0
      end
    end

    def instructions
      "(Press <enter> when to make selection)"
    end

    def render
      TTY.clear
      print "? ".colorize(:cyan)
      print @question
      print ": "
      if @finished
        print @choices[@active_index][:label].colorize(:green)
      else
        print instructions.colorize(:light_white)
      end
      print "\n"

      unless @finished
        @choices.each_with_index do |choice, index|
          print index == @active_index ? TTY::UI::SELECTED : TTY::UI::UNSELECTED
          print " "
          print choice[:label]
          print "\n"
        end
      end
    end
  end
end<commit_msg>Colorize active item in list<commit_after>module Question
  class List
    def initialize(question, choices)
      @question = question
      @choices = choices
      @active_index = 0
      @finished = false
    end

    def ask
      TTY.interactive do
        while !@finished
          render
          handle_input
        end
        render # render the results a final time and clear the screen
      end

      @choices[@active_index]
    end

    def handle_input
      case TTY.input
      when TTY::CODE::SIGINT
        exit 130
      when TTY::CODE::RETURN, TTY::CODE::SPACE
        @finished = true
      when TTY::CODE::DOWN
        @active_index += 1
        @active_index = 0 if @active_index >= @choices.length
      when TTY::CODE::UP
        @active_index -= 1
        @active_index = @choices.length - 1 if @active_index < 0
      end
    end

    def instructions
      "(Press <enter> when to make selection)"
    end

    def render
      TTY.clear
      print "? ".cyan
      print @question
      print ": "
      if @finished
        print @choices[@active_index][:label].green
      else
        print instructions.light_black
      end
      print "\n"

      unless @finished
        @choices.each_with_index do |choice, index|
          print index == @active_index ? TTY::UI::SELECTED.green : TTY::UI::UNSELECTED
          print " "
          if index == @active_index
            print choice[:label].green
          else
            print choice[:label]
          end
          print "\n"
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08553500660501981, 'fraction_numerical': 0.0059445178335535, 'mean_word_length': 1.7968605724838411, 'pattern_counts': {'":': 2, '<': 7, '<?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': '1960464', 'n_tokens_mistral': 889, 'n_tokens_neox': 860, 'n_words': 252}