fixed stuff up

git-svn-id: file:///home/svn/incoming/trunk@2758 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Matt Miller 2005-07-14 22:58:09 +00:00
parent 2ac47328e0
commit df32affc18
6 changed files with 78 additions and 6 deletions

View File

@ -1,8 +1,8 @@
require 'msf/core'
require 'msf/base'
require 'msf/ui'
require 'msf/ui/console/shell'
require 'msf/ui/console/command_dispatcher'
require 'msf/ui/console/shell'
require 'msf/ui/console/table'
require 'find'

View File

@ -29,6 +29,14 @@ class ProgressTracker
self.stop = rng.end
end
#
# Sets the start and resets the position.
#
def start=(start)
@start = start
self.pos = start
end
#
# Steps with a given message and step size.
#
@ -36,6 +44,8 @@ class ProgressTracker
self.pos += n if (self.pos + n <= self.stop)
step_status(status)
self.pos
end
#
@ -73,7 +83,7 @@ class ProgressTracker
#
# The start of the progress.
#
attr_accessor :start
attr_reader :start
#
# The last position in the progress.
#

View File

@ -16,6 +16,7 @@ module Text
class Output < Rex::Ui::Output
require 'rex/ui/text/output/stdio'
require 'rex/ui/text/output/buffer'
def print_error(msg = '')
print_line("[-] #{msg}")
@ -33,6 +34,9 @@ class Output < Rex::Ui::Output
print(msg + "\n")
end
def reset
end
end
end

View File

@ -0,0 +1,35 @@
require 'rex/ui'
module Rex
module Ui
module Text
###
#
# Buffer
# ------
#
# This class implements output against a buffer.
#
###
class Output::Buffer < Rex::Ui::Text::Output
def initialize
self.buf = ''
end
def print(msg = '')
self.buf += msg || ''
end
def reset
self.buf = ''
end
attr_accessor :buf
end
end
end
end

View File

@ -33,7 +33,7 @@ class ProgressTracker < Rex::Ui::ProgressTracker
# Updates the status associated with the current step.
#
def step_status(msg = '')
output.print_status("#{pos}: #{msg}")
output.print_status("#{pos}: #{msg}") if (msg and msg.length > 0)
end
#
@ -50,6 +50,8 @@ class ProgressTracker < Rex::Ui::ProgressTracker
output.print_error("fatal: #{msg}")
end
attr_accessor :output
end
end

View File

@ -3,11 +3,32 @@
$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..'))
require 'test/unit'
require 'rex/ui/text/progress_tracker'
require 'rex/ui'
class Rex::Ui::Text::Table::UnitTest < Test::Unit::TestCase
class Rex::Ui::Text::ProgressTracker::UnitTest < Test::Unit::TestCase
def test_basic
def test_stuff
output = Rex::Ui::Text::Output::Buffer.new
pt = Rex::Ui::Text::ProgressTracker.new(output)
pt.range = 1..10
assert_equal(1, pt.start)
assert_equal(10, pt.stop)
pt.start = 2
assert_equal(2, pt.start)
pt.stop = 9
assert_equal(9, pt.stop)
assert_equal(2, pt.pos)
assert_equal('', output.buf)
assert_equal(3, pt.step)
assert_equal(4, pt.step("test"))
assert_equal("[*] 4: test\n", output.buf)
output.reset
assert_equal("[-] bad\n", pt.error("bad"))
output.reset
assert_equal("[-] fatal: bad\n", pt.abort("bad"))
end
end