whirled_peas 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +6 -0
- data/README.md +62 -29
- data/Rakefile +3 -2
- data/examples/intro.rb +52 -0
- data/examples/scrolling.rb +53 -0
- data/lib/whirled_peas.rb +2 -8
- data/lib/whirled_peas/command_line.rb +25 -33
- data/lib/whirled_peas/graphics/box_painter.rb +9 -1
- data/lib/whirled_peas/graphics/composer.rb +80 -0
- data/lib/whirled_peas/graphics/container_coords.rb +18 -8
- data/lib/whirled_peas/graphics/container_dimensions.rb +17 -7
- data/lib/whirled_peas/graphics/container_painter.rb +151 -33
- data/lib/whirled_peas/graphics/debugger.rb +10 -1
- data/lib/whirled_peas/graphics/grid_painter.rb +14 -2
- data/lib/whirled_peas/graphics/mock_screen.rb +1 -1
- data/lib/whirled_peas/graphics/painter.rb +1 -6
- data/lib/whirled_peas/graphics/renderer.rb +1 -29
- data/lib/whirled_peas/graphics/screen.rb +8 -3
- data/lib/whirled_peas/graphics/text_painter.rb +6 -4
- data/lib/whirled_peas/settings/container_settings.rb +11 -0
- data/lib/whirled_peas/settings/debugger.rb +9 -0
- data/lib/whirled_peas/settings/grid_settings.rb +4 -0
- data/lib/whirled_peas/settings/scrollbar.rb +15 -0
- data/lib/whirled_peas/version.rb +1 -1
- data/screen_test/rendered/elements/box.frame +1 -1
- data/screen_test/rendered/elements/grid.frame +1 -1
- data/screen_test/rendered/elements/screen_overflow.frame +1 -0
- data/screen_test/rendered/elements/text.frame +1 -1
- data/screen_test/rendered/elements/text_multiline.frame +1 -1
- data/screen_test/rendered/settings/align/box.frame +1 -1
- data/screen_test/rendered/settings/align/box.rb +14 -10
- data/screen_test/rendered/settings/align/children_center.frame +1 -1
- data/screen_test/rendered/settings/align/children_left.frame +1 -1
- data/screen_test/rendered/settings/align/children_right.frame +1 -1
- data/screen_test/rendered/settings/align/grid.frame +1 -1
- data/screen_test/rendered/settings/ansi/bold.frame +1 -1
- data/screen_test/rendered/settings/ansi/color.frame +1 -1
- data/screen_test/rendered/settings/ansi/underline.frame +1 -1
- data/screen_test/rendered/settings/border.frame +1 -1
- data/screen_test/rendered/settings/flow/box_b2t.frame +1 -0
- data/screen_test/rendered/settings/flow/box_b2t.rb +24 -0
- data/screen_test/rendered/settings/flow/{l2r.frame → box_l2r.frame} +1 -1
- data/screen_test/rendered/settings/flow/{l2r.rb → box_l2r.rb} +0 -0
- data/screen_test/rendered/settings/flow/box_r2l.frame +1 -0
- data/screen_test/rendered/settings/flow/box_r2l.rb +24 -0
- data/screen_test/rendered/settings/flow/{t2b.frame → box_t2b.frame} +1 -1
- data/screen_test/rendered/settings/flow/{t2b.rb → box_t2b.rb} +0 -0
- data/screen_test/rendered/settings/flow/grid_b2t.frame +1 -0
- data/screen_test/rendered/settings/flow/grid_b2t.rb +14 -0
- data/screen_test/rendered/settings/flow/grid_l2r.frame +1 -0
- data/screen_test/rendered/settings/flow/grid_l2r.rb +14 -0
- data/screen_test/rendered/settings/flow/grid_r2l.frame +1 -0
- data/screen_test/rendered/settings/flow/grid_r2l.rb +14 -0
- data/screen_test/rendered/settings/flow/grid_t2b.frame +1 -0
- data/screen_test/rendered/settings/flow/grid_t2b.rb +14 -0
- data/screen_test/rendered/settings/height/box.frame +1 -1
- data/screen_test/rendered/settings/height/grid.frame +1 -1
- data/screen_test/rendered/settings/height/overflow_box.frame +1 -1
- data/screen_test/rendered/settings/height/overflow_box_l2r.frame +1 -1
- data/screen_test/rendered/settings/height/overflow_box_t2b.frame +1 -1
- data/screen_test/rendered/settings/height/overflow_grid.frame +1 -1
- data/screen_test/rendered/settings/margin.frame +1 -1
- data/screen_test/rendered/settings/padding.frame +1 -1
- data/screen_test/rendered/settings/position/box_left.frame +1 -1
- data/screen_test/rendered/settings/position/box_left_negative.frame +1 -1
- data/screen_test/rendered/settings/position/box_top.frame +1 -1
- data/screen_test/rendered/settings/position/box_top_negative.frame +1 -1
- data/screen_test/rendered/settings/position/grid_left.frame +1 -1
- data/screen_test/rendered/settings/position/grid_left_negative.frame +1 -1
- data/screen_test/rendered/settings/position/grid_top.frame +1 -1
- data/screen_test/rendered/settings/position/grid_top_negative.frame +1 -1
- data/screen_test/rendered/settings/scroll/horiz_box.frame +1 -0
- data/screen_test/rendered/settings/scroll/horiz_box.rb +15 -0
- data/screen_test/rendered/settings/scroll/vert_box.frame +1 -0
- data/screen_test/rendered/settings/scroll/vert_box.rb +18 -0
- data/screen_test/rendered/settings/title_font.frame +1 -1
- data/screen_test/rendered/settings/width/box.frame +1 -1
- data/screen_test/rendered/settings/width/grid.frame +1 -1
- data/screen_test/rendered/settings/width/overflow_box.frame +1 -1
- data/screen_test/rendered/settings/width/overflow_box_l2r.frame +1 -1
- data/screen_test/rendered/settings/width/overflow_box_t2b.frame +1 -1
- data/screen_test/rendered/settings/width/overflow_grid.frame +1 -1
- data/screen_test/screen_tester.rb +13 -3
- metadata +27 -16
- data/bin/debug +0 -35
- data/lib/whirled_peas/debugger.rb +0 -80
- data/lib/whirled_peas/template.rb +0 -5
- data/lib/whirled_peas/template/box_element.rb +0 -8
- data/lib/whirled_peas/template/composer.rb +0 -68
- data/lib/whirled_peas/template/container.rb +0 -28
- data/lib/whirled_peas/template/debugger.rb +0 -34
- data/lib/whirled_peas/template/element.rb +0 -13
- data/lib/whirled_peas/template/grid_element.rb +0 -8
- data/lib/whirled_peas/template/text_element.rb +0 -24
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'whirled_peas/settings/box_settings'
|
2
|
-
require 'whirled_peas/settings/grid_settings'
|
3
|
-
require 'whirled_peas/settings/text_settings'
|
4
|
-
|
5
|
-
require_relative 'box_element'
|
6
|
-
require_relative 'grid_element'
|
7
|
-
require_relative 'text_element'
|
8
|
-
|
9
|
-
module WhirledPeas
|
10
|
-
module Template
|
11
|
-
class Composer
|
12
|
-
def self.next_name
|
13
|
-
@counter ||= 0
|
14
|
-
@counter += 1
|
15
|
-
"Element-#{@counter}"
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.build
|
19
|
-
settings = Settings::BoxSettings.new
|
20
|
-
template = BoxElement.new('TEMPLATE', settings)
|
21
|
-
composer = Template::Composer.new(template)
|
22
|
-
value = yield composer, settings
|
23
|
-
if !template.children? && TextElement.stringable?(value)
|
24
|
-
composer.add_text { value.to_s }
|
25
|
-
end
|
26
|
-
template
|
27
|
-
end
|
28
|
-
|
29
|
-
attr_reader :element
|
30
|
-
|
31
|
-
def initialize(element)
|
32
|
-
@element = element
|
33
|
-
end
|
34
|
-
|
35
|
-
def add_text(name=self.class.next_name, &block)
|
36
|
-
child_settings = Settings::TextSettings.inherit(element.settings)
|
37
|
-
child = TextElement.new(name, child_settings)
|
38
|
-
# TextElements are not composable, so yield nil
|
39
|
-
child.content = yield nil, child_settings
|
40
|
-
element.add_child(child)
|
41
|
-
end
|
42
|
-
|
43
|
-
def add_box(name=self.class.next_name, &block)
|
44
|
-
child_settings = Settings::BoxSettings.inherit(element.settings)
|
45
|
-
child = BoxElement.new(name, child_settings)
|
46
|
-
composer = self.class.new(child)
|
47
|
-
value = yield composer, child.settings
|
48
|
-
element.add_child(child)
|
49
|
-
if !child.children? && TextElement.stringable?(value)
|
50
|
-
composer.add_text("#{name}-Text") { value.to_s }
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def add_grid(name=self.class.next_name, &block)
|
55
|
-
child_settings = Settings::GridSettings.inherit(element.settings)
|
56
|
-
child = GridElement.new(name, child_settings)
|
57
|
-
composer = self.class.new(child)
|
58
|
-
values = yield composer, child.settings
|
59
|
-
element.add_child(child)
|
60
|
-
if !child.children? && values.is_a?(Array)
|
61
|
-
values.each.with_index do |value, index|
|
62
|
-
composer.add_text("#{name}-Text-#{index}") { value.to_s }
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require_relative 'element'
|
2
|
-
|
3
|
-
module WhirledPeas
|
4
|
-
module Template
|
5
|
-
class Container < Element
|
6
|
-
def initialize(name, settings)
|
7
|
-
super
|
8
|
-
@children = []
|
9
|
-
end
|
10
|
-
|
11
|
-
def add_child(child)
|
12
|
-
@children << child
|
13
|
-
end
|
14
|
-
|
15
|
-
def children?
|
16
|
-
@children.length > 0
|
17
|
-
end
|
18
|
-
|
19
|
-
def num_children
|
20
|
-
@children.length
|
21
|
-
end
|
22
|
-
|
23
|
-
def each_child(&block)
|
24
|
-
@children.each(&block)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'whirled_peas/settings/debugger'
|
2
|
-
|
3
|
-
require_relative 'container'
|
4
|
-
require_relative 'text_element'
|
5
|
-
|
6
|
-
module WhirledPeas
|
7
|
-
module Template
|
8
|
-
class Debugger
|
9
|
-
def initialize(element)
|
10
|
-
@element = element
|
11
|
-
end
|
12
|
-
|
13
|
-
def debug(indent='')
|
14
|
-
info = [
|
15
|
-
"#{indent}* #{element.class}(#{element.name})",
|
16
|
-
]
|
17
|
-
if element.is_a?(TextElement)
|
18
|
-
info << "#{indent + ' '}- Content: #{element.content}"
|
19
|
-
end
|
20
|
-
info << "#{indent + ' '}- Settings"
|
21
|
-
info << Settings::Debugger.new(element.settings).debug(indent + ' ')
|
22
|
-
if element.is_a?(Container)
|
23
|
-
info << "#{indent + ' '}- Children"
|
24
|
-
info += element.each_child.map { |c| Debugger.new(c).debug(indent + ' ') }
|
25
|
-
end
|
26
|
-
info.join("\n")
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
attr_reader :element
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require_relative 'element'
|
2
|
-
|
3
|
-
module WhirledPeas
|
4
|
-
module Template
|
5
|
-
class TextElement < Element
|
6
|
-
# List of classes that convert nicely to a string
|
7
|
-
STRINGALBE_CLASSES = [FalseClass, Float, Integer, NilClass, String, Symbol, TrueClass]
|
8
|
-
private_constant :STRINGALBE_CLASSES
|
9
|
-
|
10
|
-
def self.stringable?(value)
|
11
|
-
STRINGALBE_CLASSES.include?(value.class)
|
12
|
-
end
|
13
|
-
|
14
|
-
attr_reader :content
|
15
|
-
|
16
|
-
def content=(val)
|
17
|
-
unless self.class.stringable?(val)
|
18
|
-
raise ArgumentError, "Unsupported type for TextElement: #{val.class}"
|
19
|
-
end
|
20
|
-
@content = val.to_s
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|