vedeu 0.4.14 → 0.4.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -3
  3. data/README.md +47 -35
  4. data/docs/views.md +1 -1
  5. data/examples/material_colours_app.rb +0 -5
  6. data/lib/vedeu/cursor/cursor.rb +4 -5
  7. data/lib/vedeu/cursor/move.rb +52 -84
  8. data/lib/vedeu/cursor/refresh_cursor.rb +12 -18
  9. data/lib/vedeu/debug.rb +3 -1
  10. data/lib/vedeu/geometry/area.rb +0 -2
  11. data/lib/vedeu/geometry/coordinate.rb +10 -0
  12. data/lib/vedeu/geometry/dimension.rb +34 -18
  13. data/lib/vedeu/geometry/null_geometry.rb +10 -1
  14. data/lib/vedeu/geometry/position.rb +1 -1
  15. data/lib/vedeu/geometry/position_validator.rb +2 -2
  16. data/lib/vedeu/input/mapper.rb +4 -18
  17. data/lib/vedeu/main_loop.rb +1 -3
  18. data/lib/vedeu/models/cell.rb +11 -17
  19. data/lib/vedeu/models/interface.rb +0 -7
  20. data/lib/vedeu/output/border.rb +34 -61
  21. data/lib/vedeu/output/clear.rb +39 -14
  22. data/lib/vedeu/output/colour.rb +15 -15
  23. data/lib/vedeu/output/esc.rb +1 -1
  24. data/lib/vedeu/output/html_char.rb +18 -24
  25. data/lib/vedeu/output/null_border.rb +14 -10
  26. data/lib/vedeu/output/presentation.rb +32 -8
  27. data/lib/vedeu/output/renderers/all.rb +1 -0
  28. data/lib/vedeu/output/renderers/text_renderer.rb +40 -0
  29. data/lib/vedeu/output/translator.rb +2 -4
  30. data/lib/vedeu/output/viewport.rb +22 -13
  31. data/lib/vedeu/output/virtual_terminal.rb +0 -1
  32. data/lib/vedeu/repositories/repositories/borders.rb +3 -4
  33. data/lib/vedeu/repositories/repositories/cursors.rb +13 -1
  34. data/lib/vedeu/repositories/repositories/geometries.rb +1 -1
  35. data/lib/vedeu/support/all.rb +1 -0
  36. data/lib/vedeu/support/options.rb +65 -0
  37. data/lib/vedeu/support/terminal.rb +3 -5
  38. data/test/lib/vedeu/cursor/cursor_test.rb +0 -5
  39. data/test/lib/vedeu/cursor/move_test.rb +87 -92
  40. data/test/lib/vedeu/geometry/null_geometry_test.rb +3 -1
  41. data/test/lib/vedeu/models/cell_test.rb +13 -16
  42. data/test/lib/vedeu/models/interface_test.rb +0 -17
  43. data/test/lib/vedeu/output/border_test.rb +0 -22
  44. data/test/lib/vedeu/output/clear_test.rb +4 -2
  45. data/test/lib/vedeu/output/null_border_test.rb +8 -4
  46. data/test/lib/vedeu/output/renderers/text_renderer_test.rb +24 -0
  47. data/test/lib/vedeu/repositories/repositories/borders_test.rb +1 -13
  48. data/test/lib/vedeu/support/options_test.rb +70 -0
  49. data/vedeu.gemspec +1 -1
  50. metadata +8 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7c54da4b2eda5de86cde144c882a63a2699475f
4
- data.tar.gz: d3477590f4f488e40117aa284a57702e039df523
3
+ metadata.gz: 1c8865f24cef3c2543a91eb50d836dbc561e25d4
4
+ data.tar.gz: 36c470985cca56b3ce4971da527483b67371121b
5
5
  SHA512:
