Module: Cuboid::Support::Mixins::Terminal

Extended by:
Terminal
Included in:
Terminal
Defined in:
lib/cuboid/support/mixins/terminal.rb

Overview

Terminal manipulation methods.

Instance Method Summary collapse

Instance Method Details

#clear_screenObject

Clear the bottom of the screen

[View source]

31
32
33
# File 'lib/cuboid/support/mixins/terminal.rb', line 31

def clear_screen
    print "\e[2J"
end

#empty_screenObject

[View source]

35
36
37
38
39
40
# File 'lib/cuboid/support/mixins/terminal.rb', line 35

def empty_screen
    move_to_home
    rows, cols = $stdin.winsize
    (rows - 1).times{ puts ' ' * cols }
    move_to_home
end

#flushObject

Flushes the STDOUT buffer

[View source]

48
49
50
# File 'lib/cuboid/support/mixins/terminal.rb', line 48

def flush
    $stdout.flush
end

#move_to_homeObject

Moves cursor top left to its home

[View source]

43
44
45
# File 'lib/cuboid/support/mixins/terminal.rb', line 43

def move_to_home
    print "\e[H"
end

#reprint(str = '') ⇒ Object

Clears the line before printing.

Parameters:

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

    String to output.

[View source]

22
23
24
# File 'lib/cuboid/support/mixins/terminal.rb', line 22

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

[View source]

14
15
16
# File 'lib/cuboid/support/mixins/terminal.rb', line 14

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

#restr(str = '') ⇒ Object

[View source]

26
27
28
# File 'lib/cuboid/support/mixins/terminal.rb', line 26

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