<commit_before>require_relative 'BaseAction.rb'

#noinspection RubyResolve
module PPCurses

  class GetEnumeratedStringAction < PromptAction

    # enumeration is a list of possible values
    # i.e. CD, Vinyl, MP3
    def initialize(prompt, enumeration) 
      super(prompt)

      # verify enumeration is an array
      unless enumeration.respond_to?('each_with_index') then
        raise
      end

      @options = enumeration
      @current_option = 0
    end

    def print_prompt
      super()
      @options.each_with_index  do |option, index|
        @win.addstr(option)
        if index == @current_option then
          @win.addstr(' [X] ')
        else
          @win.addstr(' [ ] ')
        end

      end
    end

    def execute
      print_prompt()
      # Enables reading arrow keys in getch 
      @win.keypad(true)
      while 1
        noecho
        c = @win.getch

        if c == KEY_LEFT then @current_option = @current_option-1 end
        if c == KEY_RIGHT then @current_option= @current_option+1 end
        if c == 10 then break end

        if @current_option < 0 then @current_option = @options.length-1 end
        if @current_option > @options.length-1 then @current_option = 0 end

        echo
        print_prompt()
      end
      echo
      # Go to next line so that further actions to overwrite
      # the choice
      @win.setpos(@win.cury() + 1, x_padding())
    end

    def data<commit_msg>Style<commit_after>require_relative 'BaseAction.rb'

#noinspection RubyResolve
module PPCurses

  class GetEnumeratedStringAction < PromptAction

    # enumeration is a list of possible values
    # i.e. CD, Vinyl, MP3
    def initialize(prompt, enumeration) 
      super(prompt)

      # verify enumeration is an array
      unless enumeration.respond_to?('each_with_index')
        raise
      end

      @options = enumeration
      @current_option = 0
    end

    def print_prompt
      super()
      @options.each_with_index  do |option, index|
        @win.addstr(option)
        if index == @current_option
          @win.addstr(' [X] ')
        else
          @win.addstr(' [ ] ')
        end

      end
    end

    def execute
      print_prompt
      # Enables reading arrow keys in getch 
      @win.keypad(true)
      while 1
        noecho
        c = @win.getch

        if c == KEY_LEFT then @current_option = @current_option-1 end
        if c == KEY_RIGHT then @current_option = @current_option+1 end
        if c == 10 then break end

        if @current_option < 0 then @current_option = @options.length-1 end
        if @current_option > @options.length-1 then @current_option = 0 end

        echo
        print_prompt
      end
      echo
      # Go to next line so that further actions to overwrite
      # the choice
      @win.setpos(@win.cury + 1, x_padding)
    end

    def data
{'fraction_non_alphanumeric': 0.07743752199929602, 'fraction_numerical': 0.008447729672650475, 'mean_word_length': 2.0757575757575757, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '2134492', 'n_tokens_mistral': 888, 'n_tokens_neox': 829, 'n_words': 255}