Sha256: c1e8b2b10467a364406414bcb850b1c0b525e182a35f36d12a94d7eef96387c1

Contents?: true

Size: 1.18 KB

Versions: 15

Compression:

Stored size: 1.18 KB

Contents

# -*- coding: binary -*-
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

15 entries across 15 versions & 3 rubygems

Version Path
rex-2.0.13 lib/rex/ui/text/input/buffer.rb
rex-2.0.12 lib/rex/ui/text/input/buffer.rb
rex-2.0.11 lib/rex/ui/text/input/buffer.rb
rex-2.0.10 lib/rex/ui/text/input/buffer.rb
rex-2.0.9 lib/rex/ui/text/input/buffer.rb
rex-2.0.8 lib/rex/ui/text/input/buffer.rb
rex-2.0.7 lib/rex/ui/text/input/buffer.rb
rex-2.0.5 lib/rex/ui/text/input/buffer.rb
rex-2.0.4 lib/rex/ui/text/input/buffer.rb
dstruct-0.0.1 lib/rex/ui/text/input/buffer.rb
rex-2.0.3 lib/rex/ui/text/input/buffer.rb
librex-0.0.999 lib/rex/ui/text/input/buffer.rb
rex-2.0.2 lib/rex/ui/text/input/buffer.rb
librex-0.0.71 lib/rex/ui/text/input/buffer.rb
librex-0.0.70 lib/rex/ui/text/input/buffer.rb