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.



20
21
22
23
# File 'lib/rex/ui/text/input/buffer.rb', line 20

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

Instance Method Details

#closeObject



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

def close
	@sock.cleanup_abstraction
end

#eof?Boolean

Returns whether or not EOF has been reached on stdin.

Returns:

  • (Boolean)


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

def eof?
	@sock.lsock.closed?
end

#fdObject

Returns the file descriptor associated with a socket.



68
69
70
# File 'lib/rex/ui/text/input/buffer.rb', line 68

def fd
	return @sock.rsock
end

#getsObject

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



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rex/ui/text/input/buffer.rb', line 40

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) ⇒ Object



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

def put(msg)
	@sock.lsock.write(msg)
end

#sysread(len = 1) ⇒ Object



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

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