Module: Arachni::Mixins::Terminal

Extended by:
Terminal
Included in:
Terminal, UI::CLI
Defined in:
lib/arachni/mixins/terminal.rb

Overview

Terminal manipulation methods

Driver/demo code

require_relative 'terminal'
require_relative 'progress_bar'

include Terminal
include ProgressBar

# clear the screen
clear_screen!

start_time = Time.now

MAX = 5000
(1..MAX).each {
    |i|

    # move the cursor to its home, top-left of the screen.
    move_to_home!

    prog =  i / Float( MAX ) * 100

    reputs "Counting to #{MAX}..."
    reputs "Progress:   #{prog}%"
    reputs "Current:    #{i}"

    reputs
    reprint eta( prog, start_time ) + "    "
    reputs progress_bar( prog.ceil )

    # make sure that everything is sent out on time
    flush!
    sleep 0.003
}

Instance Method Summary collapse

Instance Method Details

#clear_screen!Object

Clear the bottom of the screen



84
85
86
# File 'lib/arachni/mixins/terminal.rb', line 84

def clear_screen!
    print "\e[2J"
end

#flush!Object

Flushes the STDOUT buffer



98
99
100
# File 'lib/arachni/mixins/terminal.rb', line 98

def flush!
    $stdout.flush
end

#move_to_home!Object

Moves cursor top left to its home



91
92
93
# File 'lib/arachni/mixins/terminal.rb', line 91

def move_to_home!
    print "\e[H"
end

#reprint(str = '') ⇒ Object

Clears the line before printing

Parameters:

  • str (String) (defaults to: '')

    string to output



73
74
75
# File 'lib/arachni/mixins/terminal.rb', line 73

def reprint( str = '' )
    print restr( str )
end

#reputs(str = '') ⇒ Object

Clears the line before printing using ‘puts’

Parameters:

  • str (String) (defaults to: '')

    string to output



64
65
66
# File 'lib/arachni/mixins/terminal.rb', line 64

def reputs( str = '' )
    reprint str + "\n"
end

#restr(str = '') ⇒ Object



77
78
79
# File 'lib/arachni/mixins/terminal.rb', line 77

def restr( str = '' )
    "\e[0K" + str
end