Module: Vedeu::EscapeSequences::Esc

Extended by:
Esc
Includes:
Common, Actions, Background, Borders, Colours, Foreground, Mouse
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.

Instance Method Summary collapse

Methods included from Mouse

#disable_mouse, #enable_mouse, #mouse_off, #mouse_on, #mouse_x10_off, #mouse_x10_on

Methods included from Foreground

#black, #blue, #cyan, #dark_grey, #default, #foreground, #green, #light_blue, #light_cyan, #light_green, #light_grey, #light_magenta, #light_red, #light_yellow, #magenta, #red, #white, #yellow

Methods included from Colours

#background_codes, #background_colour, #colour, #foreground_codes, #valid_codes, #valid_name?

Methods included from Common

#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?

Methods included from Borders

#border_off, #border_on, #bottom_left, #bottom_right, #horizontal, #horizontal_bottom, #horizontal_top, #top_left, #top_right, #vertical, #vertical_left, #vertical_right

Methods included from Background

#background, #on_black, #on_blue, #on_cyan, #on_dark_grey, #on_default, #on_green, #on_light_blue, #on_light_cyan, #on_light_green, #on_light_grey, #on_light_magenta, #on_light_red, #on_light_yellow, #on_magenta, #on_red, #on_white, #on_yellow

Methods included from Actions

#bg_reset, #blink, #blink_off, #bold, #bold_off, #cursor_position, #dim, #fg_reset, #hide_cursor, #negative, #positive, #reset, #show_cursor, #underline, #underline_off

Instance Method Details

#border(&block) ⇒ String

Return the escape sequence to render a border character.

Parameters:

  • block (Proc)

Yield Returns:

  • (void)

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

Returns:

  • (String)


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

def border(&block)
  return '' unless block_given?

  border_on + yield + border_off
end

#clearString

Returns:

  • (String)


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

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

#clear_lineString

Returns:

  • (String)


85
86
87
# File 'lib/vedeu/esc/esc.rb', line 85

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

#colour_resetString

Returns:

  • (String)


90
91
92
# File 'lib/vedeu/esc/esc.rb', line 90

def colour_reset
  Vedeu::Colours::Colour.coerce(Vedeu.config.colour).to_s
end

#escVedeu::EscapeSequences::Esc



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

def esc
  self
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.

Parameters:

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

Returns:

  • (String)


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

def escape(stream = '')
  return stream if absent?(stream)

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

#last_character_positionString

Returns:

  • (String)


105
106
107
# File 'lib/vedeu/esc/esc.rb', line 105

def last_character_position
  Vedeu::Geometries::Position.coerce([Vedeu.height, Vedeu.width]).to_s
end

#normalString

Returns:

  • (String)


95
96
97
# File 'lib/vedeu/esc/esc.rb', line 95

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

#screen_colour_resetString

Returns:

  • (String)


100
101
102
# File 'lib/vedeu/esc/esc.rb', line 100

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

#screen_exitString

Returns:

  • (String)


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

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

#screen_initString

Returns:

  • (String)


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

def screen_init
  "#{reset}#{clear}#{hide_cursor}#{enable_mouse}"
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.

Parameters:

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

Returns:

  • (String)


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

def string(value = '')
  return '' unless present?(value)

  send(value)
rescue NoMethodError
  ''
end