whirled_peas 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +3 -3
- data/doc/components.md +1 -1
- data/doc/screen_test.md +1 -2
- data/doc/settings.md +11 -11
- data/lib/data/themes.yaml +0 -2
- data/lib/whirled_peas/animator/renderer_consumer.rb +5 -2
- data/lib/whirled_peas/component/list_with_active.rb +8 -7
- data/lib/whirled_peas/device/screen.rb +2 -7
- data/lib/whirled_peas/graphics/pixel_grid.rb +37 -0
- data/lib/whirled_peas/graphics/renderer.rb +1 -1
- data/lib/whirled_peas/settings/border.rb +2 -2
- data/lib/whirled_peas/version.rb +1 -1
- data/screen_test/elements/theme.rb +1 -0
- data/tools/whirled_peas/tools/screen_tester.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8aa42eec508df7b2634b3df5d1e3ac0b568db7051400bc4939f0516c7b34545e
|
4
|
+
data.tar.gz: 858ce91653f22b6e01771fb7397d5899caa116b42af7f8331da4bba85cf6cd74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d646e3833f854b03a200ffb5af37bf19907b0d8dc95a99700e29149ad4e0cf92e53fa911b8eae5749cc931401c1d7323333c1dd2d6e310c5cd3c17154ba1b99d
|
7
|
+
data.tar.gz: 63da3f42f0f83d5158ccd1f4af211791cbb5e6c1cddb438413962edc0cd9703ccd24d816ca08d217ccc8fc94bb4104715066380ee12eb0ad97ca14cf58fdd379
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v0.13.0- 2021-02-03
|
4
|
+
|
5
|
+
- [c4feba9](https://github.com/tcollier/whirled_peas/tree/c4feba92c34cf39e6e12650bae701744dd5999d2): Only paint the diff
|
6
|
+
- [fa871e5](https://github.com/tcollier/whirled_peas/tree/fa871e5e9a40feb33d68e8d213b8613e0dcdaa09): Don't require `active_index` for `ListWithActive`
|
7
|
+
- [0417b66](https://github.com/tcollier/whirled_peas/tree/0417b66c4a143c7c0ca439699519853f07eb6ac3): Use :soft border as default and for built-in themes
|
8
|
+
|
3
9
|
## v0.12.0- 2021-01-31
|
4
10
|
|
5
11
|
- [f218ed5](https://github.com/tcollier/whirled_peas/tree/f218ed5a8bbc20fc332a42ad9720467784a916e2): Optimize rendered frames
|
data/README.md
CHANGED
@@ -18,7 +18,7 @@
|
|
18
18
|
╚══╝╚══╝ ╚═╝ ╚═╝╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝╚══════╝
|
19
19
|
```
|
20
20
|
|
21
|
-
Easily create terminal-based graphics to visualize 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
|
21
|
+
Easily create terminal-based graphics to visualize 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.
|
22
22
|
|
23
23
|
## Installation
|
24
24
|
|
@@ -41,9 +41,9 @@ Or install it yourself as:
|
|
41
41
|
A Whirled Peas application consists of the following required pieces
|
42
42
|
|
43
43
|
- [The application](doc/application.md) - the code that is to be visualized, it dictates the frame contents and playback speed
|
44
|
-
- [The template factory](doc/template_factory.md) - builds templates to convert
|
44
|
+
- [The template factory](doc/template_factory.md) - builds templates to convert frames from the application into terminal graphics
|
45
45
|
|
46
|
-
These pieces are configured as
|
46
|
+
These pieces are configured as follows
|
47
47
|
|
48
48
|
```ruby
|
49
49
|
# visualize.rb
|
data/doc/components.md
CHANGED
@@ -28,11 +28,11 @@ This component takes the following options
|
|
28
28
|
|
29
29
|
#### Required
|
30
30
|
|
31
|
-
- `active_index` - the index of the active item
|
32
31
|
- `items` - the array of items to be displayed in the box
|
33
32
|
|
34
33
|
#### Optional
|
35
34
|
|
35
|
+
- `active_index` - the index of the active item, the item at the position will be highlighted and moved to the _preferred_ position. For items in the middle of a long list, the _preferred_ position is roughly 2/3rds to the way to the right in the viewport.
|
36
36
|
- `flow` - `:l2r` or `:t2b`
|
37
37
|
- `separator` - string used to separate items in the list, e.g. `", "` for a horizontal list or `"----"` for a vertical list
|
38
38
|
- `viewport_size` - number of characters of the viewport in the flow direction
|
data/doc/screen_test.md
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
## Screen Tests
|
2
2
|
|
3
|
-
In addition to standard RSpec tests, WhirledPeas has custom tests for rendered templates. These files live in `screen_test/`. Each ruby file is expected to define a class named `TemplateFactory` that responds to `#build(name, args)` returning a template (the standard template factory role). Each file should also be accompanied by a `.frame` file with the same base name. This file will contain the output of the rendered screen and is considered the correct output when running tests.
|
3
|
+
In addition to standard RSpec tests, WhirledPeas has custom tests for rendered templates. These files live in `screen_test/`. Each ruby file is expected to define a class named `TemplateFactory` that responds to `#build(name, args)` returning a template (this is the standard template factory role). Each file should also be accompanied by a `.frame` file with the same base name. This file will contain the output of the rendered screen and is considered the correct output when running tests. Use the `--view` flag to create the `.frame` file for an individual test or the `--view-pedning` flag to interactively create `.frame` files for all tests that do not have one.
|
4
4
|
|
5
5
|
Note: viewing `.frame` files with `cat` works better than most other text editors.
|
6
6
|
|
7
7
|
```
|
8
|
-
|
9
8
|
Usage: screen_test [file] [options]
|
10
9
|
|
11
10
|
If not file or options are provide, all tests are run
|
data/doc/settings.md
CHANGED
@@ -317,7 +317,17 @@ The border settings consist of 6 boolean values (border are either width 1 or no
|
|
317
317
|
|
318
318
|
Available border styles are
|
319
319
|
|
320
|
-
- `:
|
320
|
+
- `:soft` (default)
|
321
|
+
|
322
|
+
```
|
323
|
+
╭──┬──╮
|
324
|
+
│ │ │
|
325
|
+
├──┼──┤
|
326
|
+
│ │ │
|
327
|
+
╰──┴──╯
|
328
|
+
```
|
329
|
+
|
330
|
+
- `:bold`
|
321
331
|
|
322
332
|
```
|
323
333
|
┏━━┳━━┓
|
@@ -337,16 +347,6 @@ Available border styles are
|
|
337
347
|
╚══╩══╝
|
338
348
|
```
|
339
349
|
|
340
|
-
- `:soft`
|
341
|
-
|
342
|
-
```
|
343
|
-
╭──┬──╮
|
344
|
-
│ │ │
|
345
|
-
├──┼──┤
|
346
|
-
│ │ │
|
347
|
-
╰──┴──╯
|
348
|
-
```
|
349
|
-
|
350
350
|
### Display Flow
|
351
351
|
|
352
352
|
Child elements can flow in one of 4 directions
|
data/lib/data/themes.yaml
CHANGED
@@ -2,7 +2,6 @@ bright:
|
|
2
2
|
axis_color: :red
|
3
3
|
bg_color: :bright_white
|
4
4
|
border_color: :bright_blue
|
5
|
-
border_style: :soft
|
6
5
|
color: :blue
|
7
6
|
title_font: :default
|
8
7
|
|
@@ -10,7 +9,6 @@ dark:
|
|
10
9
|
axis_color: :bright_white
|
11
10
|
bg_color: :black
|
12
11
|
border_color: :gray
|
13
|
-
border_style: :double
|
14
12
|
color: :white
|
15
13
|
highlight_bg_color: :bright_red
|
16
14
|
highlight_color: :black
|
@@ -11,13 +11,16 @@ module WhirledPeas
|
|
11
11
|
@width = width
|
12
12
|
@height = height
|
13
13
|
@rendered_frames = []
|
14
|
+
@prev_pixel_grid = nil
|
14
15
|
end
|
15
16
|
|
16
17
|
def add_frameset(frameset)
|
17
18
|
frameset.each_frame do |frame, duration, args|
|
18
19
|
template = template_factory.build(frame, args)
|
19
|
-
|
20
|
+
pixel_grid = Graphics::Renderer.new(template, width, height).paint
|
21
|
+
strokes = prev_pixel_grid.nil? ? pixel_grid.to_s : pixel_grid.diff(prev_pixel_grid)
|
20
22
|
rendered_frames << Device::RenderedFrame.new(strokes, duration)
|
23
|
+
@prev_pixel_grid = pixel_grid
|
21
24
|
end
|
22
25
|
end
|
23
26
|
|
@@ -27,7 +30,7 @@ module WhirledPeas
|
|
27
30
|
|
28
31
|
private
|
29
32
|
|
30
|
-
attr_reader :template_factory, :device, :width, :height, :rendered_frames
|
33
|
+
attr_reader :template_factory, :device, :width, :height, :rendered_frames, :prev_pixel_grid
|
31
34
|
end
|
32
35
|
end
|
33
36
|
end
|
@@ -30,7 +30,7 @@ module WhirledPeas
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def compose(composer, settings)
|
33
|
-
%i[items
|
33
|
+
%i[items].each do |required_attr|
|
34
34
|
if send(required_attr).nil?
|
35
35
|
raise ArgumentError, "Required field #{required_attr} missing"
|
36
36
|
end
|
@@ -40,21 +40,22 @@ module WhirledPeas
|
|
40
40
|
settings.flow = flow
|
41
41
|
settings.align = :left
|
42
42
|
settings.full_border
|
43
|
+
curr_index = active_index || 0
|
43
44
|
if flow == :l2r
|
44
45
|
settings.width = viewport_size
|
45
|
-
active_start = separator.nil? ? 0 :
|
46
|
-
items.first(
|
46
|
+
active_start = separator.nil? ? 0 : curr_index * separator.length
|
47
|
+
items.first(curr_index).each do |item|
|
47
48
|
active_start += item.length
|
48
49
|
end
|
49
|
-
|
50
|
+
curr_size = items[curr_index].length
|
50
51
|
else
|
51
52
|
settings.height = viewport_size
|
52
|
-
active_start =
|
53
|
-
|
53
|
+
active_start = curr_index + (separator.nil? ? 0 : curr_index)
|
54
|
+
curr_size = 1
|
54
55
|
end
|
55
56
|
|
56
57
|
if viewport_size < total_size
|
57
|
-
front_padding = (viewport_size -
|
58
|
+
front_padding = (viewport_size - curr_size) * 0.667
|
58
59
|
offset = (active_start - front_padding).round
|
59
60
|
if offset < 0
|
60
61
|
offset = 0
|
@@ -8,14 +8,9 @@ module WhirledPeas
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def handle_rendered_frames(rendered_frames)
|
11
|
-
next_frame_at =
|
11
|
+
next_frame_at = Time.now
|
12
12
|
rendered_frames.each do |rendered_frame|
|
13
|
-
|
14
|
-
next_frame_at = Time.now + rendered_frame.duration
|
15
|
-
else
|
16
|
-
next_frame_at += rendered_frame.duration
|
17
|
-
next if next_frame_at < Time.now
|
18
|
-
end
|
13
|
+
next_frame_at += rendered_frame.duration
|
19
14
|
output.print(rendered_frame.strokes)
|
20
15
|
output.flush
|
21
16
|
sleep([0, next_frame_at - Time.now].max)
|
@@ -14,6 +14,43 @@ module WhirledPeas
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
def pixel_at(col, row)
|
18
|
+
pixels[row][col]
|
19
|
+
end
|
20
|
+
|
21
|
+
def diff(other)
|
22
|
+
str = ''
|
23
|
+
formatting = nil
|
24
|
+
chars = ''
|
25
|
+
pixels.each.with_index do |row, row_index|
|
26
|
+
row.each.with_index do |pixel, col_index|
|
27
|
+
if pixel == other.pixel_at(col_index, row_index)
|
28
|
+
if chars != ''
|
29
|
+
str += Utils::FormattedString.new(chars, formatting).to_s
|
30
|
+
chars = ''
|
31
|
+
formatting = nil
|
32
|
+
end
|
33
|
+
elsif chars == ''
|
34
|
+
str += Utils::Ansi.cursor_pos(left: col_index, top: row_index)
|
35
|
+
chars = pixel.char
|
36
|
+
formatting = pixel.formatting
|
37
|
+
elsif formatting != pixel.formatting
|
38
|
+
str += Utils::FormattedString.new(chars, formatting).to_s
|
39
|
+
chars = pixel.char
|
40
|
+
formatting = pixel.formatting
|
41
|
+
else
|
42
|
+
chars += pixel.char
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
if chars != ''
|
47
|
+
str += chars
|
48
|
+
chars = ''
|
49
|
+
formatting = nil
|
50
|
+
end
|
51
|
+
str
|
52
|
+
end
|
53
|
+
|
17
54
|
def to_s
|
18
55
|
str = Utils::Ansi.cursor_pos(left: 0, top: 0) + Utils::Ansi.clear_down
|
19
56
|
formatting = nil
|
@@ -34,7 +34,7 @@ module WhirledPeas
|
|
34
34
|
'╚', '═', '╩', '╝'
|
35
35
|
)
|
36
36
|
|
37
|
-
DEFAULT =
|
37
|
+
DEFAULT = SOFT
|
38
38
|
|
39
39
|
def self.validate!(style)
|
40
40
|
return if style.nil?
|
@@ -94,7 +94,7 @@ module WhirledPeas
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def style
|
97
|
-
@_style || theme.border_style || Styles::
|
97
|
+
@_style || theme.border_style || Styles::DEFAULT
|
98
98
|
end
|
99
99
|
|
100
100
|
def style=(val)
|
data/lib/whirled_peas/version.rb
CHANGED
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.
|
4
|
+
version: 0.13.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-02-
|
11
|
+
date: 2021-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: highline
|