Module: Vedeu::EscapeSequences::Esc
Overview
Provides escape sequence strings for setting the cursor position and various display related functions.
Class Method Summary collapse
-
.absent?(variable) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether a variable is nil or empty.
-
.background_codes ⇒ Hash<Symbol => Fixnum>
extended
from Colours
Produces the background named colour escape sequence hash from the foreground escape sequence hash.
-
.border ⇒ String
Return the escape sequence to render a border character.
- .border_off ⇒ String extended from Borders
- .border_on ⇒ String extended from Borders
-
.characters ⇒ Hash<Symbol => String>
extended
from Borders
Provides all the semigraphic characters.
- .clear ⇒ String private
- .clear_line ⇒ String private
- .colour_reset ⇒ String private
- .define_backgrounds! ⇒ void extended from Colours
-
.define_foregrounds! ⇒ void
extended
from Colours
Dynamically creates methods for each terminal named colour.
-
.demodulize(klass) ⇒ String
extended
from Common
private
Removes the module part from the expression in the string.
- .disable_mouse ⇒ String private
- .enable_mouse ⇒ String private
-
.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.
-
.foreground_codes ⇒ Hash<Symbol => Fixnum>
(also: #codes)
extended
from Colours
Produces the foreground named colour escape sequence hash.
- .last_character_position ⇒ String private
- .mouse_codes ⇒ Hash<Symbol => String> extended from Mouse
- .normal ⇒ String private
-
.present?(variable) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether a variable has a useful value.
- .screen_colour_reset ⇒ String private
- .screen_exit ⇒ String private
- .screen_init ⇒ String private
- .setup! ⇒ void extended from Mouse
-
.snake_case(name) ⇒ String
extended
from Common
private
Converts a class name to a lowercase snake case string.
-
.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.
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable is nil or empty.
-
#background_codes ⇒ Hash<Symbol => Fixnum>
included
from Colours
Produces the background named colour escape sequence hash from the foreground escape sequence hash.
-
#border ⇒ String
Return the escape sequence to render a border character.
- #border_off ⇒ String included from Borders
- #border_on ⇒ String included from Borders
-
#characters ⇒ Hash<Symbol => String>
included
from Borders
Provides all the semigraphic characters.
- #clear ⇒ String private
- #clear_line ⇒ String private
- #colour_reset ⇒ String private
- #define_backgrounds! ⇒ void included from Colours
-
#define_foregrounds! ⇒ void
included
from Colours
Dynamically creates methods for each terminal named colour.
-
#demodulize(klass) ⇒ String
included
from Common
private
Removes the module part from the expression in the string.
- #disable_mouse ⇒ String private
- #enable_mouse ⇒ String private
-
#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.
-
#foreground_codes ⇒ Hash<Symbol => Fixnum>
(also: #codes)
included
from Colours
Produces the foreground named colour escape sequence hash.
- #last_character_position ⇒ String private
- #mouse_codes ⇒ Hash<Symbol => String> included from Mouse
- #normal ⇒ String private
-
#present?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable has a useful value.
- #screen_colour_reset ⇒ String private
- #screen_exit ⇒ String private
- #screen_init ⇒ String private
- #setup! ⇒ void included from Mouse
-
#snake_case(name) ⇒ String
included
from Common
private
Converts a class name to a lowercase snake case string.
-
#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.
Class Method Details
.absent?(variable) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether a variable is nil or empty.
.background_codes ⇒ Hash<Symbol => Fixnum> Originally defined in module Colours
Produces the background named colour escape sequence hash from the foreground escape sequence hash.
.border ⇒ String
Return the escape sequence to render a border character.
54 55 56 57 58 |
# File 'lib/vedeu/esc/esc.rb', line 54 def border return '' unless block_given? "#{border_on}#{yield}#{border_off}".freeze end |
.border_off ⇒ String Originally defined in module Borders
.border_on ⇒ String Originally defined in module Borders
.characters ⇒ Hash<Symbol => String> Originally defined in module Borders
Provides all the semigraphic characters.
# 0 1 2 3 4 5 6 7 8 9 A B C D E F 6 ┘ ┐ ┌ └ ┼7 ─ ├ ┤ ┴ ┬ │
.clear ⇒ String (private)
63 64 65 |
# File 'lib/vedeu/esc/esc.rb', line 63 def clear "#{colour_reset}\e[2J".freeze end |
.clear_line ⇒ String (private)
68 69 70 |
# File 'lib/vedeu/esc/esc.rb', line 68 def clear_line "#{colour_reset}\e[2K".freeze end |
.colour_reset ⇒ String (private)
73 74 75 |
# File 'lib/vedeu/esc/esc.rb', line 73 def colour_reset Vedeu::Configuration.colour.to_s end |
.define_backgrounds! ⇒ void Originally defined in module Colours
This method returns an undefined value.
.define_foregrounds! ⇒ void Originally defined in module Colours
This method returns an undefined value.
Dynamically creates methods for each terminal named colour. When a block is given, then the colour is reset to ‘default’ once the block is called.
.demodulize(klass) ⇒ String Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Removes the module part from the expression in the string.
.disable_mouse ⇒ String (private)
78 79 80 81 82 83 84 85 86 |
# File 'lib/vedeu/esc/esc.rb', line 78 def disable_mouse if Vedeu::Configuration.mouse == true "#{mouse_x10_off}".freeze else ''.freeze end end |
.enable_mouse ⇒ String (private)
89 90 91 92 93 94 95 96 97 |
# File 'lib/vedeu/esc/esc.rb', line 89 def enable_mouse if Vedeu::Configuration.mouse == true "#{mouse_x10_on}".freeze else ''.freeze end 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.
29 30 31 32 33 |
# File 'lib/vedeu/esc/esc.rb', line 29 def escape(stream = '') return stream if absent?(stream) stream.gsub(/\e/, '\\e') end |
.foreground_codes ⇒ Hash<Symbol => Fixnum> Also known as: codes Originally defined in module Colours
Produces the foreground named colour escape sequence hash. The background escape sequences are also generated from this by adding 10 to the values. This hash gives rise to methods you can call directly on ‘Esc` to produce the desired colours:
.last_character_position ⇒ String (private)
121 122 123 |
# File 'lib/vedeu/esc/esc.rb', line 121 def last_character_position Vedeu::Geometry::Position[Vedeu.height, Vedeu.width].to_s end |
.mouse_codes ⇒ Hash<Symbol => String> Originally defined in module Mouse
.normal ⇒ String (private)
100 101 102 |
# File 'lib/vedeu/esc/esc.rb', line 100 def normal "#{underline_off}#{bold_off}#{positive}".freeze end |
.present?(variable) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether a variable has a useful value.
.screen_colour_reset ⇒ String (private)
110 111 112 |
# File 'lib/vedeu/esc/esc.rb', line 110 def screen_colour_reset "#{fg_reset}#{bg_reset}".freeze end |
.screen_exit ⇒ String (private)
115 116 117 118 |
# File 'lib/vedeu/esc/esc.rb', line 115 def screen_exit "#{disable_mouse}#{show_cursor}#{screen_colour_reset}#{reset}" \ "#{last_character_position}\n".freeze end |
.screen_init ⇒ String (private)
105 106 107 |
# File 'lib/vedeu/esc/esc.rb', line 105 def screen_init "#{reset}#{clear}#{hide_cursor}#{enable_mouse}".freeze end |
.setup! ⇒ void Originally defined in module Mouse
This method returns an undefined value.
.snake_case(name) ⇒ String Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a class name to a lowercase snake case string.
.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.
41 42 43 44 45 46 47 |
# File 'lib/vedeu/esc/esc.rb', line 41 def string(value = '') return ''.freeze if value.empty? send(value) rescue NoMethodError ''.freeze end |
Instance Method Details
#absent?(variable) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether a variable is nil or empty.
#background_codes ⇒ Hash<Symbol => Fixnum> Originally defined in module Colours
Produces the background named colour escape sequence hash from the foreground escape sequence hash.
#border ⇒ String
Return the escape sequence to render a border character.
54 55 56 57 58 |
# File 'lib/vedeu/esc/esc.rb', line 54 def border return '' unless block_given? "#{border_on}#{yield}#{border_off}".freeze end |
#border_off ⇒ String Originally defined in module Borders
#border_on ⇒ String Originally defined in module Borders
#characters ⇒ Hash<Symbol => String> Originally defined in module Borders
Provides all the semigraphic characters.
# 0 1 2 3 4 5 6 7 8 9 A B C D E F 6 ┘ ┐ ┌ └ ┼7 ─ ├ ┤ ┴ ┬ │
#clear ⇒ String (private)
63 64 65 |
# File 'lib/vedeu/esc/esc.rb', line 63 def clear "#{colour_reset}\e[2J".freeze end |
#clear_line ⇒ String (private)
68 69 70 |
# File 'lib/vedeu/esc/esc.rb', line 68 def clear_line "#{colour_reset}\e[2K".freeze end |
#colour_reset ⇒ String (private)
73 74 75 |
# File 'lib/vedeu/esc/esc.rb', line 73 def colour_reset Vedeu::Configuration.colour.to_s end |
#define_backgrounds! ⇒ void Originally defined in module Colours
This method returns an undefined value.
#define_foregrounds! ⇒ void Originally defined in module Colours
This method returns an undefined value.
Dynamically creates methods for each terminal named colour. When a block is given, then the colour is reset to ‘default’ once the block is called.
#demodulize(klass) ⇒ String Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Removes the module part from the expression in the string.
#disable_mouse ⇒ String (private)
78 79 80 81 82 83 84 85 86 |
# File 'lib/vedeu/esc/esc.rb', line 78 def disable_mouse if Vedeu::Configuration.mouse == true "#{mouse_x10_off}".freeze else ''.freeze end end |
#enable_mouse ⇒ String (private)
89 90 91 92 93 94 95 96 97 |
# File 'lib/vedeu/esc/esc.rb', line 89 def enable_mouse if Vedeu::Configuration.mouse == true "#{mouse_x10_on}".freeze else ''.freeze end 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.
29 30 31 32 33 |
# File 'lib/vedeu/esc/esc.rb', line 29 def escape(stream = '') return stream if absent?(stream) stream.gsub(/\e/, '\\e') end |
#foreground_codes ⇒ Hash<Symbol => Fixnum> Also known as: codes Originally defined in module Colours
Produces the foreground named colour escape sequence hash. The background escape sequences are also generated from this by adding 10 to the values. This hash gives rise to methods you can call directly on ‘Esc` to produce the desired colours:
#last_character_position ⇒ String (private)
121 122 123 |
# File 'lib/vedeu/esc/esc.rb', line 121 def last_character_position Vedeu::Geometry::Position[Vedeu.height, Vedeu.width].to_s end |
#mouse_codes ⇒ Hash<Symbol => String> Originally defined in module Mouse
#normal ⇒ String (private)
100 101 102 |
# File 'lib/vedeu/esc/esc.rb', line 100 def normal "#{underline_off}#{bold_off}#{positive}".freeze end |
#present?(variable) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether a variable has a useful value.
#screen_colour_reset ⇒ String (private)
110 111 112 |
# File 'lib/vedeu/esc/esc.rb', line 110 def screen_colour_reset "#{fg_reset}#{bg_reset}".freeze end |
#screen_exit ⇒ String (private)
115 116 117 118 |
# File 'lib/vedeu/esc/esc.rb', line 115 def screen_exit "#{disable_mouse}#{show_cursor}#{screen_colour_reset}#{reset}" \ "#{last_character_position}\n".freeze end |
#screen_init ⇒ String (private)
105 106 107 |
# File 'lib/vedeu/esc/esc.rb', line 105 def screen_init "#{reset}#{clear}#{hide_cursor}#{enable_mouse}".freeze end |
#setup! ⇒ void Originally defined in module Mouse
This method returns an undefined value.
#snake_case(name) ⇒ String Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a class name to a lowercase snake case string.
#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.
41 42 43 44 45 46 47 |
# File 'lib/vedeu/esc/esc.rb', line 41 def string(value = '') return ''.freeze if value.empty? send(value) rescue NoMethodError ''.freeze end |