whirled_peas 0.7.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +25 -0
  4. data/README.md +467 -120
  5. data/Rakefile +1 -20
  6. data/bin/easing +33 -0
  7. data/bin/reset_cursor +11 -0
  8. data/bin/screen_test +68 -0
  9. data/examples/graph.rb +54 -0
  10. data/examples/intro.rb +3 -3
  11. data/examples/scrolling.rb +5 -4
  12. data/lib/data/themes.yaml +13 -0
  13. data/lib/whirled_peas.rb +12 -6
  14. data/lib/whirled_peas/animator.rb +5 -0
  15. data/lib/whirled_peas/animator/debug_consumer.rb +17 -0
  16. data/lib/whirled_peas/animator/easing.rb +72 -0
  17. data/lib/whirled_peas/animator/frame.rb +5 -0
  18. data/lib/whirled_peas/animator/frameset.rb +33 -0
  19. data/lib/whirled_peas/animator/producer.rb +35 -0
  20. data/lib/whirled_peas/animator/renderer_consumer.rb +31 -0
  21. data/lib/whirled_peas/command.rb +5 -0
  22. data/lib/whirled_peas/command/base.rb +86 -0
  23. data/lib/whirled_peas/command/config_command.rb +43 -0
  24. data/lib/whirled_peas/command/debug.rb +21 -0
  25. data/lib/whirled_peas/command/fonts.rb +22 -0
  26. data/lib/whirled_peas/command/frame_command.rb +34 -0
  27. data/lib/whirled_peas/command/frames.rb +24 -0
  28. data/lib/whirled_peas/command/help.rb +38 -0
  29. data/lib/whirled_peas/command/play.rb +111 -0
  30. data/lib/whirled_peas/command/record.rb +57 -0
  31. data/lib/whirled_peas/command/still.rb +29 -0
  32. data/lib/whirled_peas/command/themes.rb +76 -0
  33. data/lib/whirled_peas/command_line.rb +24 -212
  34. data/lib/whirled_peas/config.rb +56 -6
  35. data/lib/whirled_peas/device.rb +5 -0
  36. data/lib/whirled_peas/device/null_device.rb +8 -0
  37. data/lib/whirled_peas/device/output_file.rb +19 -0
  38. data/lib/whirled_peas/device/screen.rb +26 -0
  39. data/lib/whirled_peas/graphics/composer.rb +23 -2
  40. data/lib/whirled_peas/graphics/container_painter.rb +91 -0
  41. data/lib/whirled_peas/graphics/content_dimensions.rb +19 -0
  42. data/lib/whirled_peas/graphics/content_painter.rb +20 -0
  43. data/lib/whirled_peas/graphics/graph_dimensions.rb +12 -0
  44. data/lib/whirled_peas/graphics/graph_painter.rb +97 -0
  45. data/lib/whirled_peas/graphics/grid_painter.rb +1 -4
  46. data/lib/whirled_peas/graphics/painter.rb +10 -0
  47. data/lib/whirled_peas/graphics/renderer.rb +8 -2
  48. data/lib/whirled_peas/graphics/text_painter.rb +7 -11
  49. data/lib/whirled_peas/settings/border.rb +25 -4
  50. data/lib/whirled_peas/settings/container_settings.rb +2 -4
  51. data/lib/whirled_peas/settings/element_settings.rb +12 -3
  52. data/lib/whirled_peas/settings/graph_settings.rb +21 -0
  53. data/lib/whirled_peas/settings/grid_settings.rb +7 -0
  54. data/lib/whirled_peas/settings/text_settings.rb +1 -0
  55. data/lib/whirled_peas/settings/theme.rb +40 -0
  56. data/lib/whirled_peas/settings/theme_library.rb +63 -0
  57. data/lib/whirled_peas/utils/ansi.rb +13 -0
  58. data/lib/whirled_peas/utils/file_handler.rb +57 -0
  59. data/lib/whirled_peas/version.rb +1 -1
  60. data/screen_test/elements/box.frame +1 -1
  61. data/screen_test/elements/box.rb +1 -1
  62. data/screen_test/elements/graph.frame +1 -0
  63. data/screen_test/elements/graph.rb +12 -0
  64. data/screen_test/elements/grid.frame +1 -1
  65. data/screen_test/elements/grid.rb +1 -1
  66. data/screen_test/elements/screen_overflow_x.frame +1 -1
  67. data/screen_test/elements/screen_overflow_x.rb +1 -1
  68. data/screen_test/elements/screen_overflow_y.frame +1 -1
  69. data/screen_test/elements/screen_overflow_y.rb +1 -1
  70. data/screen_test/elements/text.frame +1 -1
  71. data/screen_test/elements/text.rb +1 -1
  72. data/screen_test/elements/text_multiline.frame +1 -1
  73. data/screen_test/elements/text_multiline.rb +1 -1
  74. data/screen_test/elements/theme.frame +1 -0
  75. data/screen_test/elements/theme.rb +26 -0
  76. data/screen_test/settings/align/box_around.frame +1 -1
  77. data/screen_test/settings/align/box_around.rb +1 -1
  78. data/screen_test/settings/align/box_between.frame +1 -1
  79. data/screen_test/settings/align/box_between.rb +1 -1
  80. data/screen_test/settings/align/box_center.frame +1 -1
  81. data/screen_test/settings/align/box_center.rb +1 -1
  82. data/screen_test/settings/align/box_default.frame +1 -1
  83. data/screen_test/settings/align/box_default.rb +1 -1
  84. data/screen_test/settings/align/box_evenly.frame +1 -1
  85. data/screen_test/settings/align/box_evenly.rb +1 -1
  86. data/screen_test/settings/align/box_left.frame +1 -1
  87. data/screen_test/settings/align/box_left.rb +1 -1
  88. data/screen_test/settings/align/box_right.frame +1 -1
  89. data/screen_test/settings/align/box_right.rb +1 -1
  90. data/screen_test/settings/align/children_center.frame +1 -1
  91. data/screen_test/settings/align/children_center.rb +1 -1
  92. data/screen_test/settings/align/children_left.frame +1 -1
  93. data/screen_test/settings/align/children_left.rb +1 -1
  94. data/screen_test/settings/align/children_right.frame +1 -1
  95. data/screen_test/settings/align/children_right.rb +1 -1
  96. data/screen_test/settings/align/grid_center.frame +1 -1
  97. data/screen_test/settings/align/grid_center.rb +1 -1
  98. data/screen_test/settings/align/grid_default.frame +1 -1
  99. data/screen_test/settings/align/grid_default.rb +1 -1
  100. data/screen_test/settings/align/grid_left.frame +1 -1
  101. data/screen_test/settings/align/grid_left.rb +1 -1
  102. data/screen_test/settings/align/grid_right.frame +1 -1
  103. data/screen_test/settings/align/grid_right.rb +1 -1
  104. data/screen_test/settings/ansi/bold.frame +1 -1
  105. data/screen_test/settings/ansi/bold.rb +1 -1
  106. data/screen_test/settings/ansi/color.frame +1 -1
  107. data/screen_test/settings/ansi/color.rb +1 -1
  108. data/screen_test/settings/ansi/underline.frame +1 -1
  109. data/screen_test/settings/ansi/underline.rb +1 -1
  110. data/screen_test/settings/border.frame +1 -1
  111. data/screen_test/settings/border.rb +1 -1
  112. data/screen_test/settings/flow/box_b2t.frame +1 -1
  113. data/screen_test/settings/flow/box_b2t.rb +1 -1
  114. data/screen_test/settings/flow/box_l2r.frame +1 -1
  115. data/screen_test/settings/flow/box_l2r.rb +1 -1
  116. data/screen_test/settings/flow/box_r2l.frame +1 -1
  117. data/screen_test/settings/flow/box_r2l.rb +1 -1
  118. data/screen_test/settings/flow/box_t2b.frame +1 -1
  119. data/screen_test/settings/flow/box_t2b.rb +1 -1
  120. data/screen_test/settings/flow/grid_b2t.frame +1 -1
  121. data/screen_test/settings/flow/grid_b2t.rb +2 -2
  122. data/screen_test/settings/flow/grid_l2r.frame +1 -1
  123. data/screen_test/settings/flow/grid_l2r.rb +2 -2
  124. data/screen_test/settings/flow/grid_r2l.frame +1 -1
  125. data/screen_test/settings/flow/grid_r2l.rb +2 -2
  126. data/screen_test/settings/flow/grid_t2b.frame +1 -1
  127. data/screen_test/settings/flow/grid_t2b.rb +2 -2
  128. data/screen_test/settings/height/box.frame +1 -1
  129. data/screen_test/settings/height/box.rb +1 -1
  130. data/screen_test/settings/height/box_border_sizing.frame +1 -1
  131. data/screen_test/settings/height/box_border_sizing.rb +1 -1
  132. data/screen_test/settings/height/grid.frame +1 -1
  133. data/screen_test/settings/height/grid.rb +1 -1
  134. data/screen_test/settings/height/overflow_box.frame +1 -1
  135. data/screen_test/settings/height/overflow_box.rb +1 -1
  136. data/screen_test/settings/height/overflow_box_l2r.frame +1 -1
  137. data/screen_test/settings/height/overflow_box_l2r.rb +1 -1
  138. data/screen_test/settings/height/overflow_box_t2b.frame +1 -1
  139. data/screen_test/settings/height/overflow_box_t2b.rb +1 -1
  140. data/screen_test/settings/height/overflow_grid.frame +1 -1
  141. data/screen_test/settings/height/overflow_grid.rb +1 -1
  142. data/screen_test/settings/margin.frame +1 -1
  143. data/screen_test/settings/margin.rb +1 -1
  144. data/screen_test/settings/padding.frame +1 -1
  145. data/screen_test/settings/padding.rb +1 -1
  146. data/screen_test/settings/position/box_left.frame +1 -1
  147. data/screen_test/settings/position/box_left.rb +1 -1
  148. data/screen_test/settings/position/box_left_negative.frame +1 -1
  149. data/screen_test/settings/position/box_left_negative.rb +1 -1
  150. data/screen_test/settings/position/box_top.frame +1 -1
  151. data/screen_test/settings/position/box_top.rb +1 -1
  152. data/screen_test/settings/position/box_top_negative.frame +1 -1
  153. data/screen_test/settings/position/box_top_negative.rb +1 -1
  154. data/screen_test/settings/position/grid_left.frame +1 -1
  155. data/screen_test/settings/position/grid_left.rb +1 -1
  156. data/screen_test/settings/position/grid_left_negative.frame +1 -1
  157. data/screen_test/settings/position/grid_left_negative.rb +1 -1
  158. data/screen_test/settings/position/grid_top.frame +1 -1
  159. data/screen_test/settings/position/grid_top.rb +1 -1
  160. data/screen_test/settings/position/grid_top_negative.frame +1 -1
  161. data/screen_test/settings/position/grid_top_negative.rb +1 -1
  162. data/screen_test/settings/scroll/horiz_box.frame +1 -1
  163. data/screen_test/settings/scroll/horiz_box.rb +1 -1
  164. data/screen_test/settings/scroll/horiz_box_align_center.rb +1 -1
  165. data/screen_test/settings/scroll/horiz_box_align_right.rb +1 -1
  166. data/screen_test/settings/scroll/vert_box.frame +1 -1
  167. data/screen_test/settings/scroll/vert_box.rb +1 -1
  168. data/screen_test/settings/title_font.frame +1 -1
  169. data/screen_test/settings/title_font.rb +1 -1
  170. data/screen_test/settings/valign/box_around.frame +1 -1
  171. data/screen_test/settings/valign/box_around.rb +1 -1
  172. data/screen_test/settings/valign/box_between.frame +1 -1
  173. data/screen_test/settings/valign/box_between.rb +1 -1
  174. data/screen_test/settings/valign/box_bottom.frame +1 -1
  175. data/screen_test/settings/valign/box_bottom.rb +1 -1
  176. data/screen_test/settings/valign/box_default.frame +1 -1
  177. data/screen_test/settings/valign/box_default.rb +1 -1
  178. data/screen_test/settings/valign/box_evenly.frame +1 -1
  179. data/screen_test/settings/valign/box_evenly.rb +1 -1
  180. data/screen_test/settings/valign/box_middle.frame +1 -1
  181. data/screen_test/settings/valign/box_middle.rb +1 -1
  182. data/screen_test/settings/valign/box_top.frame +1 -1
  183. data/screen_test/settings/valign/box_top.rb +1 -1
  184. data/screen_test/settings/valign/grid_bottom.frame +1 -1
  185. data/screen_test/settings/valign/grid_bottom.rb +1 -1
  186. data/screen_test/settings/valign/grid_default.frame +1 -1
  187. data/screen_test/settings/valign/grid_default.rb +1 -1
  188. data/screen_test/settings/valign/grid_middle.frame +1 -1
  189. data/screen_test/settings/valign/grid_middle.rb +1 -1
  190. data/screen_test/settings/valign/grid_top.frame +1 -1
  191. data/screen_test/settings/valign/grid_top.rb +1 -1
  192. data/screen_test/settings/width/box_border_sizing.frame +1 -1
  193. data/screen_test/settings/width/box_border_sizing.rb +1 -1
  194. data/screen_test/settings/width/box_content.frame +1 -1
  195. data/screen_test/settings/width/box_content.rb +1 -1
  196. data/screen_test/settings/width/box_default.frame +1 -1
  197. data/screen_test/settings/width/box_default.rb +1 -1
  198. data/screen_test/settings/width/grid.frame +1 -1
  199. data/screen_test/settings/width/grid.rb +1 -1
  200. data/screen_test/settings/width/overflow_align_center.frame +1 -1
  201. data/screen_test/settings/width/overflow_align_center.rb +1 -1
  202. data/screen_test/settings/width/overflow_align_right.frame +1 -1
  203. data/screen_test/settings/width/overflow_align_right.rb +1 -1
  204. data/screen_test/settings/width/overflow_box.frame +1 -1
  205. data/screen_test/settings/width/overflow_box.rb +1 -1
  206. data/screen_test/settings/width/overflow_box_l2r.frame +1 -1
  207. data/screen_test/settings/width/overflow_box_l2r.rb +1 -1
  208. data/screen_test/settings/width/overflow_box_t2b.frame +1 -1
  209. data/screen_test/settings/width/overflow_box_t2b.rb +1 -1
  210. data/screen_test/settings/width/overflow_grid.frame +1 -1
  211. data/screen_test/settings/width/overflow_grid.rb +1 -1
  212. data/tools/whirled_peas/tools/screen_tester.rb +131 -65
  213. metadata +42 -9
  214. data/lib/whirled_peas/frame.rb +0 -6
  215. data/lib/whirled_peas/frame/consumer.rb +0 -30
  216. data/lib/whirled_peas/frame/debug_consumer.rb +0 -30
  217. data/lib/whirled_peas/frame/event_loop.rb +0 -90
  218. data/lib/whirled_peas/frame/producer.rb +0 -67
  219. data/lib/whirled_peas/graphics/screen.rb +0 -70
  220. data/lib/whirled_peas/graphics/text_dimensions.rb +0 -15
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whirled_peas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Collier
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-27 00:00:00.000000000 Z
11
+ date: 2021-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline
@@ -70,19 +70,42 @@ files:
70
70
  - README.md
