vedeu 0.1.15 → 0.1.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +2 -0
  3. data/README.md +116 -98
  4. data/lib/vedeu.rb +24 -11
  5. data/lib/vedeu/api/api.rb +174 -33
  6. data/lib/vedeu/api/composition.rb +2 -13
  7. data/lib/vedeu/api/helpers.rb +41 -0
  8. data/lib/vedeu/api/interface.rb +147 -34
  9. data/lib/vedeu/api/line.rb +47 -0
  10. data/lib/vedeu/api/stream.rb +41 -0
  11. data/lib/vedeu/application.rb +9 -2
  12. data/lib/vedeu/configuration.rb +66 -8
  13. data/lib/vedeu/launcher.rb +11 -0
  14. data/lib/vedeu/models/attributes/background.rb +29 -0
  15. data/lib/vedeu/models/attributes/coercions.rb +30 -0
  16. data/lib/vedeu/models/attributes/colour_translator.rb +106 -16
  17. data/lib/vedeu/models/attributes/foreground.rb +29 -0
  18. data/lib/vedeu/models/attributes/presentation.rb +15 -0
  19. data/lib/vedeu/models/colour.rb +12 -7
  20. data/lib/vedeu/models/composition.rb +23 -5
  21. data/lib/vedeu/models/geometry.rb +101 -16
  22. data/lib/vedeu/models/interface.rb +36 -28
  23. data/lib/vedeu/models/line.rb +16 -14
  24. data/lib/vedeu/models/stream.rb +17 -25
  25. data/lib/vedeu/models/style.rb +29 -0
  26. data/lib/vedeu/support/buffer.rb +36 -21
  27. data/lib/vedeu/support/buffers.rb +88 -0
  28. data/lib/vedeu/{output → support}/clear.rb +9 -2
  29. data/lib/vedeu/support/esc.rb +16 -2
  30. data/lib/vedeu/support/event.rb +104 -0
  31. data/lib/vedeu/support/events.rb +61 -0
  32. data/lib/vedeu/support/focus.rb +69 -0
  33. data/lib/vedeu/{api → support}/grid.rb +29 -25
  34. data/lib/vedeu/support/groups.rb +51 -0
  35. data/lib/vedeu/support/input.rb +5 -0
  36. data/lib/vedeu/support/log.rb +105 -0
  37. data/lib/vedeu/support/menu.rb +19 -0
  38. data/lib/vedeu/support/position.rb +7 -0
  39. data/lib/vedeu/{output → support}/render.rb +12 -6
  40. data/lib/vedeu/support/terminal.rb +21 -0
  41. data/lib/vedeu/support/trace.rb +54 -0
  42. data/lib/vedeu/{output → support}/view.rb +15 -10
  43. data/test/lib/vedeu/api/api_test.rb +55 -29
  44. data/test/lib/vedeu/api/interface_test.rb +3 -49
  45. data/test/lib/vedeu/api/line_test.rb +71 -0
  46. data/test/lib/vedeu/api/stream_test.rb +25 -0
  47. data/test/lib/vedeu/models/attributes/background_test.rb +83 -0
  48. data/test/lib/vedeu/models/attributes/coercer_test.rb +52 -0
  49. data/test/lib/vedeu/models/attributes/foreground_test.rb +83 -0
  50. data/test/lib/vedeu/models/attributes/presentation_test.rb +30 -0
  51. data/test/lib/vedeu/models/composition_test.rb +6 -6
  52. data/test/lib/vedeu/models/geometry_test.rb +34 -0
  53. data/test/lib/vedeu/models/interface_test.rb +0 -12
  54. data/test/lib/vedeu/models/line_test.rb +1 -13
  55. data/test/lib/vedeu/models/stream_test.rb +4 -50
  56. data/test/lib/vedeu/models/style_test.rb +39 -0
  57. data/test/lib/vedeu/support/buffer_test.rb +7 -3
  58. data/test/lib/vedeu/support/buffers_test.rb +15 -0
  59. data/test/lib/vedeu/{output → support}/clear_test.rb +8 -1
  60. data/test/lib/vedeu/support/esc_test.rb +2 -2
  61. data/test/lib/vedeu/support/event_test.rb +41 -0
  62. data/test/lib/vedeu/support/events_test.rb +70 -0
  63. data/test/lib/vedeu/support/focus_test.rb +114 -0
  64. data/test/lib/vedeu/support/grid_test.rb +31 -0
  65. data/test/lib/vedeu/support/groups_test.rb +65 -0
  66. data/test/lib/vedeu/{output → support}/render_test.rb +8 -1
  67. data/test/lib/vedeu/{output → support}/view_test.rb +1 -1
  68. data/test/test_helper.rb +3 -1
  69. data/vedeu.gemspec +3 -2
  70. metadata +67 -31
  71. data/lib/vedeu/api/events.rb +0 -46
  72. data/lib/vedeu/api/log.rb +0 -84
  73. data/lib/vedeu/models/attributes/attributes.rb +0 -25
  74. data/lib/vedeu/models/store.rb +0 -29
  75. data/lib/vedeu/output/buffers.rb +0 -65
  76. data/test/lib/vedeu/api/events_test.rb +0 -36
  77. data/test/lib/vedeu/api/grid_test.rb +0 -33
  78. data/test/lib/vedeu/models/attributes/attributes_test.rb +0 -39
  79. data/test/lib/vedeu/models/attributes/colour_translator_test.rb +0 -78
  80. data/test/lib/vedeu/models/store_test.rb +0 -57
  81. data/test/lib/vedeu/output/buffers_test.rb +0 -35
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 395f38280fc3c3c2c08cd35934211d1bf5f2f088
4
- data.tar.gz: 56e22bfd0a48a8afed5d95577db5d556207f394e
3
+ metadata.gz: 8d097569d9ae161024a467480aee254bf3ea16db
4
+ data.tar.gz: a1f6e430f3a22d102ede5020716dc16a932126ce
5
5
  SHA512:
6
- metadata.gz: 358f6eb1e2c13a9e3c6ff57db89165c9799a5b5df066251cf1437443897d210435f08abed2f4a582d7d15b66cef4d0bd0bbfa4c382e1ccb4f631c23afe2542ee
7
- data.tar.gz: 34dcb6740bdae17988a112977b1b795fb455a926e474e53e41be69b2d30f11396b02333648afe7508a400da5257257a64b2ee963ef79b1f077f1a6297c5be12f
6
+ metadata.gz: ae5f70b23729b9eb744efac5ed4fcc8182ad9c4738b29b914cfb892a4d15ef83fcb5d04960955f3e8c01979990bf043aa229df1b6e89522260a1e82ccab23645
7
+ data.tar.gz: af4164804508dd1dc6cc58c2faf5f2e6248de9d31b62bab1d7fb6c70c0f8fbff09848071a08598280fadfcdc471d58550f45ed051fa6f859dd8da7e2da2b8bf2
@@ -1,4 +1,6 @@
1
1
  Copyright (c) 2014 Gavin Laking
2
+ Copyright (c) 2013 Steve Klabnik - Monologger
3
+ (https://github.com/steveklabnik/mono_logger)
2
4
 
3
5
  MIT License
4
6
 
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  [![Code Climate](https://codeclimate.com/github/gavinlaking/vedeu.png)](https://codeclimate.com/github/gavinlaking/vedeu)
2
2
  [![Build Status](https://travis-ci.org/gavinlaking/vedeu.svg?branch=master)](https://travis-ci.org/gavinlaking/vedeu)
3
+ [![Inline docs](http://inch-ci.org/github/gavinlaking/vedeu.svg?branch=master)](http://inch-ci.org/github/gavinlaking/vedeu)
3
4
 
4
5
  # Vedeu
5
6
 
@@ -26,7 +27,7 @@ And then execute:
26
27
 
27
28
  ## Example
28
29
 
29
- Have a look at: https://github.com/gavinlaking/playa
30
+ Have a look at: [Playa](https://github.com/gavinlaking/playa). Please browse the source of Playa and Vedeu to get a feel for how it all works. The [RubyDoc](http://rubydoc.info/github/gavinlaking/vedeu/master/frames) may also help!
30
31
 
31
32
 
32
33
  ## Usage
@@ -35,81 +36,79 @@ Expect proper documentation soon!
35
36
 
36
37
  ### Getting Started
37
38
 
38
- require 'vedeu'
39
-
40
- class MyApp
41
- include Vedeu
42
-
43
- interface 'main' do
44
- ...
45
- end
46
-
47
- event :some_event do
48
- # ...
49
- end
50
-
51
- event :other_event do |hash_args, array_args, args|
52
- # ...
53
- end
54
-
55
- event :key do |key|
56
- case key
57
- when 'a' then puts "Apple"
58
- when 'b' then puts "Banana"
59
- # ...
60
- when :f1 then trigger(:some_event)
61
- when :f2 then
62
- trigger(:other_event, { args: here }, [:or, :here], :etc)
63
- end
64
- end
65
- end
39
+ The basic mechanics of a Vedeu app are outlined below:
40
+
41
+ ```ruby
42
+ require 'vedeu'
43
+
44
+ class MyApp
45
+ include Vedeu
66
46
 
47
+ interface 'main' do
48
+ ...
49
+ end
67
50
 
68
- ### Building Views
51
+ event :some_event do
52
+ # ...
53
+ end
54
+
55
+ event :other_event do |hash_args, array_args, args|
56
+ # ...
57
+ end
58
+
59
+ event :key do |key|
60
+ case key
61
+ when 'a' then puts "Apple"
62
+ when 'b' then puts "Banana"
63
+ # ...
64
+ when :f1 then trigger(:some_event)
65
+ when :f2 then
66
+ trigger(:other_event, { args: here }, [:or, :here], :etc)
67
+ end
68
+ end
69
+ end
70
+ ```
71
+
72
+ ### Building Interfaces & Views
69
73
 
70
74
  Views with Vedeu are made up of simple building blocks. These blocks can be arranged in a multitude of ways which I hope is more than sufficient for your design needs.
71
75
 
72
- - Interfaces (`Interface`) are made up of lines. (`Line`)
73
- - Lines are made up of zero, one or multiple streams. (`Stream`)
76
+ - A view (`Composition`) is made up of one or more interfaces.
77
+ - An interface is an area on the screen where you can take input or direct output. You will define it's colour and style, its dimensions, including position and give it a name. You can then direct the output of a command, or event, to this interface and Vedeu will ensure the content is placed there.
78
+ - Interfaces (`Interface`) are made up of lines (`Line`), their length being the width of the interface and their number being the height of the interface.
79
+ - An interface with `width: 12, height: 5` will have five lines, each made of 12 characters- providing 60 cells. Colours and styles are handled by terminal escape sequences and therefore do not consume a cell.
80
+ - Lines are made up of zero, one or multiple streams (`Stream`) which are basically subsets of the line.
74
81
  - An interface, line or stream can have a colour (`colour`) attribute.
75
82
  - An interface, line or stream can have a style (`style`) attribute.
76
83
  - Interfaces have a position (`y`, `x`) on the screen, and a size. (`width`, `height`)
77
- - Interfaces can be placed relative to each other based on their attributes. (`top`, `right`, `bottom`, `left`)
84
+ - Interfaces can be placed relative to each other based on their attributes.
85
+ - An interface has a `top`, `right`, `bottom`, `left`.
86
+ - An interface also has a `north` and `west` (`top` and `left` minus 1 respectively).
87
+ - An interface also has a `south` and `east` (`bottom` and `right` plus 1 respectively).
78
88
  - Colours are defined in CSS-style values, i.e. `#ff0000` would be red.
79
89
  - Styles are named. See the table below for supported styles.
80
90
 
81
91
 
82
- ### Some Terms
83
-
84
- To understand how Vedeu works, you need to familiarise yourself with some terms.
85
-
86
- - Interface: This is an area on the screen where you can take input or direct output. You will define it's colour and style, its dimensions, including position and give it a name. You can then direct the output of a command to this interface and Vedeu will ensure the content is placed there.
87
-
88
- - Line: An interface is composed of many lines. Their length being the width of the interface and their number being the height of the interface.
89
-
90
- An interface with `width: 12, height: 5` will have five lines, each made of 12 characters.
91
-
92
- - Stream: A stream is a subset of a line. Having streams basically allow us to apply styles and colours to part of a line; their not necessary, but provide you with greater flexibility for your output.
93
-
94
-
95
92
  ### On Defining Interfaces
96
93
 
97
- interface 'main' do
98
- y 1
99
- x 1
100
- width 10 # see notes below
101
- height 10
102
- colour foreground: '#ffffff', background: '#000000'
103
- cursor false
104
- end
94
+ ```ruby
95
+ interface 'main' do
96
+ y 1
97
+ x 1
98
+ width 10 # see notes below
99
+ height 10
100
+ colour foreground: '#ffffff', background: '#000000'
101
+ cursor false
102
+ end
103
+ ```
105
104
 
106
105
  Referring to the above example, interfaces have a name, and various default attributes.
107
106
 
108
107
  - `y` sets the starting row point. (See Geometry)
109
108
  - `x` sets the starting column point.
110
109
 
111
- - `width` sets character width of the interface
112
- - `height` sets character height of the interface
110
+ - `width` sets the character width of the interface
111
+ - `height` sets the character height of the interface
113
112
 
114
113
  Note: not setting a width or height will set the values to the terminal's reported width and height.
115
114
 
@@ -120,18 +119,22 @@ Note: not setting a width or height will set the values to the terminal's report
120
119
 
121
120
  ### On Defining Events
122
121
 
123
- event :event_name do |arg1, arg2|
124
- end
122
+ ```ruby
123
+ event :event_name do |arg1, arg2|
124
+ end
125
+ ```
125
126
 
126
127
  One can define events which perform work or trigger other events. Vedeu has built-in events which are namespaced with underscores:
127
128
 
128
129
  - `:_initialize_` Special event which Vedeu triggers when it is ready to enter the main loop. Client applications can listen for this event and perform some action(s), like render the first screen, interface or make a sound.
129
130
 
131
+ - `:_cleanup_` This event is fired by Vedeu when `:_exit_` is triggered. You can hook into this to perform a special action before the application terminates. Saving the user's work, session or preferences might be popular here.
132
+
130
133
  - `:_clear_` Clears the whole terminal space.
131
134
 
132
- - `:_exit_` when triggered, Vedeu will attempt to exit.
135
+ - `:_exit_` when triggered, Vedeu will trigger a `:_cleanup_` event which you can define (to save files, etc) and attempt to exit.
133
136
 
134
- - `:_keypress_` triggering this event will cause the triggering of the `key` event; which you should define to 'do things'. If the `escape` key is pressed, then `key` is triggered with the argument `:escape`, also an internal event `_mode_switch_` is triggered.
137
+ - `:_keypress_` triggering this event will cause the triggering of the `:key` event; which you should define to 'do things'. If the `escape` key is pressed, then `key` is triggered with the argument `:escape`, also an internal event `_mode_switch_` is triggered.
135
138
 
136
139
  - `:_mode_switch_` when triggered (after the user presses `escape`), Vedeu switches from a "raw mode" terminal to a "cooked mode" terminal. The idea here being that the raw mode is for single keypress actions, whilst cooked mode allows the user to enter more elaborate commands- such as commands with arguments.
137
140
 
@@ -141,59 +144,74 @@ One can define events which perform work or trigger other events. Vedeu has buil
141
144
 
142
145
  - `:_refresh_(interface_name)_` will refresh the interface with this name. E.g. `_refresh_widget_` will refresh the interface `widget`.
143
146
 
144
- Note: Overriding or adding additional events to the Vedeu event namespace may cause unpredictable results.
147
+ Note: Overriding or adding additional events to the Vedeu event namespace may cause unpredictable results. It is recommended to only to hook into events like :_cleanup_, :_initialize_ and :key if you need to do something respective to those events.
145
148
 
146
149
 
147
150
  ### Geometry
148
151
 
149
- Geometry for Vedeu, as the same for ANSI terminals, is set top-left, which is point 1, 1. Interfaces have internal geometry which is handled automatically. Unless you are doing something special, you will probably only set it on a per-interface basis.
152
+ Geometry for Vedeu, as the same for ANSI terminals, is set top-left, which is cell/point 1, 1. Interfaces themselves have internal geometry which is handled automatically. Unless you are doing something special, you will probably only set it on a per-interface basis.
150
153
 
151
154
 
152
155
  ### Colours
153
156
 
154
- Vedeu uses HTML/CSS style notation (i.e. '#aadd00'), they can be used at the stream level, the line level or for the whole interface.
157
+ Vedeu uses HTML/CSS style notation (i.e. '#aadd00'), they can be used at the stream level, the line level or for the whole interface. Terminals generally support either 8, 16 or 256 colours, with few supporting full 24-bit colour. Vedeu attempts to detect the colour depth using the `$TERM` environment variable.
158
+
159
+ To set your `$TERM` variable to allow 256 colour support:
155
160
 
156
- "colour": { "foreground": "#ff0000", "background": "#ffffff" }
161
+ ```bash
162
+ echo "export TERM=xterm-256color" >> ~/.bashrc
163
+ ```
164
+
165
+ or, if you wish not to tamper with `$TERM`:
166
+
167
+ ```bash
168
+ echo "export VEDEUTERM=xterm-256color" >> ~/.bashrc
169
+ ```
170
+
171
+ If you know your terminal supports full 24-bit colour, set the `$VEDEUTERM` environment variable:
172
+
173
+ ```bash
174
+ echo "export VEDEUTERM=xterm-truecolor" >> ~/.bashrc
175
+ ```
157
176
 
158
177
 
159
178
  ### Styles
160
179
 
161
- Vedeu has a range of symbol styles which are compatible with most terminals which are ANSI compatible.
162
-
163
- "style": []
164
-
165
- Like colours, they can be defined in either interfaces, for specific lines or within streams. Styles are applied as encountered.
166
-
167
- | Style name | Escape Sequence |
168
- |---------------|-------------------------------|
169
- | bg_reset | `\e[48;2;49m` |
170
- | blink | `\e[5m` |
171
- | blink_off | `\e[25m` |
172
- | bold | `\e[1m` |
173
- | bold_off | `\e[21m` |
174
- | clear | `\e[2J` |
175
- | clear_line | `\e[38;2;39m\e[48;2;49m\e[2K` |
176
- | colour_reset | `\e[38;2;39m\e[48;2;49m` |
177
- | fg_reset | `\e[38;2;39m` |
178
- | hide_cursor | `\e[?25l` |
179
- | negative | `\e[7m` |
180
- | positive | `\e[27m` |
181
- | reset | `\e[0m` |
182
- | normal | `\e[24m\e[21m\e[27m` |
183
- | dim | `\e[2m` |
184
- | show_cursor | `\e[?25h` |
185
- | underline | `\e[4m` |
186
- | underline_off | `\e[24m` |
187
-
188
-
189
- ## Contributing
190
-
191
- 1. Fork it ( http://github.com/gavinlaking/vedeu/fork )
180
+ Vedeu has a range of symbol styles which are compatible with most terminals which are ANSI compatible. Like colours, they can be defined in either interfaces, for specific lines or within streams. Styles are applied as encountered.
181
+
182
+
183
+ ## Development / Contributing
184
+
185
+ * Documentation hosted at [RubyDoc](http://rubydoc.info/github/gavinlaking/vedeu/master/frames).
186
+ * Source hosted at [GitHub](https://github.com/gavinlaking/vedeu).
187
+
188
+ Pull requests are very welcome! Please try to follow these simple rules if applicable:
189
+
190
+ * Please create a topic branch for every separate change you make.
191
+ * Make sure your patches are well tested.
192
+ * Update the [Yard](http://yardoc.org/) documentation.
193
+ * Update the [README](https://github.com/gavinlaking/vedeu/blob/master/README.md).
194
+ * Please **do not change** the version number.
195
+
196
+
197
+ ### General contribution help
198
+
199
+ 1. Fork it ([https://github.com/gavinlaking/vedeu/fork](https://github.com/gavinlaking/vedeu/fork))
192
200
  2. Clone it
193
201
  3. `bundle`
194
- 4. `rake` or `bundle exec guard`
202
+ 4. `rake` (runs all tests and coverage report) or `bundle exec guard`
195
203
  5. Create your feature branch (`git checkout -b my-new-feature`)
196
- 6. Write some tests, write some code, have some fun
204
+ 6. Write some tests, write some code, have some fun!
197
205
  7. Commit your changes (`git commit -am 'Add some feature'`)
198
206
  8. Push to the branch (`git push origin my-new-feature`)
199
- 9. Create a new pull request
207
+ 9. Create a new pull request.
208
+
209
+
210
+ ## Author & Contributors
211
+
212
+ [Gavin Laking](https://github.com/gavinlaking) ([@gavinlaking](http://twitter.com/gavinlaking))
213
+
214
+
215
+ ### Contributors
216
+
217
+ [https://github.com/gavinlaking/vedeu/graphs/contributors](https://github.com/gavinlaking/vedeu/graphs/contributors)
@@ -1,5 +1,11 @@
1
1
  module Vedeu
2
2
 
3
+ EntityNotFound = Class.new(StandardError)
4
+ GroupNotFound = Class.new(StandardError)
5
+ ModeSwitch = Class.new(StandardError)
6
+ NotImplemented = Class.new(StandardError)
7
+ OutOfRange = Class.new(StandardError)
8
+
3
9
  def self.included(receiver)
4
10
  receiver.send(:include, API)
5
11
  receiver.extend(API)
@@ -13,38 +19,45 @@ require 'io/console'
13
19
  require 'logger'
14
20
  require 'optparse'
15
21
 
16
- require 'vedeu/models/attributes/attributes'
22
+ require 'vedeu/configuration'
23
+
24
+ require 'vedeu/models/attributes/coercions'
17
25
  require 'vedeu/models/attributes/colour_translator'
26
+ require 'vedeu/models/attributes/background'
27
+ require 'vedeu/models/attributes/foreground'
28
+ require 'vedeu/models/attributes/presentation'
18
29
  require 'vedeu/models/composition'
19
30
  require 'vedeu/support/terminal'
20
31
  require 'vedeu/models/geometry'
21
32
  require 'vedeu/models/colour'
33
+ require 'vedeu/models/style'
22
34
  require 'vedeu/models/interface'
23
35
  require 'vedeu/models/line'
24
- require 'vedeu/models/store'
25
36
  require 'vedeu/models/stream'
26
37
 
27
38
  require 'vedeu/api/api'
28
39
  require 'vedeu/api/composition'
29
- require 'vedeu/api/events'
30
- require 'vedeu/api/grid'
31
40
  require 'vedeu/api/helpers'
32
41
  require 'vedeu/api/interface'
33
42
  require 'vedeu/api/line'
34
- require 'vedeu/api/log'
35
43
  require 'vedeu/api/stream'
36
44
 
37
45
  require 'vedeu/application'
38
- require 'vedeu/configuration'
39
46
  require 'vedeu/launcher'
40
47
 
41
- require 'vedeu/output/buffers'
42
- require 'vedeu/output/clear'
43
- require 'vedeu/output/render'
44
- require 'vedeu/output/view'
45
-
48
+ require 'vedeu/support/focus'
49
+ require 'vedeu/support/groups'
50
+ require 'vedeu/support/buffers'
51
+ require 'vedeu/support/clear'
52
+ require 'vedeu/support/render'
53
+ require 'vedeu/support/view'
46
54
  require 'vedeu/support/buffer'
47
55
  require 'vedeu/support/position'
48
56
  require 'vedeu/support/esc'
57
+ require 'vedeu/support/event'
58
+ require 'vedeu/support/events'
59
+ require 'vedeu/support/grid'
49
60
  require 'vedeu/support/input'
61
+ require 'vedeu/support/log'
50
62
  require 'vedeu/support/menu'
63
+ require 'vedeu/support/trace'
@@ -1,94 +1,235 @@
1
1
  module Vedeu
2
2
  module API
3
- # @param name [Symbol] The name of the event which will be triggered later
4
- # @param delay [Fixnum|Float] Limits the execution of the triggered event to
5
- # the delay in seconds, effectively throttling the event. A delay of 1.0
6
- # will mean that even if the event is triggered multiple times a second
7
- # it will only execute once for that second. Triggers inside the delay are
8
- # discarded.
3
+
4
+ # Register an event by name with optional delay (throttling) which when
5
+ # triggered will execute the code contained within the passed block.
6
+ #
7
+ # @param name [Symbol] The name of the event which will be triggered later.
8
+ # @param [Hash] opts The options to register the event with.
9
+ # @option opts :delay [Fixnum|Float] Limits the execution of the
10
+ # triggered event to only execute when first triggered, with subsequent
11
+ # triggering being ignored until the delay has expired.
12
+ # @option opts :debounce [Fixnum|Float] Limits the execution of the
13
+ # triggered event to only execute once the debounce has expired.
14
+ # Subsequent triggers before debounce expiry are ignored.
9
15
  # @param block [Proc] The event to be executed when triggered. This block
10
16
  # could be a method call, or the triggering of another event, or sequence
11
17
  # of either/both.
12
- def event(name, delay = 0, &block)
13
- Vedeu.events.event(name, delay, &block)
18
+ #
19
+ # @example
20
+ # Vedeu.event :my_event do |some, args|
21
+ # ... some code here ...
22
+ #
23
+ # Vedeu.trigger(:my_other_event)
24
+ # end
25
+ #
26
+ # T = Triggered, X = Executed, I = Ignored.
27
+ # 0.0.....0.2.....0.4.....0.6.....0.8.....1.0.....1.2.....1.4.....1.6...
28
+ # .T...T...T...T...T...T...T...T...T...T...T...T...T...T...T...T...T...T
29
+ # .X...I...I...I...I...X...I...I...I...I...X...I...I...I...I...I...I...I
30
+ #
31
+ # Vedeu.event(:my_delayed_event, { delay: 0.5 })
32
+ # ... some code here ...
33
+ # end
34
+ #
35
+ # T = Triggered, X = Executed, I = Ignored.
36
+ # 0.0.....0.2.....0.4.....0.6.....0.8.....1.0.....1.2.....1.4.....1.6...
37
+ # .T...T...T...T...T...T...T...T...T...T...T...T...T...T...T...T...T...T
38
+ # .I...I...I...I...I...I...I...X...I...I...I...I...I...I...X...I...I...I
39
+ #
40
+ # Vedeu.event(:my_debounced_event, { debounce: 0.7 })
41
+ # ... some code here ...
42
+ # end
43
+ #
44
+ # @return [Hash]
45
+ def event(name, opts = {}, &block)
46
+ Vedeu.events.event(name, opts = {}, &block)
14
47
  end
15
48
 
16
- # @api private
17
- def events
18
- @events ||= API::Events.new do
19
- event(:_log_) { |msg| Vedeu.log(msg) }
20
- event(:_exit_) { fail StopIteration }
21
- event(:_mode_switch_) { fail ModeSwitch }
22
- event(:_clear_) { Terminal.clear_screen }
23
- event(:_refresh_) { Buffers.refresh_all }
24
- event(:_keypress_) { |key| Vedeu.keypress(key) }
25
- end
49
+ # Unregister an event by name.
50
+ #
51
+ # @param name [Symbol]
52
+ # @return [Hash]
53
+ def unevent(name)
54
+ Vedeu.events.unevent(name)
26
55
  end
27
56
 
57
+ # def focus(name)
58
+ # Focus.by_name(name)
59
+ # end
60
+
61
+ # Find out how many lines the current terminal is able to display.
62
+ #
63
+ # @example
64
+ # Vedeu.height
65
+ #
28
66
  # @return [Fixnum] The total height of the current terminal.
29
67
  def height
30
68
  Terminal.height
31
69
  end
32
70
 
71
+ # Register an interface by name which will display output from a event or
72
+ # command. This provides the means for you to define your application's
73
+ # views without their content.
74
+ #
33
75
  # @param name [String] The name of the interface. Used to reference the
34
76
  # interface throughout your application's execution lifetime.
35
77
  # @param block [Proc] A set of attributes which define the features of the
36
78
  # interface. TODO: More help.
79
+ #
80
+ # @example
81
+ # Vedeu.interface 'my_interface' do
82
+ # ... some interface attributes like width and height ...
83
+ # end
84
+ #
85
+ # @return [TrueClass]
37
86
  def interface(name, &block)
38
87
  API::Interface.define({ name: name }, &block)
39
88
  end
40
89
 
41
- # @param key [String] A simulated keypress. Escape sequences are also
42
- # supported.
90
+ # Simulate keypresses in your application. TODO: More help.
91
+ #
92
+ # @param key [String|Symbol] A simulated keypress. Escape sequences are also
93
+ # supported. Special keys like the F-keys are named as symbols; i.e. `:f4`
94
+ #
95
+ # @example
96
+ # TODO
97
+ #
98
+ # @return []
43
99
  def keypress(key)
44
- trigger(:key, key)
45
- trigger(:_log_, "Key: #{key}")
46
- trigger(:_mode_switch_) if key == :escape
100
+ Vedeu.events.trigger(:key, key)
101
+ Vedeu.events.trigger(:_log_, "Key: #{key}")
102
+ Vedeu.events.trigger(:_mode_switch_) if key == :escape
47
103
  end
48
104
 
105
+ # Write a message to the Vedeu log file located at `$HOME/.vedeu/vedeu.log`
106
+ #
49
107
  # @param message [String] The message you wish to emit to the log
50
108
  # file, useful for debugging.
109
+ #
110
+ # @example
111
+ # Vedeu.log('A useful debugging message: Error!')
112
+ #
113
+ # @return [TrueClass]
51
114
  def log(message)
52
- API::Log.logger.debug(message)
115
+ Vedeu::Log.logger.debug(message)
53
116
  end
54
117
 
118
+ # Trigger a registered or system event by name with arguments.
119
+ #
55
120
  # @param name [Symbol] The name of the event you wish to trigger.
56
121
  # The event does not have to exist.
57
122
  # @param args [Array] Any arguments the event needs to execute correctly.
123
+ #
124
+ # @example
125
+ # Vedeu.trigger(:my_event, :oxidize, 'nitrogen')
126
+ #
127
+ # @return [Array]
58
128
  def trigger(name, *args)
59
129
  Vedeu.events.trigger(name, *args)
60
130
  end
61
131
 
132
+ # Use attributes of another interface whilst defining one. TODO: More help.
133
+ #
62
134
  # @param name [String] The name of the interface you wish to use. Typically
63
- # used when defining interfaces to share geometry. TODO: Example required.
135
+ # used when defining interfaces to share geometry.
136
+ #
137
+ # @example
138
+ # Vedeu.interface 'main_screen' do
139
+ # ... some attributes ...
140
+ # width use('my_interface').width
141
+ # x use('my_interface').east(1)
142
+ # end
143
+ #
144
+ # @return [Vedeu::Interface]
64
145
  def use(name)
65
- Vedeu::Interface.new(Vedeu::Store.query(name))
146
+ Vedeu::Interface.new(Vedeu::Buffers.retrieve_attributes(name))
66
147
  end
67
148
 
149
+ # Define a view (content) for an interface. TODO: More help.
150
+ #
68
151
  # @param name [String] The name of the interface you are targetting for this
69
152
  # view.
70
153
  # @param block [Proc] The directives you wish to send to this interface.
71
- # TODO: Example required.
154
+ #
155
+ # @example
156
+ # view 'my_interface' do
157
+ # ... some view attributes ...
158
+ # end
159
+ #
160
+ # @return [Hash]
72
161
  def view(name, &block)
73
- {
74
- interfaces: [
75
- API::Interface.build({ name: name }, &block)
76
- ]
77
- }
162
+ API::Composition.build { view(name, &block) }
78
163
  end
79
164
 
165
+ # Instruct Vedeu to treat contents of block as a single composition.
166
+ # TODO: More help.
167
+ #
80
168
  # @param block [Proc] Instructs Vedeu to treat all of the 'view' directives
81
169
  # therein as one instruction. Useful for redrawing multiple interfaces at
82
- # once. TODO: Example required.
170
+ # once.
171
+ #
172
+ # @example
173
+ # views do
174
+ # view 'my_interface' do
175
+ # ... some attributes ...
176
+ # end
177
+ # view 'my_other_interface' do
178
+ # ... some other attributes ...
179
+ # end
180
+ # end
181
+ #
182
+ # composition do
183
+ # view 'my_interface' do
184
+ # ...
185
+ # ...
186
+ #
187
+ # @return [Hash]
83
188
  def views(&block)
84
189
  API::Composition.build(&block)
85
190
  end
191
+ alias_method :composition, :views
86
192
 
193
+ # Find out how many columns the current terminal is able to display.
194
+ #
195
+ # @example
196
+ # Vedeu.width
197
+ #
87
198
  # @return [Fixnum] The total width of the current terminal.
88
199
  def width
89
200
  Terminal.width
90
201
  end
202
+
203
+ # @api private
204
+ def events
205
+ @events ||= Vedeu::Events.new do
206
+ event(:_log_) { |msg| Vedeu.log(msg) }
207
+ event(:_exit_) { Vedeu.shutdown }
208
+ event(:_mode_switch_) { fail ModeSwitch }
209
+ event(:_clear_) { Terminal.clear_screen }
210
+ event(:_refresh_) { Buffers.refresh_all }
211
+ event(:_resize_, { delay: 0.25 }) { Vedeu.resize }
212
+ event(:_keypress_) { |key| Vedeu.keypress(key) }
213
+ end
214
+ end
215
+
216
+ # @api private
217
+ def resize
218
+ trigger(:_clear_)
219
+
220
+ trigger(:_refresh_)
221
+ end
222
+
223
+ # @api private
224
+ def shutdown
225
+ trigger(:_cleanup_)
226
+
227
+ fail StopIteration
228
+ end
229
+
91
230
  end
92
231
 
93
232
  extend API
233
+
234
+ trap('SIGWINCH') { Vedeu.trigger(:_resize_) }
94
235
  end