Class: ScripTTY::ScreenPattern::Generator
- Inherits:
-
Object
- Object
- ScripTTY::ScreenPattern::Generator
- Defined in:
- lib/scriptty/screen_pattern/generator.rb
Constant Summary collapse
- IGNORE_CHAR_CHOICES =
['.', '~', "'", "^", "-", "?", " ", "░"]
- CURSOR_CHAR_CHOICES =
["@", "+", "&", "█"]
- FIELD_CHAR_CHOICES =
["#", "*", "%", "=", "_", "◆"]
Class Method Summary collapse
-
.generate(name, properties_and_options = {}) ⇒ Object
Generate a screen pattern from a specification.
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(name, properties = {}) ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize(name, properties = {}) ⇒ Generator
Returns a new instance of Generator.
52 53 54 55 56 57 58 59 |
# File 'lib/scriptty/screen_pattern/generator.rb', line 52 def initialize(name, properties={}) properties = properties.dup @force_cursor = properties.delete(:force_cursor) || /\s/ @force_fields = properties.delete(:force_fields) @ignore = properties.delete(:ignore) load_spec(name, properties) make_grid end |
Class Method Details
.generate(name, properties_and_options = {}) ⇒ Object
Generate a screen pattern from a specification
Options:
- :force_fields
-
If true, the fields will be positioned in-line, even if there is matching text or cursor there. :force_fields takes precedence over :force_cursor.
- :force_cursor
-
If true, the cursor will be positioned in-line, even if there is matching text or fields there. :force_cursor may also be a Regexp, in which case the regexp must match in order for the field to be replaced. :force_fields takes precedence over :force_cursor. :force_cursor defaults to the regexp /s/
- :ignore
-
If specified, this is an array of [row, col0..col1] ranges.
42 43 44 |
# File 'lib/scriptty/screen_pattern/generator.rb', line 42 def generate(name, ={}) new(name, ).generate end |
Instance Method Details
#generate ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/scriptty/screen_pattern/generator.rb', line 61 def generate @out = [] @out << "[#{@name}]" @out << "position: #{encode_tuple(@position)}" if @position and @position != [0,0] @out << "size: #{encode_tuple(@size)}" if @char_cursor @out << "char_cursor: #{encode_string(@char_cursor)}" elsif @cursor_pos @out << "cursor_pos: #{encode_tuple(@cursor_pos)}" end @out << "char_ignore: #{encode_string(@char_ignore)}" if @char_ignore @out << "char_field: #{encode_string(@char_field)}" if @char_field if @explicit_fields @out << "fields: <<END" @explicit_fields.each { |f| @out << " #{encode_tuple(f)}" } @out << "END" end if @text_lines @out << "text: <<END" @out += @text_lines @out << "END" end @out.map{|line| "#{line}\n"}.join end |