README.md in whirled_peas-0.4.0 vs README.md in whirled_peas-0.4.1
- old
+ new
@@ -22,13 +22,13 @@
## Usage
A Whirled Peas application consists of the following pieces
-1. [REQUIRED] The driver, which emits lightweight frame events
-1. [REQUIRED] The main template factory, which builds templates to convert frame events from the driver into terminal graphics
-1. [OPTIONAL] A loading screen template factory, which is used while content is loading
+- The driver (required) - the code that is to be visualized, it emits lightweight frame events through a producer
+- The main template factory (required) - builds templates to convert frame events from the driver into terminal graphics
+- A loading screen template factory (optional) - builds templates to display while content is loading
These pieces are configured as following
```ruby
# visualize.rb
@@ -37,20 +37,20 @@
class TemplateFactory
def build(frame, args)
WhirledPeas.template do |body|
body.add_box('Title') do |_, settings|
settings.underline = true
- "Hello #{args['name']}"
+ "Hello #{args[:name]}"
end
# ...
end
end
end
class Driver
def start(producer)
- producer.send_frame('starting', args: { 'name' => 'World' })
+ producer.send_frame('starting', args: { name: 'World' })
# ...
end
end
WhirledPeas.configure do |config|
@@ -65,11 +65,11 @@
$ whirled_peas start visualize.rb
```
The optional loading screen can be configured like
-````ruby
+```ruby
class LoadingTemplateFactory
def build
WhirledPeas.template do |t|
t.add_box('Loading') do |box, settings|
settings.set_margin(top: 15)
@@ -96,23 +96,25 @@
#
# @param producer [Producer] frame producer that sends events to the UI
def start(producer)
# application code here
end
-````
+```
The producer provides a single method
```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
+# @param args [Hash<Symbol, Object>] key value pairs to send as arguments to the template factory
def send_frame(name, duration:, args:)
# implementation
end
```
+
+**IMPORTANT**: the keys for arguments must be symbols.
#### Example
Simple application that loads a set of numbers and looks for a pair that adds up to 1,000