Class: Rex::Ui::Text::Output

Inherits:
Output
  • Object
show all
Includes:
Text::Color
Defined in:
lib/rex/ui/text/output.rb,
lib/rex/ui/text/output/buffer/stdout.rb

Overview

This class implements text-based output but is not tied to an output medium.

Direct Known Subclasses

Buffer, File, Socket, Stdio, Tee

Defined Under Namespace

Classes: Buffer, File, Socket, Stdio, Tee

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Output

#flush, #prompting, #prompting?

Constructor Details

#initializeOutput

Returns a new instance of Output.


25
26
27
28
29
30
# File 'lib/rex/ui/text/output.rb', line 25

def initialize
  @config = {
    :color => :auto, # true, false, :auto
  }
  super
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config


31
32
33
# File 'lib/rex/ui/text/output.rb', line 31

def config
  @config
end

#inputObject

Returns the value of attribute input


32
33
34
# File 'lib/rex/ui/text/output.rb', line 32

def input
  @input
end

Instance Method Details

#auto_colorObject


42
43
44
# File 'lib/rex/ui/text/output.rb', line 42

def auto_color
  @config[:color] = :auto
end

#disable_colorObject


34
35
36
# File 'lib/rex/ui/text/output.rb', line 34

def disable_color
  @config[:color] = false
end

#enable_colorObject


38
39
40
# File 'lib/rex/ui/text/output.rb', line 38

def enable_color
  @config[:color] = true
end

73
74
75
# File 'lib/rex/ui/text/output.rb', line 73

def print(msg = '')
  print_raw(substitute_colors(msg))
end

51
52
53
# File 'lib/rex/ui/text/output.rb', line 51

def print_error(msg = '')
  print_line("%bld%red[-]%clr #{msg}")
end

57
58
59
# File 'lib/rex/ui/text/output.rb', line 57

def print_good(msg = '')
  print_line("%bld%grn[+]%clr #{msg}")
end

65
66
67
# File 'lib/rex/ui/text/output.rb', line 65

def print_line(msg = '')
 print(msg + "\n")
end

61
62
63
# File 'lib/rex/ui/text/output.rb', line 61

def print_status(msg = '')
  print_line("%bld%blu[*]%clr #{msg}")
end

69
70
71
# File 'lib/rex/ui/text/output.rb', line 69

def print_warning(msg = '')
  print_line("%bld%yel[!]%clr #{msg}")
end

#puts(*args) ⇒ Object


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rex/ui/text/output.rb', line 80

def puts(*args)
  args.each do |argument|
    line = argument.to_s
    print_raw(line)

    unless line.ends_with? "\n"
      # yes, this is output, but `IO#puts` uses `rb_default_rs`, which is
      # [`$/`](https://github.com/ruby/ruby/blob/3af8e150aded9d162bfd41426aaaae0279e5a653/io.c#L12168-L12172),
      # which is [`$INPUT_RECORD_SEPARATOR`](https://github.com/ruby/ruby/blob/3af8e150aded9d162bfd41426aaaae0279e5a653/lib/English.rb#L83)
      print_raw($INPUT_RECORD_SEPARATOR)
    end
  end

  nil
end

#resetObject


77
78
# File 'lib/rex/ui/text/output.rb', line 77

def reset
end

#update_prompt(prompt = nil) ⇒ Object


46
47
48
49
# File 'lib/rex/ui/text/output.rb', line 46

def update_prompt(prompt = nil)
  return if prompt.nil?
  substitute_colors(prompt, true)
end