71
71
  - Rakefile
72
72
  - bin/console
73
+ - bin/easing
74
+ - bin/reset_cursor
75
+ - bin/screen_test
73
76
  - bin/setup
77
+ - examples/graph.rb
74
78
  - examples/intro.rb
75
79
  - examples/scrolling.rb
76
80
  - exe/whirled_peas
81
+ - lib/data/themes.yaml
77
82
  - lib/whirled_peas.rb
83
+ - lib/whirled_peas/animator.rb
84
+ - lib/whirled_peas/animator/debug_consumer.rb
85
+ - lib/whirled_peas/animator/easing.rb
86
+ - lib/whirled_peas/animator/frame.rb
87
+ - lib/whirled_peas/animator/frameset.rb
88
+ - lib/whirled_peas/animator/producer.rb
89
+ - lib/whirled_peas/animator/renderer_consumer.rb
90
+ - lib/whirled_peas/command.rb
91
+ - lib/whirled_peas/command/base.rb
92
+ - lib/whirled_peas/command/config_command.rb
93
+ - lib/whirled_peas/command/debug.rb
94
+ - lib/whirled_peas/command/fonts.rb
95
+ - lib/whirled_peas/command/frame_command.rb
96
+ - lib/whirled_peas/command/frames.rb
97
+ - lib/whirled_peas/command/help.rb
98
+ - lib/whirled_peas/command/play.rb
99
+ - lib/whirled_peas/command/record.rb
100
+ - lib/whirled_peas/command/still.rb
101
+ - lib/whirled_peas/command/themes.rb
78
102
  - lib/whirled_peas/command_line.rb
