whirled_peas 0.9.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/README.md +65 -20
  4. data/lib/data/themes.yaml +13 -0
  5. data/lib/whirled_peas.rb +10 -2
  6. data/lib/whirled_peas/command/config_command.rb +1 -2
  7. data/lib/whirled_peas/command/play.rb +3 -0
  8. data/lib/whirled_peas/command/themes.rb +76 -0
  9. data/lib/whirled_peas/command_line.rb +3 -1
  10. data/lib/whirled_peas/graphics/composer.rb +5 -2
  11. data/lib/whirled_peas/settings/border.rb +25 -4
  12. data/lib/whirled_peas/settings/container_settings.rb +2 -2
  13. data/lib/whirled_peas/settings/element_settings.rb +8 -4
  14. data/lib/whirled_peas/settings/graph_settings.rb +1 -1
  15. data/lib/whirled_peas/settings/text_settings.rb +1 -0
  16. data/lib/whirled_peas/settings/theme.rb +40 -0
  17. data/lib/whirled_peas/settings/theme_library.rb +63 -0
  18. data/lib/whirled_peas/version.rb +1 -1
  19. data/screen_test/elements/box.frame +1 -1
  20. data/screen_test/elements/box.rb +1 -1
  21. data/screen_test/elements/graph.frame +1 -1
  22. data/screen_test/elements/graph.rb +1 -1
  23. data/screen_test/elements/grid.frame +1 -1
  24. data/screen_test/elements/grid.rb +1 -1
  25. data/screen_test/elements/screen_overflow_x.frame +1 -1
  26. data/screen_test/elements/screen_overflow_x.rb +1 -1
  27. data/screen_test/elements/screen_overflow_y.frame +1 -1
  28. data/screen_test/elements/screen_overflow_y.rb +1 -1
  29. data/screen_test/elements/text.frame +1 -1
  30. data/screen_test/elements/text.rb +1 -1
  31. data/screen_test/elements/text_multiline.frame +1 -1
  32. data/screen_test/elements/text_multiline.rb +1 -1
  33. data/screen_test/elements/theme.frame +1 -0
  34. data/screen_test/elements/theme.rb +26 -0
  35. data/screen_test/settings/align/box_around.frame +1 -1
  36. data/screen_test/settings/align/box_around.rb +1 -1
  37. data/screen_test/settings/align/box_between.frame +1 -1
  38. data/screen_test/settings/align/box_between.rb +1 -1
  39. data/screen_test/settings/align/box_center.frame +1 -1
  40. data/screen_test/settings/align/box_center.rb +1 -1
  41. data/screen_test/settings/align/box_default.frame +1 -1
  42. data/screen_test/settings/align/box_default.rb +1 -1
  43. data/screen_test/settings/align/box_evenly.frame +1 -1
  44. data/screen_test/settings/align/box_evenly.rb +1 -1
  45. data/screen_test/settings/align/box_left.frame +1 -1
  46. data/screen_test/settings/align/box_left.rb +1 -1
  47. data/screen_test/settings/align/box_right.frame +1 -1
  48. data/screen_test/settings/align/box_right.rb +1 -1
  49. data/screen_test/settings/align/children_center.frame +1 -1
  50. data/screen_test/settings/align/children_center.rb +1 -1
  51. data/screen_test/settings/align/children_left.frame +1 -1
  52. data/screen_test/settings/align/children_left.rb +1 -1
  53. data/screen_test/settings/align/children_right.frame +1 -1
  54. data/screen_test/settings/align/children_right.rb +1 -1
  55. data/screen_test/settings/align/grid_center.frame +1 -1
  56. data/screen_test/settings/align/grid_center.rb +1 -1
  57. data/screen_test/settings/align/grid_default.frame +1 -1
  58. data/screen_test/settings/align/grid_default.rb +1 -1
  59. data/screen_test/settings/align/grid_left.frame +1 -1
  60. data/screen_test/settings/align/grid_left.rb +1 -1
  61. data/screen_test/settings/align/grid_right.frame +1 -1
  62. data/screen_test/settings/align/grid_right.rb +1 -1
  63. data/screen_test/settings/ansi/bold.frame +1 -1
  64. data/screen_test/settings/ansi/bold.rb +1 -1
  65. data/screen_test/settings/ansi/color.frame +1 -1
  66. data/screen_test/settings/ansi/color.rb +1 -1
  67. data/screen_test/settings/ansi/underline.frame +1 -1
  68. data/screen_test/settings/ansi/underline.rb +1 -1
  69. data/screen_test/settings/border.frame +1 -1
  70. data/screen_test/settings/border.rb +1 -1
  71. data/screen_test/settings/flow/box_b2t.frame +1 -1
  72. data/screen_test/settings/flow/box_b2t.rb +1 -1
  73. data/screen_test/settings/flow/box_l2r.frame +1 -1
  74. data/screen_test/settings/flow/box_l2r.rb +1 -1
  75. data/screen_test/settings/flow/box_r2l.frame +1 -1
  76. data/screen_test/settings/flow/box_r2l.rb +1 -1
  77. data/screen_test/settings/flow/box_t2b.frame +1 -1
  78. data/screen_test/settings/flow/box_t2b.rb +1 -1
  79. data/screen_test/settings/flow/grid_b2t.frame +1 -1
  80. data/screen_test/settings/flow/grid_b2t.rb +1 -1
  81. data/screen_test/settings/flow/grid_l2r.frame +1 -1
  82. data/screen_test/settings/flow/grid_l2r.rb +1 -1
  83. data/screen_test/settings/flow/grid_r2l.frame +1 -1
  84. data/screen_test/settings/flow/grid_r2l.rb +1 -1
  85. data/screen_test/settings/flow/grid_t2b.frame +1 -1
  86. data/screen_test/settings/flow/grid_t2b.rb +1 -1
  87. data/screen_test/settings/height/box.frame +1 -1
  88. data/screen_test/settings/height/box.rb +1 -1
  89. data/screen_test/settings/height/box_border_sizing.frame +1 -1
  90. data/screen_test/settings/height/box_border_sizing.rb +1 -1
  91. data/screen_test/settings/height/grid.frame +1 -1
  92. data/screen_test/settings/height/grid.rb +1 -1
  93. data/screen_test/settings/height/overflow_box.frame +1 -1
  94. data/screen_test/settings/height/overflow_box.rb +1 -1
  95. data/screen_test/settings/height/overflow_box_l2r.frame +1 -1
  96. data/screen_test/settings/height/overflow_box_l2r.rb +1 -1
  97. data/screen_test/settings/height/overflow_box_t2b.frame +1 -1
  98. data/screen_test/settings/height/overflow_box_t2b.rb +1 -1
  99. data/screen_test/settings/height/overflow_grid.frame +1 -1
  100. data/screen_test/settings/height/overflow_grid.rb +1 -1
  101. data/screen_test/settings/margin.frame +1 -1
  102. data/screen_test/settings/margin.rb +1 -1
  103. data/screen_test/settings/padding.frame +1 -1
  104. data/screen_test/settings/padding.rb +1 -1
  105. data/screen_test/settings/position/box_left.frame +1 -1
  106. data/screen_test/settings/position/box_left.rb +1 -1
  107. data/screen_test/settings/position/box_left_negative.frame +1 -1
  108. data/screen_test/settings/position/box_left_negative.rb +1 -1
  109. data/screen_test/settings/position/box_top.frame +1 -1
  110. data/screen_test/settings/position/box_top.rb +1 -1
  111. data/screen_test/settings/position/box_top_negative.frame +1 -1
  112. data/screen_test/settings/position/box_top_negative.rb +1 -1
  113. data/screen_test/settings/position/grid_left.frame +1 -1
  114. data/screen_test/settings/position/grid_left.rb +1 -1
  115. data/screen_test/settings/position/grid_left_negative.frame +1 -1
  116. data/screen_test/settings/position/grid_left_negative.rb +1 -1
  117. data/screen_test/settings/position/grid_top.frame +1 -1
  118. data/screen_test/settings/position/grid_top.rb +1 -1
  119. data/screen_test/settings/position/grid_top_negative.frame +1 -1
  120. data/screen_test/settings/position/grid_top_negative.rb +1 -1
  121. data/screen_test/settings/scroll/horiz_box.frame +1 -1
  122. data/screen_test/settings/scroll/horiz_box.rb +1 -1
  123. data/screen_test/settings/scroll/horiz_box_align_center.rb +1 -1
  124. data/screen_test/settings/scroll/horiz_box_align_right.rb +1 -1
  125. data/screen_test/settings/scroll/vert_box.frame +1 -1
  126. data/screen_test/settings/scroll/vert_box.rb +1 -1
  127. data/screen_test/settings/title_font.frame +1 -1
  128. data/screen_test/settings/title_font.rb +1 -1
  129. data/screen_test/settings/valign/box_around.frame +1 -1
  130. data/screen_test/settings/valign/box_around.rb +1 -1
  131. data/screen_test/settings/valign/box_between.frame +1 -1
  132. data/screen_test/settings/valign/box_between.rb +1 -1
  133. data/screen_test/settings/valign/box_bottom.frame +1 -1
  134. data/screen_test/settings/valign/box_bottom.rb +1 -1
  135. data/screen_test/settings/valign/box_default.frame +1 -1
  136. data/screen_test/settings/valign/box_default.rb +1 -1
  137. data/screen_test/settings/valign/box_evenly.frame +1 -1
  138. data/screen_test/settings/valign/box_evenly.rb +1 -1
  139. data/screen_test/settings/valign/box_middle.frame +1 -1
  140. data/screen_test/settings/valign/box_middle.rb +1 -1
  141. data/screen_test/settings/valign/box_top.frame +1 -1
  142. data/screen_test/settings/valign/box_top.rb +1 -1
  143. data/screen_test/settings/valign/grid_bottom.frame +1 -1
  144. data/screen_test/settings/valign/grid_bottom.rb +1 -1
  145. data/screen_test/settings/valign/grid_default.frame +1 -1
  146. data/screen_test/settings/valign/grid_default.rb +1 -1
  147. data/screen_test/settings/valign/grid_middle.frame +1 -1
  148. data/screen_test/settings/valign/grid_middle.rb +1 -1
  149. data/screen_test/settings/valign/grid_top.frame +1 -1
  150. data/screen_test/settings/valign/grid_top.rb +1 -1
  151. data/screen_test/settings/width/box_border_sizing.frame +1 -1
  152. data/screen_test/settings/width/box_border_sizing.rb +1 -1
  153. data/screen_test/settings/width/box_content.frame +1 -1
  154. data/screen_test/settings/width/box_content.rb +1 -1
  155. data/screen_test/settings/width/box_default.frame +1 -1
  156. data/screen_test/settings/width/box_default.rb +1 -1
  157. data/screen_test/settings/width/grid.frame +1 -1
  158. data/screen_test/settings/width/grid.rb +1 -1
  159. data/screen_test/settings/width/overflow_align_center.frame +1 -1
  160. data/screen_test/settings/width/overflow_align_center.rb +1 -1
  161. data/screen_test/settings/width/overflow_align_right.frame +1 -1
  162. data/screen_test/settings/width/overflow_align_right.rb +1 -1
  163. data/screen_test/settings/width/overflow_box.frame +1 -1
  164. data/screen_test/settings/width/overflow_box.rb +1 -1
  165. data/screen_test/settings/width/overflow_box_l2r.frame +1 -1
  166. data/screen_test/settings/width/overflow_box_l2r.rb +1 -1
  167. data/screen_test/settings/width/overflow_box_t2b.frame +1 -1
  168. data/screen_test/settings/width/overflow_box_t2b.rb +1 -1
  169. data/screen_test/settings/width/overflow_grid.frame +1 -1
  170. data/screen_test/settings/width/overflow_grid.rb +1 -1
  171. data/tools/whirled_peas/tools/screen_tester.rb +15 -1
  172. metadata +8 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 424038cc2fb2f4b48edb6e43219f515eb5564f7e78871506d63ea1bbbc724ff9
