Sha256: ecd6447e86b1a2e4ad6c54d5d47f5183885c773c558e7a56a8b6d28766e4b4a4

Contents?: true

Size: 1.04 KB

Versions: 14

Compression:

Stored size: 1.04 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
	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)
		@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

14 entries across 14 versions & 1 rubygems

Version Path
librex-0.0.30 lib/rex/ui/text/input/buffer.rb
librex-0.0.29 lib/rex/ui/text/input/buffer.rb
librex-0.0.28 lib/rex/ui/text/input/buffer.rb
librex-0.0.27 lib/rex/ui/text/input/buffer.rb
librex-0.0.26 lib/rex/ui/text/input/buffer.rb
librex-0.0.25 lib/rex/ui/text/input/buffer.rb
librex-0.0.23 lib/rex/ui/text/input/buffer.rb
librex-0.0.21 lib/rex/ui/text/input/buffer.rb
librex-0.0.19 lib/rex/ui/text/input/buffer.rb
librex-0.0.17 lib/rex/ui/text/input/buffer.rb
librex-0.0.13 lib/rex/ui/text/input/buffer.rb
librex-0.0.12 lib/rex/ui/text/input/buffer.rb
librex-0.0.7 lib/rex/ui/text/input/buffer.rb
librex-0.0.6 lib/rex/ui/text/input/buffer.rb