Module: Arachni::Mixins::Terminal

Extended by:
Terminal
Included in:
Terminal, UI::CLI::RPC::Instance, UI::CLI::Utilities
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_screenObject

Clear the bottom of the screen



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

def clear_screen
    print "\e[2J"
end

#flushObject

Flushes the STDOUT buffer



104
105
106
# File 'lib/arachni/mixins/terminal.rb', line 104

def flush
    $stdout.flush
end

#move_to_homeObject

Moves cursor top left to its home



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

def move_to_home
    print "\e[H"
end

#reprint(str = '') ⇒ Object

Clears the line before printing

Parameters:

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

    string to output



79
80
81
# File 'lib/arachni/mixins/terminal.rb', line 79

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



70
71
72
# File 'lib/arachni/mixins/terminal.rb', line 70

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

#restr(str = '') ⇒ Object



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

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