README.md in whirled_peas-0.2.0 vs README.md in whirled_peas-0.3.0
- old
+ new
@@ -1,5 +1,7 @@
+[![Build Status](https://travis-ci.com/tcollier/whirled_peas.svg?branch=main)](https://travis-ci.com/tcollier/whirled_peas)
+
# WhirledPeas
Visualize your code's execution with Whirled Peas!
## Installation
@@ -35,11 +37,11 @@
end
end
class Driver
def start(producer)
- producer.send('starting', args: { 'name' => 'World' })
+ producer.send_frame('starting', args: { 'name' => 'World' })
# ...
end
end
WhirledPeas.start(Driver.new, TemplateFactory.new)
@@ -68,13 +70,12 @@
```ruby
# Send frame events to the UI
#
# @param name [String] application defined name for the frame. The template factory will be provided this name
# @param duration [Number] time in seconds this frame should be displayed for (defaults to 1 frame)
-# @param args [Hash] key value pairs to send as arguments to the template factory, these values will be
-# serialized/deserialized
-def send(name, duration:, args:)
+# @param args [Hash] key value pairs to send as arguments to the template factory
+def send_frame(name, duration:, args:)
# implementation
end
```
#### Example
@@ -83,29 +84,29 @@
```ruby
class Driver
def start(producer)
numbers = File.readlines('/path/to/numbers.txt').map(&:to_i)
- producer.send('load-numbers', duration: 3, args: { numbers: numbers })
+ producer.send_frame('load-numbers', duration: 3, args: { numbers: numbers })
numbers.sort!
- producer.send('sort-numbers', duration: 3, args: { numbers: numbers })
+ producer.send_frame('sort-numbers', duration: 3, args: { numbers: numbers })
low = 0
high = numbers.length - 1
while low < high
sum = numbers[low] + numbers[high]
if sum == 1000
- producer.send('found-pair', duration: 5, args: { low: low, high: high, sum: sum })
+ producer.send_frame('found-pair', duration: 5, args: { low: low, high: high, sum: sum })
return
elsif sum < 1000
- producer.send('too-low', args: { low: low, high: high, sum: sum })
+ producer.send_frame('too-low', args: { low: low, high: high, sum: sum })
low += 1
else
- producer.send('too-high', args: { low: low, high: high, sum: sum })
+ producer.send_frame('too-high', args: { low: low, high: high, sum: sum })
high -= 1
end
end
- producer.send('no-solution', duration: 5)
+ producer.send_frame('no-solution', duration: 5)
end
end
```
### Template Factory
@@ -114,11 +115,11 @@
#### Building Blocks
A template is created with `WhirledPeas.template`, which yields a `Template` object and `TemplateSettings`. This template object is a `ComposableElement`, which allows for attaching child elements and setting layout options. `GridElement` and `BoxElement` are two other composable elements and `TextElement` is a simple element that can hold a text/number value and has layout options, but cannot have any child elements.
-A `ComposableElement` provides the following methods to add child elements
+A `ComposableElement` 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).
- `add_box` - yields a `ComposableElement` and a `BoxSettings`, which will be added to the parent's children
- `add_grid` - yields a `ComposableElement` and a `GridSettings`, which will be added to the parent's children
- `add_text` - yields `nil` and a `TextSettings`, which will be added to the parent's children
@@ -200,19 +201,20 @@
##### Margin and Padding
Margin and padding settings allow for setting the spacing on each of the 4 sides of the element independently. The set these values, use
+- `clear_margin` - sets all margin values to 0
- `set_margin(left:, top:, right:, bottom:)`
+- `clear_padding` - sets all margin values to 0
- `set_padding(left:, top:, right:, bottom:)`
-Any argument value not provided will result in that value being 0.
-
##### Border
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
+- `clear_border` - sets all border positions to `false`
- `set_border(left:, top:, right:, bottom:, inner_horiz:, inner_vert:, color:, style:)`
Available border styles are
- `:bold` (default)
@@ -307,22 +309,22 @@
```ruby
class TemplateFactory
def build(frame, args)
set_state(frame, args)
WhirledPeas.template do |t|
- t.add_box(&method(:body))
+ t.add_box('Body', &method(:body))
end
end
private
def set_state(frame, args)
@frame = frame
- @numbers = args.key?('numbers') ? args['numbers'] || []
- @sum = args['sum'] if args.key?('sum')
- @low = args['low'] if args.key?('low')
- @high = args['high'] if args.key?('high')
+ @numbers = args.key?(:numbers) ? args[:numbers] || []
+ @sum = args[:sum] if args.key?(:sum)
+ @low = args[:low] if args.key?(:low)
+ @high = args[:high] if args.key?(:high)
end
def title(_elem, settings)
settings.underline = true
"Pair Finder"
@@ -345,12 +347,12 @@
def body(elem, settings)
settings.flow = :l2r
settings.auto_margin = true
- elem.add_box(&method(:title))
- elem.add_box(&method(:sum))
- elem.add_grid(&method(:number_grid))
+ elem.add_box('Title', &method(:title))
+ elem.add_box('Sum', &method(:sum))
+ elem.add_grid('NumberGrid', &method(:number_grid))
end
end
```
## Development