<commit_before># encoding: utf-8

require 'forwardable'
require 'pastel'
require 'tty-cursor'
require 'tty-reader'

require_relative 'prompt/answers_collector'
require_relative 'prompt/confirm_question'
require_relative 'prompt/expander'
require_relative 'prompt/enum_list'
require_relative 'prompt/keypress'
require_relative 'prompt/list'
require_relative 'prompt/multi_list'
require_relative 'prompt/multiline'
require_relative 'prompt/mask_question'
require_relative 'prompt/question'
require_relative 'prompt/slider'
require_relative 'prompt/statement'
require_relative 'prompt/suggestion'
require_relative 'prompt/utils'
require_relative 'prompt/version'

module TTY
  # A main entry for asking prompt questions.
  class Prompt
    extend Forwardable

    # Raised when wrong parameter is used to configure prompt
    ConfigurationError = Class.new(StandardError)

    # Raised when type conversion cannot be performed
    ConversionError = Class.new(StandardError)

    # Raised when the passed in validation argument is of wrong type
    ValidationCoercion = Class.new(TypeError)

    # Raised when the required argument is not supplied
    ArgumentRequired = Class.new(ArgumentError)

    # Raised when the argument validation fails
    ArgumentValidation = Class.new(ArgumentError)

    # Raised when the argument is not expected
    InvalidArgument = Class.new(ArgumentError)

    # @api private
    attr_reader :input

    # @api private
    attr_reader :output

    attr_reader :reader

    attr_reader :cursor

    # Prompt prefix
    #
    # @example
    #   prompt = TTY::Prompt.new(prefix: [?])
    #
    # @return [String]
    #
    # @api private
    attr_reader :prefix

    # Theme colors
    #
    # @api private
    attr_reader :active_color, :help_color, :error_color, :enabled_color

    def_delegators :@pastel, :decorate, :strip

    def_delegators :@cursor, :clear_lines, :clear_line,
                   :show, :hide

    def_delegators :@reader, :read_char, :read_line, :read_keypress,
                   :read_multiline, :on, :subscribe, :trigger

    def_delegators :@output, :print, :puts, :flush

    def self.messages
      {
        range?: 'Value %{value} must be within the range %{in}',
        valid?: 'Your answer is invalid (must match %{valid})',
        required?: 'Value must be provided'
      }
    end

    # Initialize a Prompt
    #
    # @param [Hash] options
    # @option options [IO] :input
    #   the input stream
    # @option options [IO] :output
    #   the output stream
    # @option options [Hash] :env
    #   the environment variables
    # @option options [String] :prefix
    #   the prompt prefix, by default empty
    # @option options [Boolean] :enable_color
    #   enable color support, true by default
    # @option options [String] :active_color
    #   the color used for selected option
    # @option options [String] :help_color
    #   the color used for help text
    # @option options [String] :error_color
    #   the color used for displaying error messages
    # @option options [Symbol] :interrupt
    #   handling of Ctrl+C key out of :signal, :exit, :noop
    # @option options [Boolean] :track_history
    #   disable line history tracking, true by default
    #
    # @api public
    def initialize(*args)
      options = Utils.extract_options!(args)
      @input  = options.fetch(:input) { $stdin }
      @output = options.fetch(:output) { $stdout }
      @env    = options.fetch(:env) { ENV }
      @prefix = options.fetch(:prefix) { '' }
      @enabled_color = options[:enable_color]
      @active_color  = options.fetch(:active_color) { :green }
      @help_color    = options.fetch(:help_color)   { :bright_black }
      @error_color   = options.fetch(:error_color)  { :red }
      @interrupt     = options.fetch(:interrupt)    { :error }
      @track_history = options.fetch(:track_history) { true }

      @cursor = TTY::Cursor
      @pastel = Pastel.new(@enabled_color.nil? ? {} : { enabled: @enabled_color })
      @reader = TTY::Reader.new(@input, @output, interrupt: @interrupt,
                                track_history: @track_history, env: @env)
    end

    # Invoke a question type of prompt
    #
    # @example
    #   prompt = TTY::Prompt.new
    #   prompt.invoke_question(Question, "Your name? ")
    #
    # @return [String]
    #
    # @api public
    def invoke_question(object, message, *args, &block)
      options = Utils.extract_options!(args)
      options[:messages] = self.class.messages
      question = object.new(self, options)
      question.(message, &block)
    end

    # Ask a question.
    #
    # @example
    #   propmt = TTY::Prompt.new
    #   prompt.ask("What is your name?")
    #
    # @param [String] message
    #   the question to be asked
    #<commit_msg>Change to use new reader options<commit_after># encoding: utf-8

require 'forwardable'
require 'pastel'
require 'tty-cursor'
require 'tty-reader'