6
- metadata.gz: a5868261a9d78a1fee37410fdc2eda682a90c4f631384fff07be495f83993869b5e6be62b246656c9ef6b6ea97389646d190295095c993c39f3fde1071322e5c
7
- data.tar.gz: 7faf1541d7b987ace4a81d94714be0c5bec7a97e750e7dac8bf8cb0c8016fccc6a3e3ac99dd9a7df357629e659069473c6c463ef07e0e8a6a53762242b5b1a6c
6
+ metadata.gz: 6fd140c4261e97199d0ac05f7d1cd45bbbd6132b4fb34db4359786c35d5f2a2fdbb4957946647cded9fcc5eecf18b7eab4a57ade8aabfb47957661e04f6d7f09
7
+ data.tar.gz: 5b123a4c23bc9600064f974c2326c0b699747c689388ff096eb3e9cfd6417fb88d04168d392ea4c76717bc6beefb4508f0606f68fdf69b1138a6f80f97eb6630
@@ -619,7 +619,7 @@ Style/WordArray:
619
619
  Metrics/AbcSize:
620
620
  # The ABC size is a calculated magnitude, so this number can be a Fixnum or
621
621
  # a Float.
622
- Max: 15
622
+ Max: 20
623
623
 
624
624
  Metrics/BlockNesting:
625
625
  Max: 3
@@ -630,7 +630,7 @@ Metrics/ClassLength:
630
630
 
631
631
  # Avoid complex methods.
632
632
  Metrics/CyclomaticComplexity:
633
- Max: 6
633
+ Max: 10
634
634
 
635
635
  Metrics/LineLength:
636
636
  Max: 80
@@ -650,7 +650,7 @@ Metrics/ParameterLists:
650
650
  CountKeywordArgs: true
651
651
 
652
652
  Metrics/PerceivedComplexity:
653
- Max: 7
653
+ Max: 10
654
654
 
655
655
  ##################### Lint ##################################
656
656
 
data/README.md CHANGED
@@ -4,7 +4,9 @@
4
4
 
5
5
  # Vedeu
6
6
 
7
- Vedeu (vee-dee-you; aka VDU) is my attempt at creating a terminal based application framework without the need for Ncurses. I've tried to make Vedeu as simple and flexible as possible.
7
+ Vedeu (vee-dee-you; aka VDU) is my attempt at creating a terminal based
8
+ application framework without the need for Ncurses. I've tried to make Vedeu
9
+ as simple and flexible as possible.
8
10
 
9
11
 
10
12
  ## Requirements
@@ -12,7 +14,8 @@ Vedeu (vee-dee-you; aka VDU) is my attempt at creating a terminal based applicat
12
14
  Vedeu has been built primarily on MacOSX 10.9/10.10 (Mavericks/Yosemite) with
13
15
  Ruby v2.1.
14
16
 
15
- Note: You may have trouble running Vedeu with Windows installations. (Pull requests welcome!)
17
+ Note: You may have trouble running Vedeu with Windows installations. (Pull
18
+ requests welcome!)
16
19
 
17
20
 
18
21
  ## Installation
@@ -28,7 +31,9 @@ And then execute:
28
31
 
29
32
  ## Example
30
33
 
