Module: Vedeu::Esc

Extended by:
Esc
Included in:
Esc
Defined in:
lib/vedeu/support/esc.rb

Instance Method Summary collapse

Instance Method Details

#set_position(y = 1, x = 1, &block) ⇒ String

Return the escape sequence required to position the cursor at a particular point on the screen. When passed a block, will do the aforementioned, call the block and then reposition to this location.

Parameters:

  • y (Fixnum) (defaults to: 1)

    The row/line position.

  • x (Fixnum) (defaults to: 1)

    The column/character position.

  • block (Proc)

Returns:

  • (String)


14
15
16
# File 'lib/vedeu/support/esc.rb', line 14

def set_position(y = 1, x = 1, &block)
  Position.new(y, x).to_s(&block)
end

#string(value = '') ⇒ String

Parameters:

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

Returns:

  • (String)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/vedeu/support/esc.rb', line 20

def string(value = '')
  case value
  when 'bg_reset'      then "\e[48;2;49m"
  when 'blink'         then "\e[5m"
  when 'blink_off'     then "\e[25m"
  when 'bold'          then "\e[1m"
  when 'bold_off'      then "\e[22m"
  when 'clear'         then "\e[38;2;39m\e[48;2;49m\e[2J"
  when 'clear_line'    then "\e[38;2;39m\e[48;2;49m\e[2K"
  when 'colour_reset'  then
    [ string('fg_reset'),
      string('bg_reset') ].join

  when 'dim'           then "\e[2m"
  when 'fg_reset'      then "\e[38;2;39m"
  when 'hide_cursor'   then "\e[?25l"
  when 'negative'      then "\e[7m"
  when 'normal'        then
    [ string('underline_off'),
      string('bold_off'),
      string('positive') ].join

  when 'positive'      then "\e[27m"
  when 'reset'         then "\e[0m"
  when 'screen_init'   then
    [ string('reset'),
      string('clear'),
      string('hide_cursor') ].join

  when 'screen_exit'   then
    [ string('show_cursor'),
      string('colour_reset'),
      string('reset') ].join
  when 'show_cursor'   then "\e[?25h"
  when 'underline'     then "\e[4m"
  when 'underline_off' then "\e[24m"
  else
    ''
  end
end