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
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_actions! ⇒ void extended from Actions private
- .define_backgrounds! ⇒ void extended from Colours private
- .define_borders! ⇒ void extended from Borders private
-
.define_foregrounds! ⇒ void
extended
from Colours
private
Dynamically creates methods for each terminal named colour.
-
.demodulize(klass) ⇒ String
extended
from Common
Removes the module part from the expression in the string.
-
.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
- .normal ⇒ String private
-
.present?(variable) ⇒ Boolean
extended
from Common
Returns a boolean indicating whether a variable has a useful value.
- .screen_exit ⇒ String private
- .screen_init ⇒ String private
- .setup! ⇒ void extended from Colours
-
.snake_case(name) ⇒ String
extended
from Common
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
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_actions! ⇒ void included from Actions private
- #define_backgrounds! ⇒ void included from Colours private
- #define_borders! ⇒ void included from Borders private
-
#define_foregrounds! ⇒ void
included
from Colours
private
Dynamically creates methods for each terminal named colour.
-
#demodulize(klass) ⇒ String
included
from Common
Removes the module part from the expression in the string.
-
#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
- #normal ⇒ String private
-
#present?(variable) ⇒ Boolean
included
from Common
Returns a boolean indicating whether a variable has a useful value.
- #screen_exit ⇒ String private
- #screen_init ⇒ String private
- #setup! ⇒ void included from Colours
-
#snake_case(name) ⇒ String
included
from Common
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
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.
53 54 55 56 57 |
# File 'lib/vedeu/esc/esc.rb', line 53 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)
62 63 64 |
# File 'lib/vedeu/esc/esc.rb', line 62 def clear "#{colour_reset}\e[2J".freeze end |
.clear_line ⇒ String (private)
67 68 69 |
# File 'lib/vedeu/esc/esc.rb', line 67 def clear_line "#{colour_reset}\e[2K".freeze end |
.colour_reset ⇒ String (private)
72 73 74 |
# File 'lib/vedeu/esc/esc.rb', line 72 def colour_reset "#{fg_reset}#{bg_reset}".freeze end |
.define_actions! ⇒ void (private) Originally defined in module Actions
This method returns an undefined value.
.define_backgrounds! ⇒ void (private) Originally defined in module Colours
This method returns an undefined value.
.define_borders! ⇒ void (private) Originally defined in module Borders
This method returns an undefined value.
.define_foregrounds! ⇒ void (private) 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
Removes the module part from the expression in the string.
.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.
28 29 30 31 32 |
# File 'lib/vedeu/esc/esc.rb', line 28 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)
93 94 95 |
# File 'lib/vedeu/esc/esc.rb', line 93 def last_character_position Vedeu::Geometry::Position[Vedeu.height, Vedeu.width].to_s end |
.normal ⇒ String (private)
77 78 79 |
# File 'lib/vedeu/esc/esc.rb', line 77 def normal "#{underline_off}#{bold_off}#{positive}".freeze end |
.present?(variable) ⇒ Boolean Originally defined in module Common
Returns a boolean indicating whether a variable has a useful value.
.screen_exit ⇒ String (private)
87 88 89 90 |
# File 'lib/vedeu/esc/esc.rb', line 87 def screen_exit "#{show_cursor}#{colour_reset}#{reset}" \ "#{last_character_position}\n".freeze end |
.screen_init ⇒ String (private)
82 83 84 |
# File 'lib/vedeu/esc/esc.rb', line 82 def screen_init "#{reset}#{clear}#{hide_cursor}".freeze end |
.setup! ⇒ void Originally defined in module Colours
This method returns an undefined value.
.snake_case(name) ⇒ String Originally defined in module Common
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.
40 41 42 43 44 45 46 |
# File 'lib/vedeu/esc/esc.rb', line 40 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
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.
53 54 55 56 57 |
# File 'lib/vedeu/esc/esc.rb', line 53 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)
62 63 64 |
# File 'lib/vedeu/esc/esc.rb', line 62 def clear "#{colour_reset}\e[2J".freeze end |
#clear_line ⇒ String (private)
67 68 69 |
# File 'lib/vedeu/esc/esc.rb', line 67 def clear_line "#{colour_reset}\e[2K".freeze end |
#colour_reset ⇒ String (private)
72 73 74 |
# File 'lib/vedeu/esc/esc.rb', line 72 def colour_reset "#{fg_reset}#{bg_reset}".freeze end |
#define_actions! ⇒ void (private) Originally defined in module Actions
This method returns an undefined value.
#define_backgrounds! ⇒ void (private) Originally defined in module Colours
This method returns an undefined value.
#define_borders! ⇒ void (private) Originally defined in module Borders
This method returns an undefined value.
#define_foregrounds! ⇒ void (private) 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
Removes the module part from the expression in the string.
#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.
28 29 30 31 32 |
# File 'lib/vedeu/esc/esc.rb', line 28 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)
93 94 95 |
# File 'lib/vedeu/esc/esc.rb', line 93 def last_character_position Vedeu::Geometry::Position[Vedeu.height, Vedeu.width].to_s end |
#normal ⇒ String (private)
77 78 79 |
# File 'lib/vedeu/esc/esc.rb', line 77 def normal "#{underline_off}#{bold_off}#{positive}".freeze end |
#present?(variable) ⇒ Boolean Originally defined in module Common
Returns a boolean indicating whether a variable has a useful value.
#screen_exit ⇒ String (private)
87 88 89 90 |
# File 'lib/vedeu/esc/esc.rb', line 87 def screen_exit "#{show_cursor}#{colour_reset}#{reset}" \ "#{last_character_position}\n".freeze end |
#screen_init ⇒ String (private)
82 83 84 |
# File 'lib/vedeu/esc/esc.rb', line 82 def screen_init "#{reset}#{clear}#{hide_cursor}".freeze end |
#setup! ⇒ void Originally defined in module Colours
This method returns an undefined value.
#snake_case(name) ⇒ String Originally defined in module Common
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.
40 41 42 43 44 45 46 |
# File 'lib/vedeu/esc/esc.rb', line 40 def string(value = '') return ''.freeze if value.empty? send(value) rescue NoMethodError ''.freeze end |