CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/ui/text/input.rb
Views: 11655
1
# -*- coding: binary -*-
2
3
module Rex
4
module Ui
5
module Text
6
7
###
8
#
9
# This class acts as a base for all input mediums. It defines
10
# the interface that will be used by anything that wants to
11
# interact with a derived class.
12
#
13
###
14
class Input
15
16
require 'rex/text/color'
17
18
include Rex::Text::Color
19
20
def initialize
21
self.eof = false
22
@config = {
23
:readline => true, # true, false
24
:color => :auto, # true, false, :auto
25
}
26
super
27
end
28
29
#
30
# Whether or not the input medium supports readline.
31
#
32
def supports_readline
33
return true if not @config
34
35
config[:readline] == true
36
end
37
38
#
39
# Stub for tab completion reset
40
#
41
def reset_tab_completion
42
end
43
44
#
45
# Calls the underlying system read.
46
#
47
def sysread(len)
48
raise NotImplementedError
49
end
50
51
#
52
# Gets a line of input
53
#
54
def gets
55
raise NotImplementedError
56
end
57
58
#
59
# Has the input medium reached end-of-file?
60
#
61
def eof?
62
return eof
63
end
64
65
#
66
# Returns a pollable file descriptor that is associated with this
67
# input medium.
68
#
69
def fd
70
raise NotImplementedError
71
end
72
73
#
74
# Indicates whether or not this input medium is intrinsicly a
75
# shell provider. This would indicate whether or not it
76
# already expects to have a prompt.
77
#
78
def intrinsic_shell?
79
false
80
end
81
82
def update_prompt(new_prompt = '', new_prompt_char = '')
83
self.prompt = new_prompt + new_prompt_char
84
end
85
86
attr_reader :config
87
88
def disable_readline
89
return if not @config
90
@config[:readline] = false
91
end
92
93
def enable_readline
94
return if not @config
95
@config[:readline] = true
96
end
97
98
def disable_color
99
return if not @config
100
@config[:color] = false
101
end
102
103
def enable_color
104
return if not @config
105
@config[:color] = true
106
end
107
108
def auto_color
109
return if not @config
110
@config[:color] = :auto
111
end
112
113
def update_prompt(prompt)
114
substitute_colors(prompt, true)
115
end
116
117
def reset_color
118
end
119
120
attr_accessor :eof, :prompt, :prompt_char, :config
121
122
end
123
124
end
125
end
126
end
127
128