Class: TTY::Prompt::Statement

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/prompt/statement.rb

Overview

A class representing a statement output to prompt.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prompt, newline: true, color: false) ⇒ Statement

Initialize a Statement

Parameters:



31
32
33
34
35
# File 'lib/tty/prompt/statement.rb', line 31

def initialize(prompt, newline: true, color: false)
  @prompt  = prompt
  @newline = newline
  @color   = color
end

Instance Attribute Details

#colorObject (readonly)

Color used to display statement



16
17
18
# File 'lib/tty/prompt/statement.rb', line 16

def color
  @color
end

#newlineObject (readonly)

Flag to display newline



11
12
13
# File 'lib/tty/prompt/statement.rb', line 11

def newline
  @newline
end

Instance Method Details

#call(message) ⇒ Object

Output the message to the prompt

Parameters:

  • message (String)

    the message to be printed to stdout



43
44
45
46
47
48
49
50
51
52
# File 'lib/tty/prompt/statement.rb', line 43

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