4
- data.tar.gz: 6f35ac5a2d32f3a37a6876e0b2b7022d9c0f07a1f71eb1f3d628def4840926e7
3
+ metadata.gz: 7c1c4b2f603c535f98d7578741059e0d949ccff4e315fc88c36c13fc2fa58de5
4
+ data.tar.gz: a9c92f62d2dcb7c7c1983bf6e6e8fa66bb5a92abcec0ae689ca4efc342083625
5
5
  SHA512:
6
- metadata.gz: 4bf7a9b822e06e095fed812f5408358dd6562e604fa5da7c4e91a8cfcf9f96f081b9f33198767e0221563b2f2304a70e38e637c10830c16664440d46346cef6f
7
- data.tar.gz: 7f402bf1c932d58893df06874f314216b053fdf2019704a13e317d5b0512e20558b0019eafb5d5c7796975e45e6ddc01fc3a0fd70e1c9179485de60f527dc422
6
+ metadata.gz: 8e746107b95a5176d89792606a76935c84c3686452b2abf99c5383df676263684a096130c18cf07080fbc9ede4dc61b9ae220efe4fd8313e933c230e73d8b1b0
7
+ data.tar.gz: d5dca0db34f358072134a94ae8b5765abd60d45f18de7496dc0c410cd665c2e9ef91ef33989d00317caef1fd472c210e892af13d8a65bc3126ea37b201dc1b43
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.10.0 - 2021-01-29
4
+
5
+ - [3063a2b](https://github.com/tcollier/whirled_peas/tree/3063a2becb7680b5e320a1733b3da933e6c65210): Add built-in and user-defined themes
6
+
3
7
  ## v0.9.1 - 2021-01-29
4
8
 
5
9
  - [c35b134](https://github.com/tcollier/whirled_peas/tree/c35b134e1340b8b5f1d1fb0e6e56dc2a99b52e94): Improve graph plots
data/README.md CHANGED
@@ -85,7 +85,8 @@ $ whirled_peas play visualize.rb
85
85
  The application is code to be visualized that integrates with Whirled Peas by providing the signature below
86
86
 
87
87
  ```ruby
88
- # Start the application and pass frame events to the producer to be rendered by the UI
88
+ # Start the application and pass frame events to the producer to be rendered
89
+ # by the UI
89
90
  #
90
91
  # @param producer [Producer] frame producer that sends events to the UI
91
92
  def start(producer)
@@ -98,15 +99,27 @@ The producer provides the following methods
98
99
  ```ruby
99
100
  # Add a frame to be displayed
100
101
  #
101
- # @param name [String] application defined name for the frame. The template factory will be provided this name
102
- # @param duration [Number] time in seconds this frame should be displayed for (defaults to 1 frame)
103
- # @param args [Hash<Symbol, Object>] key value pairs to send as arguments to the template factory
102
+ # @param name [String] (required) application defined name for the frame. The
103
+ # template factory will be provided this name
104
+ # @param duration [Number] (optional) time in seconds this frame should be
105
+ # displayed for (defaults to 1 frame)
106
+ # @param args [Hash<Symbol, Object>] (optional) key/value pairs to send as
107
+ # arguments to the template factory
104
108
  def add_frame(name, duration:, args:)
105
109
  end
106
110
 
107
- # Create and yield a frameset instance that allows applications to add multiple frames to play over the
108
- # given duration. Adding frames to the yielded frameset will result in playback that is eased by the
109
- # gvien `easing` and `effect` arguments (default is `:linear` easing)
111
+ # Create and yield a frameset instance that allows applications to add multiple
112
+ # frames to play over the given duration. Adding frames to the yielded frameset
113
+ # will result in playback that is eased by the given `easing` and `effect`
114
+ # arguments (default is `:linear` easing)
115
+ #
116
+ # @param duration [Number] (required) total duration for which all frames in
117
+ # frameset will be displayed
118
+ # @param easing [Symbol] (optional) easing function to be used to transition
119
+ # through all frames (defaults to `:linear`)
120
+ # @param effect [Symbol] (optional) how to apply the easing function (defaults
121
+ # to `:in_out`, also available are `:in` and `:out`)
122
+ # @yield [Frameset] instance that provides `#add_frame(name, args:)`
110
123
  def frameset(duration, easing:, effect:, &block)
111
124
  end
112
125
  ```
@@ -114,11 +127,13 @@ end
114
127
  A frameset instance provides one method
115
128
 
116
129
  ```ruby
117
- # Add a frame to be displayed, the duration will be determine by the number of frames in the frameset along
118
- # with the duration and easing of the frameset
130
+ # Add a frame to be displayed, the duration will be determine by the number of
131
+ # frames in the frameset along with the duration and easing of the frameset
119
132
  #
120
- # @param name [String] application defined name for the frame. The template factory will be provided this name
121
- # @param args [Hash<Symbol, Object>] key value pairs to send as arguments to the template factory
133
+ # @param name [String] (required) application defined name for the frame. The
134
+ # template factory will be provided this name
135
+ # @param args [Hash<Symbol, Object>] (optional) key/value pairs to send as
136
+ # arguments to the template factory
122
137
  def add_frame(name, args:)
123
138
  end
124
139
  ```
@@ -232,29 +247,45 @@ end
232
247
 
233
248
  #### Settings
234
249
 
235
- Each element type has an associated settings type, which provide a custom set of options to format the output. Child settings will inherit from the parent, where applicable
236
- The available settigs are
250
+ Each element type has an associated settings type, which provide a custom set of options to format the output. Child settings will inherit from the parent, where applicable. The table below lists all settings along with which element types the settings can be applied to (`Grid` and `Box` are containers)
237
251
 
238
252
  | Setting | Description | Default | Availability | Inherited |
239
253
  | ------------ | -------------------------------------------------------------------------------- | ---------- | ------------ | -------------------- |
240
- | `align` | Justifies the content in the horizontal direction | `:left` | `Container` | No |
254
+ | `align` | Justifies the content in the horizontal direction | `:left` | containers | No |
241
255
  | `axis_color` | Color used to paint the axes of the graph (see [Colors](#colors)) | | `Graph` | No |
242
256
  | `bg_color` | Background color (see [Colors](#colors)) | | all | Yes |
243
257
  | `bold` | `true` makes the font bold | `false` | all | Yes |
244
- | `border` | Set the border for the lements | none | `Container`, | Only style and color |
258
+ | `border` | Set the border for the lements | none | containers, | Only style and color |
245
259
  | `color` | Foreground text color (see [Colors](#colors)) | | all | Yes |
246
- | `flow` | Flow to display child elements (see [Display Flow](#display-flow)) | `:l2r` | `Container` | No |
260
+ | `flow` | Flow to display child elements (see [Display Flow](#display-flow)) | `:l2r` | containers | No |
247
261
  | `height` | Override the calculated height of an element's content area | | all | No |
248
- | `margin` | Set the (left, top, right, bottom) margin of the element | `0` | `Container` | No |
262
+ | `margin` | Set the (left, top, right, bottom) margin of the element | `0` | containers | No |
249
263
  | `num_cols` | Number of columns in the grid (must be set!) | | `Grid` | No |
250
- | `padding` | Set the (left, top, right, bottom) padding of the element | `0` | `Container` | No |
251
- | `position` | Set the (left, top) position of the element relative to parent content area | `0` | `Container` | No |
264
+ | `padding` | Set the (left, top, right, bottom) padding of the element | `0` | containers | No |
265
+ | `position` | Set the (left, top) position of the element relative to parent content area | `0` | containers | No |
252
266
  | `scrollbar` | Display a scroll bar for vertical or horizontal scrolling | | `Box` | No |
253
267
  | `sizing` | Sizing model (`:content` or `:border`) used in conjunction with `width`/`height` | `:content` | `Box` | No |
254
268
  | `title_font` | Font used for "large" text (see [Large Text](#large-text), ignores `underline`) | | `Text` | No |
255
269
  | `underline` | `true` underlines the font | `false` | all | Yes |
256
270
  | `width` | Override the calculated width of an element's content area | | all | No |
257
- | `valign` | Justifies the content in the vertical direction | `:top` | `Container` | No |
271
+ | `valign` | Justifies the content in the vertical direction | `:top` | containers | No |
272
+
273
+ ##### Themes
274
+
275
+ The template builder (`WhirledPeas.template`) takes an optional `theme` argument. You can provide the name of a predefined theme (run `whirled_peas themes` to see a list with samples) or define you own with the following
276
+ You can define your own theme
277
+
278
+ ```ruby
279
+ WhirledPeas.define_theme(:my_theme) do |theme|
280
+ theme.bg_color = :bright_white
281
+ theme.color = :blue
282
+ theme.border_color = :bright_green
283
+ theme.axis_color = :bright_red
284
+ theme.title_font = :default
285
+ end
286
+ ```
287
+
288
+ Theme settings will be used as default settings throughout the template, however theme settings can be overridden on any element.
258
289
 
259
290
  ##### Alignment
260
291
 
@@ -1010,6 +1041,7 @@ Available commands:
1010
1041
  play Play an animation from an application or prerecorded file
1011
1042
  record Record animation to a file
1012
1043
  still Show the specified still frame
1044
+ themes List all themes with sample template rendered in the theme
1013
1045
  ```
1014
1046
 
1015
1047
  #### `debug`
@@ -1098,6 +1130,19 @@ Show the specified still frame
1098
1130
  # Still frame is displayed
1099
1131
  ```
1100
1132
 
1133
+ #### `themes`
1134
+
1135
+ List all themes and display a small sample screen in each. Running this with no extra command line arguments will display all the built-in themes. Adding the path to a Whirled Peas configuration file will inlcude any themes defined in that configuration.
1136
+
1137
+ ```
1138
+ # Usage: whirled_peas themes [config file]
1139
+ % whirled_peas themes
1140
+ # Display all system themes
1141
+
1142
+ % whirled_peas themes my_app.rb
1143
+ # Display app-defined themes and all system themes
1144
+ ```
1145
+
1101
1146
  ## Development
1102
1147
 
1103
1148
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -0,0 +1,13 @@
1
+ bright:
2
+ bg_color: :bright_white
3
+ color: :blue
4
+ border_color: :bright_blue
5
+ axis_color: :red
6
+ title_font: :default
7
+
8
+ dark:
9
+ bg_color: :black
10
+ color: :white
11
+ border_color: :gray
12
+ axis_color: :bright_white
13
+ title_font: :swan
@@ -15,8 +15,16 @@ module WhirledPeas
15
15
  yield config
16
16
  end
17
17
 
18
- def self.template(&block)
18
+ def self.template(theme_name=nil, &block)
19
19
  require 'whirled_peas/graphics/composer'
20
- Graphics::Composer.build(&block)
20
+ Graphics::Composer.build(theme_name, &block)
21
+ end
22
+
23
+ def self.define_theme(name, &block)
24
+ require 'whirled_peas/settings/theme'
25
+ require 'whirled_peas/settings/theme_library'
26
+ theme = Settings::Theme.new
27
+ yield theme
28
+ Settings::ThemeLibrary.add(name, theme)
21
29
  end
22
30
  end
@@ -8,9 +8,8 @@ module WhirledPeas
8
8
  class ConfigCommand < Base
9
9
  def start
10
10
  require config_file
11
- rescue => e
11
+ rescue LoadError
12
12
  puts "Error loading #{config_file}"
13
- puts e.message
14
13
  exit(1)
15
14
  end
16
15
 
@@ -38,6 +38,9 @@ module WhirledPeas
38
38
  config.application.start(producer)
39
39
  end
40
40
  end
41
+ rescue LoadError
42
+ puts "Error loading #{config_file}"
43
+ exit(1)
41
44
  end
42
45
 
43
46
  private
@@ -0,0 +1,76 @@
1
+ require 'whirled_peas/device/screen'
2
+ require 'whirled_peas/graphics/renderer'
3
+ require 'whirled_peas/settings/theme_library'
4
+
5
+ require_relative 'base'
6
+
7
+ module WhirledPeas
8
+ module Command
9
+ # Display a still frame with the specified arguments.
10
+ class Themes < Base
11
+ def self.description
12
+ 'List all themes with sample template rendered in the theme'
13
+ end
14
+
15
+ def start
16
+ super
17
+
18
+ require config_file unless config_file.nil?
19
+
20
+ theme_names = Settings::ThemeLibrary.theme_names
21
+ theme_names.each.with_index do |name, index|
22
+ template = WhirledPeas.template(name) do |composer, settings|
23
+ settings.full_border
24
+ settings.flow = :t2b
25
+ composer.add_text do |_, settings|
26
+ settings.title_font = :theme
27
+ name
28
+ end
29
+ composer.add_text do
30
+ name == Settings::ThemeLibrary.default_name ? ' (default)' : ''
31
+ end
32
+ composer.add_graph do |_, settings|
33
+ settings.height = 12
34
+ 20.times.map { |i| Math.sqrt(i) }
35
+ end
36
+ end
37
+ Utils::Ansi.with_screen do |width, height|
38
+ rendered = Graphics::Renderer.new(
39
+ template,
40
+ 80,
41
+ 30
42
+ ).paint
43
+ Device::Screen.new(10000).handle_renders([rendered])
44
+ end
45
+
46
+ if index < theme_names.length - 1
47
+ print 'See next theme? [Y/q] '
48
+ STDOUT.flush
49
+ break if gets.chomp == 'q'
50
+ end
51
+ end
52
+ rescue LoadError
53
+ puts "Error loading #{config_file}"
54
+ exit(1)
55
+ end
56
+
57
+ private
58
+
59
+ attr_reader :config_file
60
+
61
+ def validate!
62
+ super
63
+ config_file = args.shift
64
+ @error_text = 'hi'
65
+ unless config_file.nil?
66
+ # We think we have a valid ruby config file, set the absolute path to @config
67
+ @config_file = config_file[0] == '/' ? config_file : File.join(Dir.pwd, config_file)
68
+ end
69
+ end
70
+
71
+ def options_usage
72
+ '[config file]'
73
+ end
74
+ end
75
+ end
76
+ end
@@ -5,6 +5,7 @@ require 'whirled_peas/command/help'
5
5
  require 'whirled_peas/command/play'
6
6
  require 'whirled_peas/command/record'
7
7
  require 'whirled_peas/command/still'
8
+ require 'whirled_peas/command/themes'
8
9
 
9
10
  module WhirledPeas
10
11
  class CommandLine
@@ -15,7 +16,8 @@ module WhirledPeas
15
16
  Command::Help,
16
17
  Command::Play,
17
18
  Command::Record,
18
- Command::Still
19
+ Command::Still,
20
+ Command::Themes
19
21
  ].map.with_object({}) { |c, h| h[c.command_name] = c }
20
22
 
21
23
  def initialize(args)
@@ -2,6 +2,7 @@ require 'whirled_peas/settings/box_settings'
2
2
  require 'whirled_peas/settings/graph_settings'
3
3
  require 'whirled_peas/settings/grid_settings'
4
4
  require 'whirled_peas/settings/text_settings'
5
+ require 'whirled_peas/settings/theme_library'
5
6
 
6
7
  require_relative 'box_painter'
7
8
  require_relative 'graph_painter'
@@ -25,8 +26,10 @@ module WhirledPeas
25
26
  "Element-#{@counter}"
26
27
  end
27
28
 
28
- def self.build
29
- settings = Settings::BoxSettings.new
29
+ def self.build(theme_name=nil, &block)
30
+ theme_name ||= Settings::ThemeLibrary.default_name
31
+ theme = Settings::ThemeLibrary.get(theme_name)
32
+ settings = Settings::BoxSettings.new(theme)
30
33
  template = BoxPainter.new('TEMPLATE', settings)
31
34
  composer = Composer.new(template)
32
35
  value = yield composer, settings
@@ -51,8 +51,20 @@ module WhirledPeas
51
51
  end
52
52
  end
53
53
 
54
+ def self.inherit(parent)
55
+ border = new(parent.theme)
56
+ border.inherit(parent)
57
+ border
58
+ end
59
+
60
+ attr_reader :theme
61
+
54
62
  attr_writer :left, :top, :right, :bottom, :inner_horiz, :inner_vert
55
63
 
64
+ def initialize(theme)
65
+ @theme = theme
66
+ end
67
+
56
68
  def left?
57
69
  @left == true
58
70
  end
@@ -82,20 +94,29 @@ module WhirledPeas
82
94
  end
83
95
 
84
96
  def style
85
- @style || Styles::DEFAULT
97
+ @_style || Styles::DEFAULT
86
98
  end
87
99
 
88
100
  def style=(val)
89
- @style = Styles.validate!(val)
101
+ @_style = Styles.validate!(val)
90
102
  end
91
103
 
92
104
  def color=(val)
93
- @color = TextColor.validate!(val)
105
+ @_color = TextColor.validate!(val)
94
106
  end
95
107
 
96
108
  def color
97
- @color || TextColor::DEFAULT
109
+ @_color || theme.border_color
98
110
  end
111
+
112
+ def inherit(parent)
113
+ @_style = parent._style
114
+ @_color = parent._color
115
+ end
116
+
117
+ protected
118
+
119
+ attr_reader :_style, :_color
99
120
  end
100
121
  end
101
122
  end
@@ -96,7 +96,7 @@ module WhirledPeas
96
96
  end
97
97
 
98
98
  def border
99
- @_border ||= Border.new
99
+ @_border ||= Border.new(theme)
100
100
  end
101
101
 
102
102
  def flow=(flow)
@@ -212,7 +212,7 @@ module WhirledPeas
212
212
  def inherit(parent)
213
213
  super
214
214
  return unless parent.is_a?(ContainerSettings)
215
- set_border(color: parent.border.color, style: parent.border.style)
215
+ @_border = Border.inherit(parent.border)
216
216
  end
217
217
 
218
218
  protected
@@ -8,18 +8,22 @@ module WhirledPeas
8
8
  module Settings
9
9
  class ElementSettings
10
10
  def self.inherit(parent)
11
- child = self.new
11
+ child = self.new(parent.theme)
12
12
  child.inherit(parent)
13
13
  child
14
14
  end
15
15
 
16
- attr_accessor :width, :height
16
+ attr_accessor :theme, :width, :height
17
+
18
+ def initialize(theme)
19
+ @theme = theme
20
+ end
17
21
 
18
22
  def validate!
19
23
  end
20
24
 
21
25
  def bg_color
22
- @_bg_color || BgColor::DEFAULT
26
+ @_bg_color || theme.bg_color
23
27
  end
24
28
 
25
29
  def bg_color=(color)
@@ -35,7 +39,7 @@ module WhirledPeas
35
39
  end
36
40
 
37
41
  def color
38
- @_color || TextColor::DEFAULT
42
+ @_color || theme.color
39
43
  end
40
44
 
41
45
  def color=(color)