Sha256: c892a60f3eac6911f9a1f61708ed197c859da6fa0a857c0279872152e2a00a21

Contents?: true

Size: 1.32 KB

Versions: 18

Compression:

Stored size: 1.32 KB

Contents

# encoding: utf-8

module TTY
  # A class responsible for shell prompt interactions.
  class Prompt
    # A class representing a statement output to prompt.
    class Statement
      # Flag to display newline
      #
      # @api public
      attr_reader :newline

      # Color used to display statement
      #
      # @api public
      attr_reader :color

      # Initialize a Statement
      #
      # @param [TTY::Prompt] prompt
      #
      # @param [Hash] options
      #
      # @option options [Symbol] :newline
      #   force a newline break after the message
      #
      # @option options [Symbol] :color
      #   change the message display to color
      #
      # @api public
      def initialize(prompt, options = {})
        @prompt  = prompt
        @newline = options.fetch(:newline) { true }
        @color   = options.fetch(:color) { false }
      end

      # Output the message to the prompt
      #
      # @param [String] message
      #   the message to be printed to stdout
      #
      # @api public
      def call(message)
        message = @prompt.decorate(message, *color) if color

        if newline && /( |\t)(\e\[\d+(;\d+)*m)?\Z/ !~ message
          @prompt.puts message
        else
          @prompt.print message
          @prompt.flush
        end
      end
    end # Statement
  end # Prompt
end # TTY

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
tty-prompt-0.15.0 lib/tty/prompt/statement.rb
tty-prompt-0.14.0 lib/tty/prompt/statement.rb
tty-prompt-0.13.2 lib/tty/prompt/statement.rb
tty-prompt-0.13.1 lib/tty/prompt/statement.rb
tty-prompt-0.13.0 lib/tty/prompt/statement.rb
austb-tty-prompt-0.13.0 lib/tty/prompt/statement.rb
tty-prompt-0.12.0 lib/tty/prompt/statement.rb
tty-prompt-0.11.0 lib/tty/prompt/statement.rb
tty-prompt-0.10.1 lib/tty/prompt/statement.rb
tty-prompt-0.10.0 lib/tty/prompt/statement.rb
tty-prompt-0.9.0 lib/tty/prompt/statement.rb
tty-prompt-0.8.0 lib/tty/prompt/statement.rb
tty-prompt-0.7.1 lib/tty/prompt/statement.rb
tty-prompt-0.7.0 lib/tty/prompt/statement.rb
tty-prompt-0.6.0 lib/tty/prompt/statement.rb
tty-prompt-0.5.0 lib/tty/prompt/statement.rb
tty-prompt-0.4.0 lib/tty/prompt/statement.rb
tty-prompt-0.3.0 lib/tty/prompt/statement.rb