reworked how the custom prompts work with different input streams

git-svn-id: file:///home/svn/framework3/trunk@13279 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
David Rude 2011-07-21 18:19:43 +00:00
parent 3046896204
commit 2776669a51
2 changed files with 55 additions and 53 deletions

View File

@ -86,57 +86,6 @@ begin
Thread.current.priority = -20
output.prompting
if framework
if prompt.include?("%T")
t = Time.now
if framework.datastore['PromptTimeFormat']
t = t.strftime(framework.datastore['PromptTimeFormat'])
end
prompt.gsub!(/%T/, t.to_s)
end
if prompt.include?("%H")
hostname = ENV['HOSTNAME']
if hostname.nil?
hostname = `hostname`.split('.')[0]
end
# check if hostname is still nil
if hostname.nil?
hostname = ENV['COMPUTERNAME']
end
if hostname.nil?
hostname = 'unknown'
end
prompt.gsub!(/%H/, hostname.chomp)
end
if prompt.include?("%U")
user = ENV['USER']
if user.nil?
user = `whoami`
end
# check if username is still nil
if user.nil?
user = ENV['USERNAME']
end
if user.nil?
user = 'unknown'
end
prompt.gsub!(/%U/, user.chomp)
end
prompt.gsub!(/%S/, framework.sessions.count.to_s)
prompt.gsub!(/%J/, framework.jobs.count.to_s)
prompt.gsub!(/%L/, Rex::Socket.source_address("50.50.50.50"))
prompt.gsub!(/%D/, ::Dir.getwd)
end
line = ::Readline.readline(prompt, true)
::Readline::HISTORY.pop if (line and line.empty?)
ensure

View File

@ -21,7 +21,8 @@ module Shell
module InputShell
attr_accessor :prompt, :output
def pgets
def pgets()
output.print(prompt)
output.flush
@ -126,7 +127,59 @@ module Shell
break if (self.stop_flag or self.stop_count > 1)
init_tab_complete
line = input.pgets(self.framework)
if framework
if input.prompt.include?("%T")
t = Time.now
if framework.datastore['PromptTimeFormat']
t = t.strftime(framework.datastore['PromptTimeFormat'])
end
input.prompt.gsub!(/%T/, t.to_s)
end
if input.prompt.include?("%H")
hostname = ENV['HOSTNAME']
if hostname.nil?
hostname = `hostname`.split('.')[0]
end
# check if hostname is still nil
if hostname.nil?
hostname = ENV['COMPUTERNAME']
end
if hostname.nil?
hostname = 'unknown'
end
input.prompt.gsub!(/%H/, hostname.chomp)
end
if input.prompt.include?("%U")
user = ENV['USER']
if user.nil?
user = `whoami`
end
# check if username is still nil
if user.nil?
user = ENV['USERNAME']
end
if user.nil?
user = 'unknown'
end
input.prompt.gsub!(/%U/, user.chomp)
end
input.prompt.gsub!(/%S/, framework.sessions.count.to_s)
input.prompt.gsub!(/%J/, framework.jobs.count.to_s)
input.prompt.gsub!(/%L/, Rex::Socket.source_address("50.50.50.50"))
input.prompt.gsub!(/%D/, ::Dir.getwd)
end
line = input.pgets()
log_output(input.prompt)
# If a block was passed in, pass the line to it. If it returns true,