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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a2a839ef0ed84dd94f346be47c38d65c0d23b6faa399abdf8f56023138788a4
|
4
|
+
data.tar.gz: 04a43d7c60d2e3896adea98036012bdba20448ecdf530947b72ca535ee5c3464
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfff87fa6a87ed784b35b400ad9ac737508b4ded1e791840a3a3194a0ef22eae1ad517c9f8db9459b929e37ce132cfa97662f85762b0b02df691f58ececa7d19
|
7
|
+
data.tar.gz: 504e279d386d56d3b476220c4f8a015134c446b7a0cdcebc5c65db50ee750f48ce2b8b5e6a72ce0d3844bdca916f832230b7974dfdd5d982140b8bc15db003c6
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
## v0.5.0 - 2021-01-25
|
4
4
|
|
5
|
+
- [73df2af](https://github.com/tcollier/whirled_peas/tree/73df2af1f1eac37fe94f720dce16da1ed568dade): Add support for scroll bars along both axes
|
6
|
+
- [f4f44e1](https://github.com/tcollier/whirled_peas/tree/f4f44e1ff6c75ed03cd682e3fa9921401dcd2d00): Implement remaining 3 flow directions for grids
|
7
|
+
- [c01d083](https://github.com/tcollier/whirled_peas/tree/c01d083e10bf70983109a8def836bb181099f59c): Implement reverse flow directions for grids
|
8
|
+
|
9
|
+
## v0.5.0 - 2021-01-25
|
10
|
+
|
5
11
|
BREAKING: there was a significant amount of structural refactoring in this release. While that aspect did not add or remove any features, it fixed several layout bugs (some known and some unknown), so most template with moderate complexity will now be laid out slightly differently.
|
6
12
|
|
7
13
|
- [3ddfede](https://github.com/tcollier/whirled_peas/tree/3ddfedee4ab2fadeecbe82c7c9caf25c2988f095): Allow relative positioning of containers
|
data/README.md
CHANGED
@@ -1,8 +1,24 @@
|
|
1
1
|
[![Build Status](https://travis-ci.com/tcollier/whirled_peas.svg?branch=main)](https://travis-ci.com/tcollier/whirled_peas)
|
2
2
|
|
3
|
-
|
3
|
+
```
|
4
|
+
██╗ ██╗██╗███████╗██╗ ██╗ █████╗ ██╗ ██╗███████╗███████╗
|
5
|
+
██║ ██║██║██╔════╝██║ ██║██╔══██╗██║ ██║╚══███╔╝██╔════╝
|
6
|
+
██║ ██║██║███████╗██║ ██║███████║██║ ██║ ███╔╝ █████╗
|
7
|
+
╚██╗ ██╔╝██║╚════██║██║ ██║██╔══██║██║ ██║ ███╔╝ ██╔══╝
|
8
|
+
╚████╔╝ ██║███████║╚██████╔╝██║ ██║███████╗██║███████╗███████╗
|
9
|
+
╚═══╝ ╚═╝╚══════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝╚══════╝╚══════╝
|
10
|
+
|
11
|
+
your code's execution with
|
12
|
+
|
13
|
+
██╗ ██╗██╗ ██╗██╗██████╗ ██╗ ███████╗██████╗ ██████╗ ███████╗ █████╗ ███████╗
|
14
|
+
██║ ██║██║ ██║██║██╔══██╗██║ ██╔════╝██╔══██╗ ██╔══██╗██╔════╝██╔══██╗██╔════╝
|
15
|
+
██║ █╗ ██║███████║██║██████╔╝██║ █████╗ ██║ ██║ ██████╔╝█████╗ ███████║███████╗
|
16
|
+
██║███╗██║██╔══██║██║██╔══██╗██║ ██╔══╝ ██║ ██║ ██╔═══╝ ██╔══╝ ██╔══██║╚════██║
|
17
|
+
╚███╔███╔╝██║ ██║██║██║ ██║███████╗███████╗██████╔╝ ██║ ███████╗██║ ██║███████║
|
18
|
+
╚══╝╚══╝ ╚═╝ ╚═╝╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝╚══════╝
|
19
|
+
```
|
4
20
|
|
5
|
-
|
21
|
+
Easily create terminal-based graphics to visual the execution of your code. Whirled Peas offers templating inspired by HTML and CSS and provides a lightweight tie-in for your code to produce visual animations with these templates.
|
6
22
|
|
7
23
|
## Installation
|
8
24
|
|
@@ -156,12 +172,12 @@ To render the frame events sent by the driver, the application requires a templa
|
|
156
172
|
|
157
173
|
#### Building Blocks
|
158
174
|
|
159
|
-
A template is created with `WhirledPeas.template`, which yields a `Composer` object for a `
|
175
|
+
A template is created with `WhirledPeas.template`, which yields a `Composer` object for a `Box` and `BoxSettings`. The composer allows for attaching child elements and the settings for setting layout options.
|
160
176
|
|
161
177
|
A `Composer` provides the following methods to add child elements, each of these takes an optional string argument that is set as the name of the element (which can be useful when debugging).
|
162
178
|
|
163
|
-
- `add_box` - yields a `Composer` and a `BoxSettings`, which will be added to the parent's children
|
164
|
-
- `add_grid` - yields a `Composer` and a `GridSettings`, which will be added to the parent's children
|
179
|
+
- `add_box` - yields a `Composer` for a `Box` and a `BoxSettings`, which will be added to the parent's children
|
180
|
+
- `add_grid` - yields a `Composer` for a `Grid` and a `GridSettings`, which will be added to the parent's children
|
165
181
|
- `add_text` - yields `nil` and a `TextSettings`, which will be added to the parent's children
|
166
182
|
|
167
183
|
E.g.
|
@@ -192,7 +208,7 @@ WhirledPeas.template do |composer, settings|
|
|
192
208
|
end
|
193
209
|
```
|
194
210
|
|
195
|
-
Additionally, if no child element is explicitly added to a `
|
211
|
+
Additionally, if no child element is explicitly added to a `Grid`, but the block returns an array of strings or numbers, those will be converted to `Text` elements and added as children to the `Grid`. For example, these are identical ways to create a grid of strings
|
196
212
|
|
197
213
|
```ruby
|
198
214
|
template.add_grid do |composer|
|
@@ -206,7 +222,7 @@ template.add_grid do
|
|
206
222
|
end
|
207
223
|
```
|
208
224
|
|
209
|
-
Similarly, if no child element is explicilty added to a `
|
225
|
+
Similarly, if no child element is explicilty added to a `Box`, but the block returns a string or number, that value will be converted to a `Text` and added as a child. For example, these are identical ways to create a box with string content
|
210
226
|
|
211
227
|
```ruby
|
212
228
|
template.add_box do |composer|
|
@@ -236,6 +252,7 @@ The available settigs are
|
|
236
252
|
| `num_cols` | Number of columns in the grid (must be set!) | | `Grid` | No |
|
237
253
|
| `padding` | Set the (left, top, right, bottom) padding of the element | `0` | `Box`, `Grid` | No |
|
238
254
|
| `position` | Set the (left, top) position of the element relative to parent content area | `0` | `Box`, `Grid` | No |
|
255
|
+
| `scrollbar` | Display a scroll bar for vertical or horizontal scrolling | | `Box` | No |
|
239
256
|
| `title_font` | Font used for "large" text (see [Large Text](#large-text), ignores `underline`) | | `Text` | No |
|
240
257
|
| `underline` | `true` underlines the font | `false` | `Box`, `Grid`, `Text` | Yes |
|
241
258
|
| `width` | Override the calculated width of an element's content area | | `Box`, `Grid` | No |
|
@@ -262,6 +279,12 @@ Padding settings dictate the spacing on the inside (i.e. inside of the border) o
|
|
262
279
|
|
263
280
|
Note: values cannot be negative
|
264
281
|
|
282
|
+
##### Scrollbar
|
283
|
+
|
284
|
+
Scroll settings dictate whether the scrollbar will be shown when child content is larger the the container's viewport. A scrollbar adds a unit to the dimensions of a container (as opposed to overwriting the leftmost/bottommost padding)
|
285
|
+
|
286
|
+
- `set_padding(horiz:, vert:)`
|
287
|
+
|
265
288
|
##### Border
|
266
289
|
|
267
290
|
The border settings consist of 6 boolean values (border are either width 1 or not shown), the 4 obvious values (`left`, `top`, `right`, and `bottom`) along with 2 other values for inner borders (`inner_horiz` and `inner_vert`) in a grid. A border also has a foreground color (defaults to `:white`) and a style. The background color is determined by the `bg_color` of the element. Border values can be set with
|
@@ -308,31 +331,53 @@ Child elements can flow in one of 4 directions
|
|
308
331
|
- `:l2r` left-to-right
|
309
332
|
|
310
333
|
```
|
334
|
+
# In a Box
|
311
335
|
[child 1] [child 2] ... [child N]
|
336
|
+
|
337
|
+
# In a Grid
|
338
|
+
[child 1] [child 2] [child 3]
|
339
|
+
[chiid 4] [child 5]
|
312
340
|
```
|
313
341
|
|
314
342
|
- `:r2l` right-to-left
|
315
343
|
|
316
344
|
```
|
345
|
+
# In a Box
|
317
346
|
[child N] [child N - 1] ... [child 1]
|
347
|
+
|
348
|
+
# In a Grid
|
349
|
+
[child 3] [child 2] [child 1]
|
350
|
+
[chiid 5] [child 4]
|
318
351
|
```
|
319
352
|
|
320
353
|
- `:t2b` top-to-bottom
|
321
354
|
|
322
355
|
```
|
356
|
+
# In a Box
|
323
357
|
[child 1]
|
324
358
|
[child 2]
|
325
359
|
...
|
326
360
|
[child N]
|
361
|
+
|
362
|
+
# In a Grid
|
363
|
+
[child 1] [child 4]
|
364
|
+
[child 2] [child 5]
|
365
|
+
[child 3]
|
327
366
|
```
|
328
367
|
|
329
368
|
- `:b2t` bottom-to-top
|
330
369
|
|
331
370
|
```
|
371
|
+
# In a Box
|
332
372
|
[child N]
|
333
373
|
[child N - 1]
|
334
374
|
...
|
335
375
|
[child 1]
|
376
|
+
|
377
|
+
# In a Grid
|
378
|
+
[child 3]
|
379
|
+
[child 2] [child 5]
|
380
|
+
[child 1] [child 4]
|
336
381
|
```
|
337
382
|
|
338
383
|
##### Colors
|
@@ -360,7 +405,7 @@ Many of these also have a "bright" option:
|
|
360
405
|
|
361
406
|
##### Large Text
|
362
407
|
|
363
|
-
The `title_font` setting for `
|
408
|
+
The `title_font` setting for `Text`s converts the standard terminal font into a large block font. The available fonts vary from system to system. Every system will have a `:default` font available, this font could look like
|
364
409
|
|
365
410
|
```
|
366
411
|
██████╗ ███████╗███████╗ █████╗ ██╗ ██╗██╗ ████████╗
|
@@ -455,30 +500,17 @@ Adding the `--template` flag will result in printing out debug information for t
|
|
455
500
|
|
456
501
|
```
|
457
502
|
$ whirled_peas <config file> play_frame move '{"direction":"N"}' --template
|
458
|
-
+ TEMPLATE [WhirledPeas::Template::BoxElement]
|
459
|
-
- Settings
|
460
|
-
WhirledPeas::Settings::BoxSettings
|
461
|
-
<default>
|
462
|
-
- Children
|
463
|
-
+ TitleContainer [WhirledPeas::Template::BoxElement]
|
464
|
-
...
|
465
|
-
```
|
466
|
-
|
467
|
-
Adding the `--painter` flag will result in printing out debug information the painter (the rendered template), e.g.
|
468
|
-
|
469
|
-
```
|
470
|
-
$ whirled_peas <config file> play_frame move '{"direction":"N"}' --painter
|
471
503
|
+ TEMPLATE [WhirledPeas::Graphics::BoxPainter]
|
472
504
|
- Settings
|
473
505
|
WhirledPeas::Settings::BoxSettings
|
474
506
|
<default>
|
475
|
-
- Dimensions
|
476
|
-
- Canvas:
|
477
507
|
- Children
|
478
508
|
+ TitleContainer [WhirledPeas::Graphics::BoxPainter]
|
479
509
|
...
|
480
510
|
```
|
481
511
|
|
512
|
+
Note: the `list_frames` command will print out frame names and arguments formatted for this command
|
513
|
+
|
482
514
|
#### loading
|
483
515
|
|
484
516
|
Displays the configured loading screen for several seconds
|
@@ -487,16 +519,16 @@ Displays the configured loading screen for several seconds
|
|
487
519
|
$ whirled_peas <config file> loading
|
488
520
|
```
|
489
521
|
|
490
|
-
Adding the `--
|
522
|
+
Adding the `--template` flag will result in just printing out the loading template's debug information, e.g.
|
491
523
|
|
492
524
|
```
|
493
|
-
$ whirled_peas <config file> loading --
|
494
|
-
+ TEMPLATE [WhirledPeas::
|
525
|
+
$ whirled_peas <config file> loading --template
|
526
|
+
+ TEMPLATE [WhirledPeas::Graphics::BoxPainter]
|
495
527
|
- Settings
|
496
|
-
WhirledPeas::
|
528
|
+
WhirledPeas::Settings::BoxSettings
|
497
529
|
<default>
|
498
530
|
- Children
|
499
|
-
+ TitleContainer [WhirledPeas::
|
531
|
+
+ TitleContainer [WhirledPeas::Graphics::BoxPainter]
|
500
532
|
...
|
501
533
|
```
|
502
534
|
|
@@ -515,7 +547,8 @@ Note: viewing `.frame` files with `cat` works better than most other text editor
|
|
515
547
|
The following rake tasks are provided to interact with the screen tests
|
516
548
|
|
517
549
|
- `screen_test` runs all screen tests in the `screen_test/rendered` directory
|
518
|
-
- `screen_test:debug[path/to/file.rb]`
|
550
|
+
- `screen_test:debug[path/to/file.rb]` render the screen without printing it, this allows for debug print statments in the code to appear in the terminal
|
551
|
+
- `screen_test:template[path/to/file.rb]` print the rendered template debug tree
|
519
552
|
- `screen_test:run[path/to/file.rb]` runs a single screen test
|
520
553
|
- `screen_test:save[path/to/file.rb]` saves the output generated by the template in the `.frame` file, overwriting any existing file
|
521
554
|
- `screen_test:view[path/to/file.rb]` views the output generated by the template
|
data/Rakefile
CHANGED
@@ -14,7 +14,7 @@ def screen_test(file, method)
|
|
14
14
|
end
|
15
15
|
|
16
16
|
namespace :screen_test do
|
17
|
-
%i[
|
17
|
+
%i[template view run save debug].each do |t|
|
18
18
|
task t, [:file] do |_, args|
|
19
19
|
screen_test(args[:file], t)
|
20
20
|
end
|
@@ -37,4 +37,5 @@ task :screen_test do
|
|
37
37
|
WhirledPeas::ScreenTester.run_all
|
38
38
|
end
|
39
39
|
|
40
|
-
task default:
|
40
|
+
task default: :ci
|
41
|
+
task ci: [:screen_test, :spec]
|
data/examples/intro.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'whirled_peas'
|
3
|
+
|
4
|
+
class TemplateFactory
|
5
|
+
TITLE_FONT = :default #roman
|
6
|
+
PRIMARY_COLOR = :bright_blue
|
7
|
+
SECONDARY_COLOR = :blue
|
8
|
+
BG_COLOR = :bright_white
|
9
|
+
|
10
|
+
def build(name, args)
|
11
|
+
WhirledPeas.template do |composer, settings|
|
12
|
+
settings.set_padding(left: 10, top: 6, right: 10, bottom: 6)
|
13
|
+
settings.align = :center
|
14
|
+
settings.width = 120
|
15
|
+
settings.flow = :t2b
|
16
|
+
settings.bold = true
|
17
|
+
settings.bg_color = BG_COLOR
|
18
|
+
|
19
|
+
composer.add_box do |composer, settings|
|
20
|
+
composer.add_text do |_, settings|
|
21
|
+
settings.title_font = TITLE_FONT
|
22
|
+
settings.color = PRIMARY_COLOR
|
23
|
+
'Visualize'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
composer.add_box do |_, settings|
|
27
|
+
settings.set_margin(top: 1)
|
28
|
+
settings.color = SECONDARY_COLOR
|
29
|
+
"your code's execution with"
|
30
|
+
end
|
31
|
+
composer.add_box do |composer, settings|
|
32
|
+
settings.set_margin(top: 1)
|
33
|
+
composer.add_text do |_, settings|
|
34
|
+
settings.title_font = TITLE_FONT
|
35
|
+
settings.color = PRIMARY_COLOR
|
36
|
+
'Whirled Peas'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class Driver
|
44
|
+
def start(producer)
|
45
|
+
producer.send_frame('intro', duration: 5)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
WhirledPeas.configure do |config|
|
50
|
+
config.template_factory = TemplateFactory.new
|
51
|
+
config.driver = Driver.new
|
52
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'whirled_peas'
|
3
|
+
|
4
|
+
class TemplateFactory
|
5
|
+
HPADDING = 0
|
6
|
+
VPADDING = 0
|
7
|
+
ITEM_COUNT = 64
|
8
|
+
|
9
|
+
def build(name, args)
|
10
|
+
top = args[:top]
|
11
|
+
WhirledPeas.template do |composer, settings|
|
12
|
+
settings.color = :green
|
13
|
+
composer.add_box('Vert') do |composer, settings|
|
14
|
+
settings.bg_color = :bright_red
|
15
|
+
settings.full_border(color: :blue)
|
16
|
+
settings.set_scrollbar(vert: true)
|
17
|
+
settings.height = 12
|
18
|
+
composer.add_box('Inner') do |composer, settings|
|
19
|
+
settings.flow = :t2b
|
20
|
+
settings.set_padding(left: HPADDING, right: HPADDING, top: VPADDING, bottom: VPADDING)
|
21
|
+
settings.set_position(top: top)
|
22
|
+
ITEM_COUNT.times do |i|
|
23
|
+
composer.add_text { "%2d" % i }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
composer.add_box('Horiz') do |composer, settings|
|
28
|
+
settings.bg_color = :bright_red
|
29
|
+
settings.full_border(color: :blue)
|
30
|
+
settings.set_padding(left: HPADDING, right: HPADDING, top: VPADDING, bottom: VPADDING)
|
31
|
+
settings.set_scrollbar(horiz: true)
|
32
|
+
settings.width = 12
|
33
|
+
composer.add_box('Inner') do |composer, settings|
|
34
|
+
settings.set_position(left: top)
|
35
|
+
ITEM_COUNT.times.map { |i| (i % 10).to_s }.join
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class Driver
|
43
|
+
def start(producer)
|
44
|
+
53.times do |i|
|
45
|
+
producer.send_frame('intro', duration: 0.3, args: { top: -i })
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
WhirledPeas.configure do |config|
|
51
|
+
config.template_factory = TemplateFactory.new
|
52
|
+
config.driver = Driver.new
|
53
|
+
end
|
data/lib/whirled_peas.rb
CHANGED
@@ -2,11 +2,9 @@ require 'logger'
|
|
2
2
|
|
3
3
|
require 'whirled_peas/errors'
|
4
4
|
require 'whirled_peas/config'
|
5
|
-
require 'whirled_peas/debugger'
|
6
5
|
require 'whirled_peas/frame'
|
7
6
|
require 'whirled_peas/graphics'
|
8
7
|
require 'whirled_peas/settings'
|
9
|
-
require 'whirled_peas/template'
|
10
8
|
require 'whirled_peas/utils'
|
11
9
|
require 'whirled_peas/version'
|
12
10
|
|
@@ -19,12 +17,8 @@ module WhirledPeas
|
|
19
17
|
yield config
|
20
18
|
end
|
21
19
|
|
22
|
-
def self.debug(config_file, option=nil)
|
23
|
-
Debugger.new(config_file, option).debug
|
24
|
-
end
|
25
|
-
|
26
20
|
def self.template(&block)
|
27
|
-
require 'whirled_peas/
|
28
|
-
|
21
|
+
require 'whirled_peas/graphics/composer'
|
22
|
+
Graphics::Composer.build(&block)
|
29
23
|
end
|
30
24
|
end
|
@@ -6,7 +6,6 @@ require 'whirled_peas/graphics/screen'
|
|
6
6
|
require 'whirled_peas/frame/debug_consumer'
|
7
7
|
require 'whirled_peas/frame/event_loop'
|
8
8
|
require 'whirled_peas/frame/producer'
|
9
|
-
require 'whirled_peas/template/debugger'
|
10
9
|
|
11
10
|
module WhirledPeas
|
12
11
|
class Command
|
@@ -138,24 +137,17 @@ module WhirledPeas
|
|
138
137
|
super
|
139
138
|
|
140
139
|
if args.last == '--template'
|
141
|
-
|
142
|
-
puts
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
consumer = Frame::EventLoop.new(
|
154
|
-
WhirledPeas.config.template_factory,
|
155
|
-
logger: logger
|
156
|
-
)
|
157
|
-
Frame::Producer.produce(consumer, logger) do |producer|
|
158
|
-
producer.send_frame(frame, args: frame_args)
|
140
|
+
template = WhirledPeas.config.template_factory.build(frame, frame_args)
|
141
|
+
puts Graphics::Debugger.new(template).debug
|
142
|
+
else
|
143
|
+
logger = self.class.build_logger(File.open('whirled_peas.log', 'a'))
|
144
|
+
consumer = Frame::EventLoop.new(
|
145
|
+
WhirledPeas.config.template_factory,
|
146
|
+
logger: logger
|
147
|
+
)
|
148
|
+
Frame::Producer.produce(consumer, logger) do |producer|
|
149
|
+
producer.send_frame(frame, args: frame_args)
|
150
|
+
end
|
159
151
|
end
|
160
152
|
end
|
161
153
|
|
@@ -180,7 +172,7 @@ module WhirledPeas
|
|
180
172
|
end
|
181
173
|
|
182
174
|
def print_usage
|
183
|
-
puts "Usage: #{$0} #{self.class.command_name} <config file> <frame> [args as a JSON string] [--
|
175
|
+
puts "Usage: #{$0} #{self.class.command_name} <config file> <frame> [args as a JSON string] [--template]"
|
184
176
|
end
|
185
177
|
end
|
186
178
|
|
@@ -189,27 +181,27 @@ module WhirledPeas
|
|
189
181
|
super
|
190
182
|
unless WhirledPeas.config.loading_template_factory
|
191
183
|
puts 'No loading screen configured'
|
192
|
-
exit
|
184
|
+
exit(1)
|
193
185
|
end
|
194
186
|
|
195
|
-
if args.last == '--
|
196
|
-
|
197
|
-
|
187
|
+
if args.last == '--template'
|
188
|
+
template = WhirledPeas.config.loading_template_factory.build
|
189
|
+
puts Graphics::Debugger.new(template).debug
|
190
|
+
else
|
191
|
+
logger = self.class.build_logger(File.open('whirled_peas.log', 'a'))
|
192
|
+
consumer = Frame::EventLoop.new(
|
193
|
+
WhirledPeas.config.template_factory,
|
194
|
+
WhirledPeas.config.loading_template_factory,
|
195
|
+
logger: logger
|
196
|
+
)
|
197
|
+
Frame::Producer.produce(consumer, logger) { sleep(5) }
|
198
198
|
end
|
199
|
-
|
200
|
-
logger = self.class.build_logger(File.open('whirled_peas.log', 'a'))
|
201
|
-
consumer = Frame::EventLoop.new(
|
202
|
-
WhirledPeas.config.template_factory,
|
203
|
-
WhirledPeas.config.loading_template_factory,
|
204
|
-
logger: logger
|
205
|
-
)
|
206
|
-
Frame::Producer.produce(consumer, logger) { sleep(5) }
|
207
199
|
end
|
208
200
|
|
209
201
|
private
|
210
202
|
|
211
203
|
def print_usage
|
212
|
-
puts "Usage: #{$0} #{self.class.command_name} [--
|
204
|
+
puts "Usage: #{$0} #{self.class.command_name} [--template]"
|
213
205
|
end
|
214
206
|
end
|
215
207
|
|