Module: Vedeu::Esc

Extended by:
Esc
Includes:
Vedeu::EscapeSequences::Actions, Vedeu::EscapeSequences::Borders, Vedeu::EscapeSequences::Colours
Included in:
Esc
Defined in:
lib/vedeu/esc/esc.rb

Overview

Provides escape sequence strings for setting the cursor position and various display related functions.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Vedeu::EscapeSequences::Colours

#background_codes, #define_backgrounds!, #define_foregrounds!, #foreground_codes, #setup!

Methods included from Vedeu::EscapeSequences::Borders

#border_off, #border_on, #characters, #define_borders!, #setup!

Methods included from Vedeu::EscapeSequences::Actions

#characters, #define_actions!, #setup!

Class Method Details

.borderString

Return the escape sequence to render a border character.

Yield Returns:

  • (void)

    The border character to wrap with border on and off escape sequences.



49
50
51
52
53
# File 'lib/vedeu/esc/esc.rb', line 49

def border
  return '' unless block_given?

  "#{border_on}#{yield}#{border_off}"
end

.clearString (private)



58
59
60
# File 'lib/vedeu/esc/esc.rb', line 58

def clear
  "#{colour_reset}\e[2J"
end

.clear_lineString (private)



63
64
65
# File 'lib/vedeu/esc/esc.rb', line 63

def clear_line
  "#{colour_reset}\e[2K"
end

.colour_resetString (private)



68
69
70
# File 'lib/vedeu/esc/esc.rb', line 68

def colour_reset
  "#{fg_reset}#{bg_reset}"
end

.escape(stream = '') ⇒ String

Return the stream with the escape sequences escaped so that they can be printed to the terminal instead of being interpreted by the terminal which will render them. This way we can see what escape sequences are being sent along with the content.



24
25
26
27
28
# File 'lib/vedeu/esc/esc.rb', line 24

def escape(stream = '')
  return stream if stream.nil? || stream.empty?

  stream.gsub(/\e/, '\\e')
end

.last_character_positionString (private)



88
89
90
# File 'lib/vedeu/esc/esc.rb', line 88

def last_character_position
  Vedeu::Geometry::Position[Vedeu.height, Vedeu.width].to_s
end

.normalString (private)



73
74
75
# File 'lib/vedeu/esc/esc.rb', line 73

def normal
  "#{underline_off}#{bold_off}#{positive}"
end

.screen_exitString (private)



83
84
85
# File 'lib/vedeu/esc/esc.rb', line 83

def screen_exit
  "#{show_cursor}#{colour_reset}#{reset}#{last_character_position}\n"
end

.screen_initString (private)



78
79
80
# File 'lib/vedeu/esc/esc.rb', line 78

def screen_init
  "#{reset}#{clear}#{hide_cursor}"
end

.string(value = '') ⇒ String

Return the escape sequence string from the list of recognised sequence ‘commands’, or an empty string when the ‘command’ cannot be found.



36
37
38
39
40
41
42
# File 'lib/vedeu/esc/esc.rb', line 36

def string(value = '')
  return '' if value.empty?

  send(value.to_sym)
rescue NoMethodError
  ''
end

Instance Method Details

#borderString

Return the escape sequence to render a border character.

Yield Returns:

  • (void)

    The border character to wrap with border on and off escape sequences.



49
50
51
52
53
# File 'lib/vedeu/esc/esc.rb', line 49

def border
  return '' unless block_given?

  "#{border_on}#{yield}#{border_off}"
end

#clearString (private)



58
59
60
# File 'lib/vedeu/esc/esc.rb', line 58

def clear
  "#{colour_reset}\e[2J"
end

#clear_lineString (private)



63
64
65
# File 'lib/vedeu/esc/esc.rb', line 63

def clear_line
  "#{colour_reset}\e[2K"
end

#colour_resetString (private)



68
69
70
# File 'lib/vedeu/esc/esc.rb', line 68

def colour_reset
  "#{fg_reset}#{bg_reset}"
end

#escape(stream = '') ⇒ String

Return the stream with the escape sequences escaped so that they can be printed to the terminal instead of being interpreted by the terminal which will render them. This way we can see what escape sequences are being sent along with the content.



24
25
26
27
28
# File 'lib/vedeu/esc/esc.rb', line 24

def escape(stream = '')
  return stream if stream.nil? || stream.empty?

  stream.gsub(/\e/, '\\e')
end

#last_character_positionString (private)



88
89
90
# File 'lib/vedeu/esc/esc.rb', line 88

def last_character_position
  Vedeu::Geometry::Position[Vedeu.height, Vedeu.width].to_s
end

#normalString (private)



73
74
75
# File 'lib/vedeu/esc/esc.rb', line 73

def normal
  "#{underline_off}#{bold_off}#{positive}"
end

#screen_exitString (private)



83
84
85
# File 'lib/vedeu/esc/esc.rb', line 83

def screen_exit
  "#{show_cursor}#{colour_reset}#{reset}#{last_character_position}\n"
end

#screen_initString (private)



78
79
80
# File 'lib/vedeu/esc/esc.rb', line 78

def screen_init
  "#{reset}#{clear}#{hide_cursor}"
end

#string(value = '') ⇒ String

Return the escape sequence string from the list of recognised sequence ‘commands’, or an empty string when the ‘command’ cannot be found.



36
37
38
39
40
41
42
# File 'lib/vedeu/esc/esc.rb', line 36

def string(value = '')
  return '' if value.empty?

  send(value.to_sym)
rescue NoMethodError
  ''
end