require_relative 'prompt/answers_collector'
require_relative 'prompt/confirm_question'
require_relative 'prompt/expander'
require_relative 'prompt/enum_list'
require_relative 'prompt/keypress'
require_relative 'prompt/list'
require_relative 'prompt/multi_list'
require_relative 'prompt/multiline'
require_relative 'prompt/mask_question'
require_relative 'prompt/question'
require_relative 'prompt/slider'
require_relative 'prompt/statement'
require_relative 'prompt/suggestion'
require_relative 'prompt/utils'
require_relative 'prompt/version'

module TTY
  # A main entry for asking prompt questions.
  class Prompt
    extend Forwardable

    # Raised when wrong parameter is used to configure prompt
    ConfigurationError = Class.new(StandardError)

    # Raised when type conversion cannot be performed
    ConversionError = Class.new(StandardError)

    # Raised when the passed in validation argument is of wrong type
    ValidationCoercion = Class.new(TypeError)

    # Raised when the required argument is not supplied
    ArgumentRequired = Class.new(ArgumentError)

    # Raised when the argument validation fails
    ArgumentValidation = Class.new(ArgumentError)

    # Raised when the argument is not expected
    InvalidArgument = Class.new(ArgumentError)

    # @api private
    attr_reader :input

    # @api private
    attr_reader :output

    attr_reader :reader

    attr_reader :cursor

    # Prompt prefix
    #
    # @example
    #   prompt = TTY::Prompt.new(prefix: [?])
    #
    # @return [String]
    #
    # @api private
    attr_reader :prefix

    # Theme colors
    #
    # @api private
    attr_reader :active_color, :help_color, :error_color, :enabled_color

    def_delegators :@pastel, :decorate, :strip

    def_delegators :@cursor, :clear_lines, :clear_line,
                   :show, :hide

    def_delegators :@reader, :read_char, :read_line, :read_keypress,
                   :read_multiline, :on, :subscribe, :trigger

    def_delegators :@output, :print, :puts, :flush

    def self.messages
      {
        range?: 'Value %{value} must be within the range %{in}',
        valid?: 'Your answer is invalid (must match %{valid})',
        required?: 'Value must be provided'
      }
    end

    # Initialize a Prompt
    #
    # @param [Hash] options
    # @option options [IO] :input
    #   the input stream
    # @option options [IO] :output
    #   the output stream
    # @option options [Hash] :env
    #   the environment variables
    # @option options [String] :prefix
    #   the prompt prefix, by default empty
    # @option options [Boolean] :enable_color
    #   enable color support, true by default
    # @option options [String] :active_color
    #   the color used for selected option
    # @option options [String] :help_color
    #   the color used for help text
    # @option options [String] :error_color
    #   the color used for displaying error messages
    # @option options [Symbol] :interrupt
    #   handling of Ctrl+C key out of :signal, :exit, :noop
    # @option options [Boolean] :track_history
    #   disable line history tracking, true by default
    #
    # @api public
    def initialize(*args)
      options = Utils.extract_options!(args)
      @input  = options.fetch(:input) { $stdin }
      @output = options.fetch(:output) { $stdout }
      @env    = options.fetch(:env) { ENV }
      @prefix = options.fetch(:prefix) { '' }
      @enabled_color = options[:enable_color]
      @active_color  = options.fetch(:active_color) { :green }
      @help_color    = options.fetch(:help_color)   { :bright_black }
      @error_color   = options.fetch(:error_color)  { :red }
      @interrupt     = options.fetch(:interrupt)    { :error }
      @track_history = options.fetch(:track_history) { true }

      @cursor = TTY::Cursor
      @pastel = Pastel.new(@enabled_color.nil? ? {} : { enabled: @enabled_color })
      @reader = TTY::Reader.new(
        input: @input,
        output: @output,
        interrupt: @interrupt,
        track_history: @track_history,
        env: @env
      )
    end

    # Invoke a question type of prompt
    #
    # @example
    #   prompt = TTY::Prompt.new
    #   prompt.invoke_question(Question, "Your name? ")
    #
    # @return [String]
    #
    # @api public
    def invoke_question(object, message, *args, &block)
      options = Utils.extract_options!(args)
      options[:messages] = self.class.messages
      question = object.new(self, options)
      question.(message, &block)
    end

    # Ask a question.
    #
    # @example
    #   propmt = TTY::Prompt.new
    #   prompt.ask("What is your name?")
    #
    # @param [String] message
    #   the question to be asked
    #
{'fraction_non_alphanumeric': 0.10205351586807716, 'fraction_numerical': 0.00020742584526031943, 'mean_word_length': 2.9913079470198674, 'pattern_counts': {'":': 0, '<': 3, '<?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': '303165', 'n_tokens_mistral': 2931, 'n_tokens_neox': 2821, 'n_words': 802}