79
103
  - lib/whirled_peas/config.rb
104
+ - lib/whirled_peas/device.rb
105
+ - lib/whirled_peas/device/null_device.rb
106
+ - lib/whirled_peas/device/output_file.rb
107
+ - lib/whirled_peas/device/screen.rb
80
108
  - lib/whirled_peas/errors.rb
81
- - lib/whirled_peas/frame.rb
82
- - lib/whirled_peas/frame/consumer.rb
83
- - lib/whirled_peas/frame/debug_consumer.rb
84
- - lib/whirled_peas/frame/event_loop.rb
85
- - lib/whirled_peas/frame/producer.rb
86
109
  - lib/whirled_peas/graphics.rb
87
110
  - lib/whirled_peas/graphics/box_painter.rb
88
111
  - lib/whirled_peas/graphics/canvas.rb
@@ -90,13 +113,15 @@ files:
90
113
  - lib/whirled_peas/graphics/container_coords.rb
91
114
  - lib/whirled_peas/graphics/container_dimensions.rb
92
115
  - lib/whirled_peas/graphics/container_painter.rb
116
+ - lib/whirled_peas/graphics/content_dimensions.rb
117
+ - lib/whirled_peas/graphics/content_painter.rb
93
118
  - lib/whirled_peas/graphics/debugger.rb
