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/subscriber.rb
Views: 11780
# -*- coding: binary -*-1module Rex2module Ui34###5#6# This module provides a subscriber interface to input/output.7#8###9module Subscriber1011##12#13# Subscribes to the output half of the user interface.14#15##16module Output1718#19# Wraps user_output.print_line20#21def print_line(msg='')22if (user_output)23print_blank_line if user_output.prompting?24user_output.print_line(msg)25end26end2728#29# Wraps user_output.print_status30#31def print_status(msg='')32if (user_output)33print_blank_line if user_output.prompting?34user_output.print_status(msg)35end36end3738#39# Wraps user_output.print_error40#41def print_error(msg='')42if (user_output)43print_blank_line if user_output.prompting?44user_output.print_error(msg)45end46end4748alias_method :print_bad, :print_error4950#51# Wraps user_output.print_good52#53def print_good(msg='')54if (user_output)55print_blank_line if user_output.prompting?56user_output.print_good(msg)57end58end5960#61# Wraps user_output.print_warning62#63def print_warning(msg='')64if (user_output)65print_blank_line if user_output.prompting?66user_output.print_warning(msg)67end68end6970#71# Wraps user_output.print72#73def print(msg='')74user_output.print(msg) if (user_output)75end7677#78# Wraps user_output.flush79#80def flush81user_output.flush if (user_output)82end8384#85# The user output handle.86#87attr_accessor :user_output8889protected9091#92# Prints a blank line. Used when the input is prompting.93#94def print_blank_line95user_output.prompting(false)96user_output.print_line97end9899end100101##102#103# Subscribes to the input half of the user interface.104#105##106module Input107108#109# Gets a line of input from the user_input handle by calling gets.110#111def gets112user_input.gets if (user_input)113end114115#116# The user input handle.117#118attr_accessor :user_input119120end121122include Output123include Input124125#126# Sets the input and output handles.127#128def init_ui(input = nil, output = nil)129self.user_input = input130self.user_output = output131end132133#134# Disables input/output135#136def reset_ui137self.user_input = nil138self.user_output = nil139end140141#142# Copy the user input and output handles from the supplied subscriber.143#144def copy_ui(subscriber)145init_ui(subscriber.user_input, subscriber.user_output)146end147148end149150end151end152153154