Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/rex/ui/text/input/buffer.rb
Views: 11704
# -*- coding: binary -*-12module Rex3module Ui4module Text56require 'rex/io/stream_abstraction'78###9#10# This class implements input against a socket.11#12###13class Input::Buffer < Rex::Ui::Text::Input1415class BufferSock16include Rex::IO::StreamAbstraction17def write(buf, opts={})18syswrite(buf)19end2021def monitor_rsock(*args, **kwargs)22dlog('monitor_rsock: Skipping - functionality not required')23end24end2526def initialize27@sock = BufferSock.new28@sock.initialize_abstraction29end3031def close32@sock.cleanup_abstraction33end3435def sysread(len = 1)36@sock.rsock.sysread(len)37end3839def put(msg, opts={})40@sock.lsock.write(msg)41end4243#44# Wait for a line of input to be read from a socket.45#46def gets47# Initialize the line buffer48line = ''4950# Read data one byte at a time until we see a LF51while (true)52break if line.include?("\n")5354# Read another character of input55char = @sock.rsock.getc5657# Append this character to the string58line << char59end6061return line62end6364#65# Returns whether or not EOF has been reached on stdin.66#67def eof?68@sock.lsock.closed?69end7071#72# Returns the file descriptor associated with a socket.73#74def fd75return @sock.rsock76end77end7879end80end81end828384