119
+ - lib/whirled_peas/graphics/graph_dimensions.rb
120
+ - lib/whirled_peas/graphics/graph_painter.rb
94
121
  - lib/whirled_peas/graphics/grid_painter.rb
95
122
  - lib/whirled_peas/graphics/mock_screen.rb
96
123
  - lib/whirled_peas/graphics/painter.rb
97
124
  - lib/whirled_peas/graphics/renderer.rb
98
- - lib/whirled_peas/graphics/screen.rb
99
- - lib/whirled_peas/graphics/text_dimensions.rb
100
125
  - lib/whirled_peas/graphics/text_painter.rb
101
126
  - lib/whirled_peas/null_logger.rb
102
127
  - lib/whirled_peas/settings.rb
@@ -109,6 +134,7 @@ files:
109
134
  - lib/whirled_peas/settings/debugger.rb
110
135
  - lib/whirled_peas/settings/display_flow.rb
111
136
  - lib/whirled_peas/settings/element_settings.rb
137
+ - lib/whirled_peas/settings/graph_settings.rb
112
138
  - lib/whirled_peas/settings/grid_settings.rb
113
139
  - lib/whirled_peas/settings/margin.rb
114
140
  - lib/whirled_peas/settings/padding.rb
@@ -118,14 +144,19 @@ files:
118
144
  - lib/whirled_peas/settings/spacing.rb
