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.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -0
  3. data/CHANGELOG.md +6 -0
  4. data/README.md +62 -29
  5. data/Rakefile +3 -2
  6. data/examples/intro.rb +52 -0
  7. data/examples/scrolling.rb +53 -0
  8. data/lib/whirled_peas.rb +2 -8
  9. data/lib/whirled_peas/command_line.rb +25 -33
  10. data/lib/whirled_peas/graphics/box_painter.rb +9 -1
  11. data/lib/whirled_peas/graphics/composer.rb +80 -0
  12. data/lib/whirled_peas/graphics/container_coords.rb +18 -8
  13. data/lib/whirled_peas/graphics/container_dimensions.rb +17 -7
  14. data/lib/whirled_peas/graphics/container_painter.rb +151 -33
  15. data/lib/whirled_peas/graphics/debugger.rb +10 -1
  16. data/lib/whirled_peas/graphics/grid_painter.rb +14 -2
  17. data/lib/whirled_peas/graphics/mock_screen.rb +1 -1
  18. data/lib/whirled_peas/graphics/painter.rb +1 -6
  19. data/lib/whirled_peas/graphics/renderer.rb +1 -29
  20. data/lib/whirled_peas/graphics/screen.rb +8 -3
  21. data/lib/whirled_peas/graphics/text_painter.rb +6 -4
  22. data/lib/whirled_peas/settings/container_settings.rb +11 -0
  23. data/lib/whirled_peas/settings/debugger.rb +9 -0
  24. data/lib/whirled_peas/settings/grid_settings.rb +4 -0
  25. data/lib/whirled_peas/settings/scrollbar.rb +15 -0
  26. data/lib/whirled_peas/version.rb +1 -1
  27. data/screen_test/rendered/elements/box.frame +1 -1
  28. data/screen_test/rendered/elements/grid.frame +1 -1
  29. data/screen_test/rendered/elements/screen_overflow.frame +1 -0
  30. data/screen_test/rendered/elements/text.frame +1 -1
  31. data/screen_test/rendered/elements/text_multiline.frame +1 -1
  32. data/screen_test/rendered/settings/align/box.frame +1 -1
  33. data/screen_test/rendered/settings/align/box.rb +14 -10
  34. data/screen_test/rendered/settings/align/children_center.frame +1 -1
  35. data/screen_test/rendered/settings/align/children_left.frame +1 -1
  36. data/screen_test/rendered/settings/align/children_right.frame +1 -1
  37. data/screen_test/rendered/settings/align/grid.frame +1 -1
  38. data/screen_test/rendered/settings/ansi/bold.frame +1 -1
  39. data/screen_test/rendered/settings/ansi/color.frame +1 -1
  40. data/screen_test/rendered/settings/ansi/underline.frame +1 -1
  41. data/screen_test/rendered/settings/border.frame +1 -1
  42. data/screen_test/rendered/settings/flow/box_b2t.frame +1 -0
  43. data/screen_test/rendered/settings/flow/box_b2t.rb +24 -0
  44. data/screen_test/rendered/settings/flow/{l2r.frame → box_l2r.frame} +1 -1
  45. data/screen_test/rendered/settings/flow/{l2r.rb → box_l2r.rb} +0 -0
  46. data/screen_test/rendered/settings/flow/box_r2l.frame +1 -0
  47. data/screen_test/rendered/settings/flow/box_r2l.rb +24 -0
  48. data/screen_test/rendered/settings/flow/{t2b.frame → box_t2b.frame} +1 -1
  49. data/screen_test/rendered/settings/flow/{t2b.rb → box_t2b.rb} +0 -0
  50. data/screen_test/rendered/settings/flow/grid_b2t.frame +1 -0
  51. data/screen_test/rendered/settings/flow/grid_b2t.rb +14 -0
  52. data/screen_test/rendered/settings/flow/grid_l2r.frame +1 -0
  53. data/screen_test/rendered/settings/flow/grid_l2r.rb +14 -0
  54. data/screen_test/rendered/settings/flow/grid_r2l.frame +1 -0
  55. data/screen_test/rendered/settings/flow/grid_r2l.rb +14 -0
  56. data/screen_test/rendered/settings/flow/grid_t2b.frame +1 -0
  57. data/screen_test/rendered/settings/flow/grid_t2b.rb +14 -0
  58. data/screen_test/rendered/settings/height/box.frame +1 -1
  59. data/screen_test/rendered/settings/height/grid.frame +1 -1
  60. data/screen_test/rendered/settings/height/overflow_box.frame +1 -1
  61. data/screen_test/rendered/settings/height/overflow_box_l2r.frame +1 -1
  62. data/screen_test/rendered/settings/height/overflow_box_t2b.frame +1 -1
  63. data/screen_test/rendered/settings/height/overflow_grid.frame +1 -1
  64. data/screen_test/rendered/settings/margin.frame +1 -1
  65. data/screen_test/rendered/settings/padding.frame +1 -1
  66. data/screen_test/rendered/settings/position/box_left.frame +1 -1
  67. data/screen_test/rendered/settings/position/box_left_negative.frame +1 -1
  68. data/screen_test/rendered/settings/position/box_top.frame +1 -1
  69. data/screen_test/rendered/settings/position/box_top_negative.frame +1 -1
  70. data/screen_test/rendered/settings/position/grid_left.frame +1 -1
  71. data/screen_test/rendered/settings/position/grid_left_negative.frame +1 -1
  72. data/screen_test/rendered/settings/position/grid_top.frame +1 -1
  73. data/screen_test/rendered/settings/position/grid_top_negative.frame +1 -1
  74. data/screen_test/rendered/settings/scroll/horiz_box.frame +1 -0
  75. data/screen_test/rendered/settings/scroll/horiz_box.rb +15 -0
  76. data/screen_test/rendered/settings/scroll/vert_box.frame +1 -0
  77. data/screen_test/rendered/settings/scroll/vert_box.rb +18 -0
  78. data/screen_test/rendered/settings/title_font.frame +1 -1
  79. data/screen_test/rendered/settings/width/box.frame +1 -1
  80. data/screen_test/rendered/settings/width/grid.frame +1 -1
  81. data/screen_test/rendered/settings/width/overflow_box.frame +1 -1
  82. data/screen_test/rendered/settings/width/overflow_box_l2r.frame +1 -1
  83. data/screen_test/rendered/settings/width/overflow_box_t2b.frame +1 -1
  84. data/screen_test/rendered/settings/width/overflow_grid.frame +1 -1
  85. data/screen_test/screen_tester.rb +13 -3
  86. metadata +27 -16
  87. data/bin/debug +0 -35
  88. data/lib/whirled_peas/debugger.rb +0 -80
  89. data/lib/whirled_peas/template.rb +0 -5
  90. data/lib/whirled_peas/template/box_element.rb +0 -8
  91. data/lib/whirled_peas/template/composer.rb +0 -68
  92. data/lib/whirled_peas/template/container.rb +0 -28
  93. data/lib/whirled_peas/template/debugger.rb +0 -34
  94. data/lib/whirled_peas/template/element.rb +0 -13
  95. data/lib/whirled_peas/template/grid_element.rb +0 -8
  96. data/lib/whirled_peas/template/text_element.rb +0 -24
@@ -1,5 +0,0 @@
1
- module WhirledPeas
2
- module Template
3
- end
4
- private_constant :Template
5
- end
@@ -1,8 +0,0 @@
1
- require_relative 'container'
2
-
3
- module WhirledPeas
4
- module Template
5
- class BoxElement < Container
6
- end
7
- end
8
- end
@@ -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,13 +0,0 @@
1
- module WhirledPeas
2
- module Template
3
- class Element
4
- attr_reader :name, :settings
5
-
6
- def initialize(name, settings)
7
- @name = name
8
- @settings = settings
9
- end
10
- end
11
- private_constant :Element
12
- end
13
- end
@@ -1,8 +0,0 @@
1
- require_relative 'container'
2
-
3
- module WhirledPeas
4
- module Template
5
- class GridElement < Container
6
- end
7
- end
8
- 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