Sha256: ef7ffd4092189939cc44621e474def2af42f1cf396b2eb253d7e196bc7b5ac16

Contents?: true

Size: 1.1 KB

Versions: 25

Compression:

Stored size: 1.1 KB

Contents

require 'rex/ui'

module Rex
module Ui
module Text

require 'rex/io/stream_abstraction'

###
#
# This class implements input against a socket.
#
###
class Input::Buffer < Rex::Ui::Text::Input

	class BufferSock
		include Rex::IO::StreamAbstraction	
		def write(buf, opts={})
			syswrite(buf)
		end
	end

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

	def close
		@sock.cleanup_abstraction
	end

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

	def put(msg, opts={})
		@sock.lsock.write(msg)
	end
	
	#
	# Wait for a line of input to be read from a socket.
	#
	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

	#
	# Returns whether or not EOF has been reached on stdin.
	#
	def eof?
		@sock.lsock.closed?
	end

	#
	# Returns the file descriptor associated with a socket.
	#
	def fd
		return @sock.rsock
	end
end

end
end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
librex-0.0.65 lib/rex/ui/text/input/buffer.rb
librex-0.0.63 lib/rex/ui/text/input/buffer.rb
librex-0.0.54 lib/rex/ui/text/input/buffer.rb
librex-0.0.53 lib/rex/ui/text/input/buffer.rb
librex-0.0.52 lib/rex/ui/text/input/buffer.rb
librex-0.0.51 lib/rex/ui/text/input/buffer.rb
librex-0.0.50 lib/rex/ui/text/input/buffer.rb
librex-0.0.49 lib/rex/ui/text/input/buffer.rb
librex-0.0.48 lib/rex/ui/text/input/buffer.rb
librex-0.0.47 lib/rex/ui/text/input/buffer.rb
librex-0.0.46 lib/rex/ui/text/input/buffer.rb
librex-0.0.44 lib/rex/ui/text/input/buffer.rb
librex-0.0.43 lib/rex/ui/text/input/buffer.rb
librex-0.0.42 lib/rex/ui/text/input/buffer.rb
librex-0.0.41 lib/rex/ui/text/input/buffer.rb
librex-0.0.40 lib/rex/ui/text/input/buffer.rb
librex-0.0.39 lib/rex/ui/text/input/buffer.rb
librex-0.0.38 lib/rex/ui/text/input/buffer.rb
librex-0.0.37 lib/rex/ui/text/input/buffer.rb
librex-0.0.36 lib/rex/ui/text/input/buffer.rb