119
145
  - lib/whirled_peas/settings/text_color.rb
120
146
  - lib/whirled_peas/settings/text_settings.rb
147
+ - lib/whirled_peas/settings/theme.rb
148
+ - lib/whirled_peas/settings/theme_library.rb
121
149
  - lib/whirled_peas/settings/vert_alignment.rb
122
150
  - lib/whirled_peas/utils.rb
123
151
  - lib/whirled_peas/utils/ansi.rb
152
+ - lib/whirled_peas/utils/file_handler.rb
124
153
  - lib/whirled_peas/utils/formatted_string.rb
125
154
  - lib/whirled_peas/utils/title_font.rb
126
155
  - lib/whirled_peas/version.rb
127
156
  - screen_test/elements/box.frame
128
157
  - screen_test/elements/box.rb
158
+ - screen_test/elements/graph.frame
159
+ - screen_test/elements/graph.rb
129
160
  - screen_test/elements/grid.frame
130
161
  - screen_test/elements/grid.rb
131
162
  - screen_test/elements/screen_overflow_x.frame
@@ -136,6 +167,8 @@ files:
136
167
  - screen_test/elements/text.rb
137
168
  - screen_test/elements/text_multiline.frame
138
169
  - screen_test/elements/text_multiline.rb
170
+ - screen_test/elements/theme.frame
171
+ - screen_test/elements/theme.rb
139
172
  - screen_test/settings/align/box_around.frame
140
173
  - screen_test/settings/align/box_around.rb
141
174
  - screen_test/settings/align/box_between.frame
