whirled_peas 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c57dd3e70f4d79c41731d220f9cb3f7fec0a3e554a715f7da556dec5e0a5cde
4
- data.tar.gz: 736d62121796101237e9aaa4fc5f37b0fe59f6d8c7670b149e63e0faf0ff9f3e
3
+ metadata.gz: 8aa42eec508df7b2634b3df5d1e3ac0b568db7051400bc4939f0516c7b34545e
4
+ data.tar.gz: 858ce91653f22b6e01771fb7397d5899caa116b42af7f8331da4bba85cf6cd74
5
5
  SHA512:
6
- metadata.gz: 1823dc0eba84af3a78992c349c1d922bfd7837452133a0e1b6e35de2fe1d94ad589b0eda8cf5c7a70ae41ec92345ef8dcde6c2e0eeb63193de806582a5d2578a
7
- data.tar.gz: d10d355b30e2cc1a0cc15413c5681b04135ec7f53a2e20e9a4ea307a8ae9bd0b69fb04cacb494dcfee8b7a9d473ae852173d140a708d1bb04210084f824acd99
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 with these templates.
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 frame from the application into terminal graphics
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 following
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
- - `:bold` (default)
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
- strokes = Graphics::Renderer.new(template, width, height).paint
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 active_index].each do |required_attr|
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 : active_index * separator.length
46
- items.first(active_index).each do |item|
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
- active_size = items[active_index].length
50
+ curr_size = items[curr_index].length
50
51
  else
51
52
  settings.height = viewport_size
52
- active_start = active_index + (separator.nil? ? 0 : active_index)
53
- active_size = 1
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 - active_size) * 0.667
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 = nil
11
+ next_frame_at = Time.now
12
12
  rendered_frames.each do |rendered_frame|
13
- if next_frame_at.nil?
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
@@ -20,7 +20,7 @@ module WhirledPeas
20
20
  template.paint(Canvas.new(0, 0, width, height), 0, 0) do |left, top, fstring|
21
21
  pixel_grid.add_stroke(left, top, fstring)
22
22
  end
23
- pixel_grid.to_s
23
+ pixel_grid
24
24
  end
25
25
 
26
26
  private
@@ -34,7 +34,7 @@ module WhirledPeas
34
34
  '╚', '═', '╩', '╝'
35
35
  )
36
36
 
37
- DEFAULT = BOLD
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::BOLD
97
+ @_style || theme.border_style || Styles::DEFAULT
98
98
  end
99
99
 
100
100
  def style=(val)
@@ -1,3 +1,3 @@
1
1
  module WhirledPeas
2
- VERSION = '0.12.0'
2
+ VERSION = '0.13.0'
3
3
  end
@@ -4,6 +4,7 @@ WhirledPeas.register_theme(:theme_test) do |theme|
4
4
  theme.bg_color = :bright_white
5
5
  theme.color = :blue
6
6
  theme.border_color = :bright_green
7
+ theme.border_style = :bold
7
8
  theme.axis_color = :bright_red
8
9
  theme.title_font = :default
9
10
  end
@@ -56,6 +56,7 @@ module WhirledPeas
56
56
  theme.color = :bright_white
57
57
  theme.bg_color = :black
58
58
  theme.border_color = :bright_white
59
+ theme.border_style = :bold
59
60
  theme.axis_color = :bright_white
60
61
  Settings::ThemeLibrary.add(:test, theme)
61
62
  @defined_theme_library = true
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.12.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-01 00:00:00.000000000 Z
11
+ date: 2021-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline