Class: Rex::Ui::Text::Input::Buffer

Inherits:
Rex::Ui::Text::Input show all
Defined in:
lib/rex/ui/text/input/buffer.rb

Overview

This class implements input against a socket.

Defined Under Namespace

Classes: BufferSock

Constant Summary

Constants included from Color

Color::AnsiAttributes

Instance Attribute Summary

Attributes inherited from Rex::Ui::Text::Input

#config, #eof, #prompt, #prompt_char

Instance Method Summary collapse

Methods inherited from Rex::Ui::Text::Input

#auto_color, #disable_color, #enable_color, #intrinsic_shell?, #reset_color, #reset_tab_completion, #supports_readline, #update_prompt

Methods included from Color

#ansi, #colorize, #do_colorize, #reset_color, #substitute_colors

Constructor Details

#initializeBuffer

Returns a new instance of Buffer.



24
25
26
27
# File 'lib/rex/ui/text/input/buffer.rb', line 24

def initialize
  @sock = BufferSock.new
  @sock.initialize_abstraction
end

Instance Method Details

#closeObject



29
30
31
# File 'lib/rex/ui/text/input/buffer.rb', line 29

def close
  @sock.cleanup_abstraction
end

#eof?Boolean

Returns whether or not EOF has been reached on stdin.

Returns:

  • (Boolean)


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

def eof?
  @sock.lsock.closed?
end

#fdObject

Returns the file descriptor associated with a socket.



72
73
74
# File 'lib/rex/ui/text/input/buffer.rb', line 72

def fd
  return @sock.rsock
end

#getsObject

Wait for a line of input to be read from a socket.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/rex/ui/text/input/buffer.rb', line 44

def gets
  # Initialize the line buffer
  line = ''

  # Read data one byte at a time until we see a LF
  while (true)
    break if line.include?("\n")

    # Read another character of input
    char = @sock.rsock.getc

    # Append this character to the string
    line << char
  end

  return line
end

#put(msg, opts = {}) ⇒ Object



37
38
39
# File 'lib/rex/ui/text/input/buffer.rb', line 37

def put(msg, opts={})
  @sock.lsock.write(msg)
end

#sysread(len = 1) ⇒ Object



33
34
35
# File 'lib/rex/ui/text/input/buffer.rb', line 33

def sysread(len = 1)
  @sock.rsock.sysread(len)
end