@@ -1,6 +0,0 @@
1
- module WhirledPeas
2
- module Frame
3
- end
4
-
5
- private_constant :Frame
6
- end
@@ -1,30 +0,0 @@
1
- module WhirledPeas
2
- module Frame
3
- # Abstract class for consuming frame events.
4
- class Consumer
5
- EOF = '__EOF__'
6
-
7
- def enqueue(name, duration, args)
8
- raise NotImplemented, "#{self.class} must implement #enqueue"
9
- end
10
-
11
- def running?
12
- @running == true
13
- end
14
-
15
- def start
16
- self.running = true
17
- end
18
-
19
- def stop
20
- enqueue(EOF, nil, {})
21
- end
22
-
23
- private
24
-
25
- attr_writer :running
26
- end
27
-
28
- private_constant :Consumer
29
- end
30
- end
@@ -1,30 +0,0 @@
1
- require 'whirled_peas/null_logger'
2
-
3
- require_relative 'consumer'
4
-
5
- module WhirledPeas
6
- module Frame
7
- class DebugConsumer < Consumer
8
- LOGGER_ID = 'PRINTER'
9
-
10
- def initialize(output=STDOUT, logger=NullLogger.new)
11
- @output = output
12
- @logger = logger
13
- end
14
-
15
- def enqueue(name, duration, args)
16
- if name == EOF
17
- output.puts "EOF frame detected"
18
- else
19
- displayed_for = duration ? "#{duration} second(s)" : '1 frame'
20
- args_str = args.empty? ? '' : " '#{JSON.generate(args)}'"
21
- output.puts "Frame '#{name}' displayed for #{displayed_for}#{args_str}"
22
- end
23
- end
24
-
25
- private
26
-
27
- attr_reader :output, :logger
28
- end
29
- end
30
- end
@@ -1,90 +0,0 @@
1
- require 'whirled_peas/null_logger'
2
- require 'whirled_peas/graphics/screen'
3
-
4
- require_relative 'consumer'
5
-
6
- module WhirledPeas
7
- module Frame
8
- class EventLoop < Consumer
9
- DEFAULT_REFRESH_RATE = 30
10
-
11
- LOGGER_ID = 'EVENT LOOP'
12
-
13
- def initialize(
14
- template_factory,
15
- loading_template_factory=nil,
16
- refresh_rate: DEFAULT_REFRESH_RATE,
17
- logger: NullLogger.new,
18
- screen: Graphics::Screen.new
19
- )
20
- @template_factory = template_factory
21
- @loading_template_factory = loading_template_factory
22
- @queue = Queue.new
23
- @frame_duration = 1.0 / refresh_rate
24
- @logger = logger
25
- @screen = screen
26
- end
27
-
28
- def enqueue(name, duration, args)
29
- # If duration is nil, set it to the duration of a single frame
30
- queue.push([name, duration || frame_duration, args])
31
- end
32
-
33
- def start
34
- super
35
- wait_for_content
36
- play_content
37
- rescue
38
- self.running = false
39
- logger.warn(LOGGER_ID) { 'Exiting with error' }
40
- raise
41
- ensure
42
- screen.finalize
43
- end
44
-
45
- private
46
-
47
- attr_reader :template_factory, :loading_template_factory, :queue, :frame_duration, :logger, :screen
48
-
49
- def wait_for_content
50
- if loading_template_factory
51
- play_loading_screen
52
- else
53
- sleep(frame_duration) while queue.empty?
54
- end
55
- end
56
-
57
- def play_loading_screen
58
- while queue.empty?
59
- screen.paint(loading_template_factory.build)
60
- sleep(frame_duration)
61
- end
62
- end
63
-
64
- def play_content
65
- template = nil
66
- frame_until = Time.new(0) # Tell the loop to immediately pick up a new frame
67
- while running?
68
- frame_start = Time.now
69
- next_frame_at = frame_start + frame_duration
70
- if frame_until > frame_start
71
- # While we're still displaying the previous frame, refresh the screen
72
- screen.refresh
73
- elsif !queue.empty?
74
- name, duration, args = queue.pop
75
- if name == EOF
76
- self.running = false
77
- else
78
- frame_until = frame_start + duration
79
- template = template_factory.build(name, args)
80
- screen.paint(template)
81
- end
82
- else
83
- wait_for_content
84
- end
85
- sleep([0, next_frame_at - Time.now].max)
86
- end
87
- end
88
- end
89
- end
90
- end
@@ -1,67 +0,0 @@
1
- require 'socket'
2
- require 'json'
3
-
4
- require 'whirled_peas/null_logger'
5
-
6
- module WhirledPeas
7
- module Frame
8
- # A Producer is the object given to the driver as the interface that allows
9
- # the driver to emit frame events. The recommended way of creating a Producer
10
- # is by invoking `Producer.produce` as it handles the lifecycle methods of
11
- # the consumer.
12
- class Producer
13
- LOGGER_ID = 'PRODUCER'
14
-
15
- # Manages the consumer lifecycle and yields a Producer to send frames to the
16
- # consumer
17
- #
18
- # @param consumer [Consumer] instance that consumes frame events through
19
- # `#enqueue`
20
- def self.produce(consumer, logger=NullLogger.new)
21
- producer = new(consumer, logger)
22
- consumer_thread = Thread.new do
23
- Thread.current.report_on_exception = false
24
- consumer.start
25
- end
26
- yield producer
27
- producer.flush
28
- rescue => e
29
- logger.warn(LOGGER_ID) { 'Exited with error' }
30
- logger.error(LOGGER_ID) { e }
31
- raise
32
- ensure
33
- consumer.stop
34
- consumer_thread.join if consumer_thread
35
- end
36
-
37
- def initialize(consumer, logger=NullLogger.new)
38
- @consumer = consumer
39
- @logger = logger
40
- @queue = Queue.new
41
- end
42
-
43
- # Buffer a frame to be played for the given duration. `#flush` must be called
44
- # for frames to get pushed to the EventLoop.
45
- #
46
- # @param name [String] name of frame, which is passed to #build of the
47
- # TemplateFactory
48
- # @param duration [Float|Integer] duration in seconds the frame should be,
49
- # displayed (default is nil, which results in a duration of a single refresh
50
- # cycle)
51
- # @param args [Hash] key/value pair of arguments, which is passed to #build of
52
- # the TemplateFactory
53
- def send_frame(name, duration: nil, args: {})
54
- queue.push([name, duration, args])
55
- end
56
-
57
- # Send any buffered frames to the EventLoop
58
- def flush
59
- consumer.enqueue(*queue.pop) while !queue.empty?
60
- end
61
-
62
- private
63
-
64
- attr_reader :consumer, :logger, :queue
65
- end
66
- end
67
- end
@@ -1,70 +0,0 @@
1
- require 'highline'
2
-
3
- require 'whirled_peas/utils/ansi'
4
-
5
- require_relative 'renderer'
6
-
7
- module WhirledPeas
8
- module Graphics
9
- class Screen
10
- def self.current_dimensions
11
- width, height = HighLine.new.terminal.terminal_size
12
- [width || 0, height || 0]
13
- end
14
-
15
- def initialize(width: nil, height: nil, output: STDOUT)
16
- @output = output
17
- @terminal = HighLine.new.terminal
18
- @strokes = []
19
- if width && height
20
- @width = width
21
- @height = height
22
- else
23
- refresh_size!
24
- Signal.trap('SIGWINCH', proc { self.refresh_size! })
25
- end
26
- end
27
-
28
- def paint(template)
29
- @template = template
30
- draw
31
- end
32
-
33
- def refresh
34
- # No need to refresh if the screen dimensions have not changed
35
- return if @refreshed_width == width || @refreshed_height == height
36
- draw
37
- end
38
-
39
- def finalize
40
- output.print Utils::Ansi.clear
41
- output.print Utils::Ansi.cursor_pos(top: height - 1)
42
- output.print Utils::Ansi.cursor_visible(true)
43
- output.flush
44
- end
45
-
46
- protected
47
-
48
- def refresh_size!
49
- @width, @height = self.class.current_dimensions
50
- end
51
-
52
- private
53
-
54
- attr_reader :output, :cursor, :terminal, :width, :height
55
-
56
- def draw
57
- strokes = [Utils::Ansi.cursor_visible(false), Utils::Ansi.cursor_pos, Utils::Ansi.clear_down]
58
- Renderer.new(@template, width, height).paint do |left, top, fstring|
59
- next unless fstring.length > 0
60
- strokes << Utils::Ansi.cursor_pos(left: left, top: top)
61
- strokes << fstring
62
- end
63
- strokes.each { |stroke| output.print(stroke) }
64
- output.flush
65
- @refreshed_width = width
66
- @refreshed_height = height
67
- end
68
- end
69
- end
70
- end
@@ -1,15 +0,0 @@
1
- module WhirledPeas
2
- module Graphics
3
- class TextDimensions
4
- attr_reader :outer_width, :outer_height
5
-
6
- def initialize(content)
7
- @outer_width = 0
8
- content.each do |line|
9
- @outer_width = line.length if line.length > @outer_width
10
- end
11
- @outer_height = content.length
12
- end
13
- end
14
- end
15
- end