31
- 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!
34
+ Have a look at: [Playa](https://github.com/gavinlaking/playa). Please browse the
35
+ source of Playa and Vedeu to get a feel for how it all works. The
36
+ [RubyDoc](http://rubydoc.info/gems/vedeu) may also help!
32
37
 
33
38
 
34
39
  ## Usage
@@ -66,20 +71,32 @@ end
66
71
 
67
72
  ### Building Interfaces & Views
68
73
 
69
- 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.
74
+ Views with Vedeu are made up of simple building blocks. These blocks can be
75
+ arranged in a multitude of ways which I hope is more than sufficient for your
76
+ design needs.
70
77
 
71
78
  - A view (`Composition`) is made up of one or more interfaces.
72
- - 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.
73
- - 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.
74
- - 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.
75
- - Lines are made up of zero, one or multiple streams (`Stream`) which are basically subsets of the line.
79
+ - An interface is an area on the screen where you can take input or direct
80
+ output. You will define it's colour and style, its dimensions, including
81
+ position and give it a name. You can then direct the output of a command, or
82
+ event, to this interface and Vedeu will ensure the content is placed there.
83
+ - Interfaces (`Interface`) are made up of lines (`Line`), their length being the
84
+ width of the interface and their number being the height of the interface.
85
+ - An interface with `width: 12, height: 5` will have five lines, each made of 12
86
+ characters- providing 60 cells. Colours and styles are handled by terminal
87
+ escape sequences and therefore do not consume a cell.
88
+ - Lines are made up of zero, one or multiple streams (`Stream`) which are
89
+ basically subsets of the line.
76
90
  - An interface, line or stream can have a colour (`colour`) attribute.
77
91
  - An interface, line or stream can have a style (`style`) attribute.
78
- - Interfaces have a position (`y`, `x`) on the screen, and a size. (`width`, `height`)
92
+ - Interfaces have a position (`y`, `x`) on the screen, and a size.
93
+ (`width`, `height`)
79
94
  - Interfaces can be placed relative to each other based on their attributes.
80
95
  - An interface has a `top`, `right`, `bottom`, `left`.
81
- - An interface also has a `north` and `west` (`top` and `left` minus 1 respectively).
82
- - An interface also has a `south` and `east` (`bottom` and `right` plus 1 respectively).
96
+ - An interface also has a `north` and `west` (`top` and `left` minus 1
97
+ respectively).
98
+ - An interface also has a `south` and `east` (`bottom` and `right` plus 1
99
+ respectively).
83
100
  - Colours are defined in CSS-style values, i.e. `#ff0000` would be red.
84
101
  - Styles are named. See the table below for supported styles.
85
102
 
@@ -98,7 +115,8 @@ interface 'main' do
98
115
  end
99
116
  ```
100
117
 
101
- Referring to the above example, interfaces have a name, and various default attributes.
118
+ Referring to the above example, interfaces have a name, and various default
119
+ attributes.
102
120
 
103
121
  - `y` sets the starting row point. (See Geometry)
104
122
  - `x` sets the starting column point.
@@ -106,7 +124,8 @@ Referring to the above example, interfaces have a name, and various default attr
106
124
  - `width` sets the character width of the interface
107
125
  - `height` sets the character height of the interface
108
126
 
109
- Note: not setting a width or height will set the values to the terminal's reported width and height.
127
+ Note: not setting a width or height will set the values to the terminal's
128
+ reported width and height.
110
129
 
111
130
  - `foreground` sets the default foreground colour.
112
131
  - `background` sets the default background colour.
@@ -114,34 +133,25 @@ Note: not setting a width or height will set the values to the terminal's report
114
133
 
115
134
  ### Events
116
135
 
117
- More information about events can be found in the [RubyDoc](http://rubydoc.info/github/gavinlaking/vedeu/master/frames).
136
+ More information about events can be found in the
137
+ [RubyDoc](http://rubydoc.info/gems/vedeu).
118
138
 
119
139
 
120
140
  ### Geometry
121
141
 
122
- 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.
123
-
124
-
125
- ## Debugging & Environment Variables
126
-
127
- Vedeu has two types of debugging; `VEDEU_DEBUG` and `VEDEU_TRACE`. Both of these can be configured at run-time using the arguments you pass to your application. They can also be enabled/disabled globally by setting environment variables (see below). These messages are written to `~/.vedeu/vedeu.log`.
128
-
129
- To enable or disable, use true or false:
130
-
131
- ```bash
132
- echo "export VEDEU_DEBUG=true" >> ~/.bashrc
133
- echo "export VEDEU_TRACE=true" >> ~/.bashrc
134
- ```
135
-
136
- Debugging (`VEDEU_DEBUG`) provides helpful messages which inform you what is happening in the application. Tracing (`VEDEU_TRACE`) is a noisy, blow-by-blow account of what is happening, letting you know which methods were called and which events have been triggered. Both (more so with tracing) can impact the performance of your application.
142
+ Geometry for Vedeu, as the same for ANSI terminals, is set top-left, which is
143
+ cell/point 1, 1. Interfaces themselves have internal geometry which is handled
144
+ automatically. Unless you are doing something special, you will probably only
145
+ set it on a per-interface basis.
137
146
 
138
147
 
139
148
  ## Development / Contributing
140
149
 
141
- * Documentation hosted at [RubyDoc](http://rubydoc.info/github/gavinlaking/vedeu/master/frames).
150
+ * Documentation hosted at [RubyDoc](http://rubydoc.info/gems/vedeu).
142
151
  * Source hosted at [GitHub](https://github.com/gavinlaking/vedeu).
143
152
 
144
- Pull requests are very welcome! Please try to follow these simple rules if applicable:
153
+ Pull requests are very welcome! Please try to follow these simple rules if
154
+ applicable:
145
155
 
146
156
  * Please create a topic branch for every separate change you make.
147
157
  * Make sure your patches are well tested.
@@ -149,8 +159,10 @@ Pull requests are very welcome! Please try to follow these simple rules if appli
149
159
  * Update the [README](https://github.com/gavinlaking/vedeu/blob/master/README.md).
150
160
  * Please **do not change** the version number.
151
161
 
152
- Any branch on the repository that is not `master` is probably experimental; do not rely on anything in these branches. Typically, `twerks` will be merged into `master` before a release,
153
- and branches prefixed with `spike/` are me playing with ideas.
162
+ Any branch on the repository that is not `master` is probably experimental; do
163
+ not rely on anything in these branches. Typically, `twerks` will be merged
164
+ into `master` before a release, and branches prefixed with `spike/` are me
165
+ playing with ideas.
154
166
 
155
167
 
156
168
  ### General contribution help
@@ -170,8 +182,8 @@ and branches prefixed with `spike/` are me playing with ideas.
170
182
 
171
183
  ### Author
172
184
 
173
- [Gavin Laking](https://github.com/gavinlaking) ([@gavinlaking](http://twitter.com/gavinlaking))
174
-
185
+ [Gavin Laking](https://github.com/gavinlaking)
186
+ ([@gavinlaking](http://twitter.com/gavinlaking))
175
187
 
176
188
  ### Contributors
177
189
 
@@ -151,7 +151,7 @@ renders/views
151
151
  #### Authors Notes
152
152
 
153
153
  The Rubydoc documentation has more specific information about the DSL methods
154
- demonstrated above; it can be accessed here.
154
+ demonstrated above: [RubyDoc](http://rubydoc.info/gems/vedeu).
155
155
 
156
156
  I've tried to write the DSL in a way which makes it read nice; believing that
157
157
  this will make it easier to use. I hope this is the case for you.
@@ -119,8 +119,3 @@ class VedeuMaterialColoursApp
119
119
  end
120
120
 
121
121
  VedeuMaterialColoursApp.start(ARGV)
122
-
123
-
124
-
125
-
126
-
@@ -8,7 +8,6 @@ module Vedeu
8
8
  #
9
9
  class Cursor
10
10
 
11
- extend Forwardable
12
11
  include Vedeu::Model
13
12
 
14
13
  # @!attribute [r] attributes
@@ -89,9 +88,8 @@ module Vedeu
89
88
  # When passed a block, will position the cursor, yield and return the
90
89
  # original position.
91
90
  #
92
- # @param block [Proc]
93
91
  # @return [String]
94
- def to_s(&block)
92
+ def to_s
95
93
  if block_given?
96
94
  [sequence, yield, sequence].join
97
95
 
@@ -103,9 +101,10 @@ module Vedeu
103
101
 
104
102
  private
105
103
 
106
- # @!attribute [r] position
107
104
  # @return [Vedeu::Position]
108
- attr_reader :position
105
+ def position
106
+ @position ||= Vedeu::Position.new(y, x)
107
+ end
109
108
 
110
109
  # The default values for a new instance of this class.
111
110
  #
@@ -37,27 +37,22 @@ module Vedeu
37
37
 
38
38
  extend Forwardable
39
39
 
40
- def_delegators :@interface, :border,
41
- :border?,
42
- :geometry
43
-
44
- def_delegators :geometry, :left,
45
- :top,
40
+ def_delegators :border,
46
41
  :height,
47
- :width
42
+ :width,
43
+ :x,
44
+ :y
48
45
 
49
46
  # Returns an instance of Vedeu::Move.
50
47
  #
51
- # @param cursor [Cursor]
52
- # @param interface [Interface]
53
- # @param dy [Fixnum] Move up (-1), or down (1), or no action (0).
54
- # @param dx [Fixnum] Move left (-1), or right (1), or no action (0).
48
+ # @param name [String] The name of the cursor.
49
+ # @param dy [Fixnum] Move up (-1), or down (1), or no action (0).
50
+ # @param dx [Fixnum] Move left (-1), or right (1), or no action (0).
55
51
  # @return [Move]
56
- def initialize(cursor, interface, dy = 0, dx = 0)
57
- @cursor = cursor
58
- @dy = dy || 0
59
- @dx = dx || 0
60
- @interface = interface
52
+ def initialize(name, dy = 0, dx = 0)
53
+ @name = name
54
+ @dy = dy
55
+ @dx = dx
61
56
  end
62
57
 
63
58
  # Move the named cursor, or that which is currently in focus in the
@@ -71,85 +66,64 @@ module Vedeu
71
66
  # cursor instance to move.
72
67
  # @return [Cursor]
73
68
  def self.by_name(direction, name = nil)
74
- if name
75
- cursor = Vedeu.cursors.by_name(name)
76
- interface = Vedeu.interfaces.find(name)
77
-
78
- else
79
- cursor = Vedeu.cursor
80
- interface = Vedeu.interfaces.current
81
-
82
- end
69
+ name = name ? name : Vedeu.focus
83
70
 
84
- new_cursor = Vedeu::Move.send(direction, cursor, interface)
85
-
86
- Vedeu.trigger(:_refresh_cursor_, new_cursor.name)
87
-
88
- new_cursor
71
+ Vedeu::Move.send(direction, name)
89
72
  end
90
73
 
91
74
  # Moves the cursor down by one row.
92
75
  #
93
- # @param cursor [Cursor]
94
- # @param interface [Interface]
76
+ # @param name [String]
95
77
  # @return [Cursor]
96
- def self.down(cursor, interface)
97
- new(cursor, interface, 1, 0).move
78
+ def self.down(name)
79
+ new(name, 1, 0).move
98
80
  end
99
81
 
100
82
  # Moves the cursor left by one column.
101
83
  #
102
- # @param cursor [Cursor]
103
- # @param interface [Interface]
84
+ # @param name [String]
104
85
  # @return [Cursor]
105
- def self.left(cursor, interface)
106
- return cursor unless cursor.ox > 0
107
-
108
- new(cursor, interface, 0, -1).move
86
+ def self.left(name)
87
+ new(name, 0, -1).move
109
88
  end
110
89
 
111
90
  # Moves the cursor right by one column.
112
91
  #
113
- # @param cursor [Cursor]
114
- # @param interface [Interface]
92
+ # @param name [String]
115
93
  # @return [Cursor]
116
- def self.right(cursor, interface)
117
- new(cursor, interface, 0, 1).move
94
+ def self.right(name)
95
+ new(name, 0, 1).move
118
96
  end
119
97
 
120
98
  # Moves the cursor up by one row.
121
99
  #
122
- # @param cursor [Cursor]
123
- # @param interface [Interface]
100
+ # @param name [String]
124
101
  # @return [Cursor]
125
- def self.up(cursor, interface)
126
- return cursor unless cursor.oy > 0
127
-
128
- new(cursor, interface, -1, 0).move
102
+ def self.up(name)
103
+ new(name, -1, 0).move
129
104
  end
130
105
 
131
106
  # Moves the cursor to the top left coordinate of the interface.
132
107
  #
133
- # @param cursor [Cursor]
134
- # @param interface [Interface]
108
+ # @param name [String]
135
109
  # @return [Cursor]
136
- def self.origin(cursor, interface)
137
- new(cursor, interface, (0 - cursor.y), (0 - cursor.x)).move
110
+ def self.origin(name)
111
+ new(name, -2000, -2000).move
138
112
  end
139
113
 
140
114
  # Returns a newly positioned and stored Cursor.
141
115
  #
142
116
  # @return [Cursor]
143
117
  def move
144
- Vedeu::Cursor.new(cursor.attributes.merge!(moved_attributes)).store
118
+ cursor = Vedeu::Cursor.new(attributes.merge!(new_attributes)).store
119
+
120
+ Vedeu.trigger(:_refresh_cursor_, name)
121
+
122
+ cursor
145
123
  end
146
124
 
147
125
  private
148
126
 
149
- # @!attribute [r] cursor
150
- # @return [Vedeu::Cursor]
151
- attr_reader :cursor
152
-
153
127
  # @!attribute [r] dx
154
128
  # @return [Fixnum]
155
129
  attr_reader :dx
@@ -158,12 +132,17 @@ module Vedeu
158
132
  # @return [Fixnum]
159
133
  attr_reader :dy
160
134
 
161
- # @!attribute [r] interface
162
- # @return [Vedeu::Interface]
163
- attr_reader :interface
135
+ # @!attribute [r] name
136
+ # @return [String]
137
+ attr_reader :name
138
+
139
+ # @return [Hash<Symbol => Fixnum, String>]
140
+ def attributes
141
+ cursor.attributes
142
+ end
164
143
 
165
144
  # @return [Hash<Symbol => Fixnum>]
166
- def moved_attributes
145
+ def new_attributes
167
146
  {
168
147
  x: validator.x,
169
148
  y: validator.y,
@@ -174,7 +153,7 @@ module Vedeu
174
153
 
175
154
  # @return [PositionValidator]
176
155
  def validator
177
- @validator ||= Vedeu::PositionValidator.validate(interface.name,
156
+ @validator ||= Vedeu::PositionValidator.validate(name,
178
157
  x_position,
179
158
  y_position)
180
159
  end
@@ -189,30 +168,19 @@ module Vedeu
189
168
  coordinate.y_position(oy)
190
169
  end
191
170
 
192
- # @return [Coordinate]
193
- def coordinate
194
- @coordinate ||= Vedeu::Coordinate.new(bordered_height,
195
- bordered_width,
196
- left,
197
- top)
171
+ # @return (see Vedeu::Borders#by_name)
172
+ def border
173
+ @border ||= Vedeu.borders.by_name(name)
198
174
  end
199
175
 
200
- # Return the height of the interface, minus any borders.
201
- #
202
- # @return [Fixnum]
203
- def bordered_height
204
- return border.height if border?
205
-
206
- height
176
+ # @return [Coordinate]
177
+ def coordinate
178
+ @coordinate ||= Vedeu::Coordinate.new(height, width, x, y)
207
179
  end
208
180
 
209
- # Return the width of the interface, minus any borders.
210
- #
211
- # @return [Fixnum]
212
- def bordered_width
213
- return border.width if border?
214
-
215
- width
181
+ # @return (see Vedeu::Cursors#by_name)
182
+ def cursor
183
+ @cursor ||= Vedeu.cursors.by_name(name)
216
184
  end
217
185
 
218
186
  # Apply the direction amount to the cursor offset. If the offset is less