vedeu 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/examples/borders_app.rb +15 -14
  3. data/examples/colours_app.rb +1 -2
  4. data/examples/cursor_app.rb +2 -5
  5. data/examples/geometry_app.rb +141 -0
  6. data/lib/vedeu.rb +0 -17
  7. data/lib/vedeu/api.rb +18 -3
  8. data/lib/vedeu/buffers/all.rb +0 -6
  9. data/lib/vedeu/buffers/buffer.rb +5 -2
  10. data/lib/vedeu/cursor/all.rb +0 -13
  11. data/lib/vedeu/cursor/cursor.rb +1 -1
  12. data/lib/vedeu/dsl/components/border.rb +94 -12
  13. data/lib/vedeu/dsl/components/geometry.rb +40 -48
  14. data/lib/vedeu/dsl/components/keymap.rb +36 -0
  15. data/lib/vedeu/dsl/interface.rb +20 -5
  16. data/lib/vedeu/dsl/stream.rb +2 -0
  17. data/lib/vedeu/events/all.rb +0 -5
  18. data/lib/vedeu/events/event.rb +2 -1
  19. data/lib/vedeu/events/trigger.rb +1 -3
  20. data/lib/vedeu/input/all.rb +7 -12
  21. data/lib/vedeu/input/keymap.rb +10 -34
  22. data/lib/vedeu/input/keys.rb +1 -0
  23. data/lib/vedeu/input/mapper.rb +1 -5
  24. data/lib/vedeu/models/collection.rb +4 -0
  25. data/lib/vedeu/models/geometry.rb +2 -1
  26. data/lib/vedeu/models/model.rb +4 -0
  27. data/lib/vedeu/models/view/char.rb +10 -0
  28. data/lib/vedeu/models/view/chars.rb +3 -2
  29. data/lib/vedeu/models/view/interface.rb +18 -28
  30. data/lib/vedeu/models/view/interfaces.rb +3 -2
  31. data/lib/vedeu/models/view/lines.rb +3 -2
  32. data/lib/vedeu/models/view/stream.rb +1 -1
  33. data/lib/vedeu/models/view/streams.rb +3 -2
  34. data/lib/vedeu/output/border.rb +29 -21
  35. data/lib/vedeu/output/compositor.rb +2 -3
  36. data/lib/vedeu/output/output.rb +5 -1
  37. data/lib/vedeu/output/viewport.rb +45 -24
  38. data/lib/vedeu/output/wordwrap.rb +7 -1
  39. data/lib/vedeu/output/writer.rb +3 -0
  40. data/lib/vedeu/presentation/presentation.rb +2 -0
  41. data/lib/vedeu/repositories/all.rb +107 -1
  42. data/lib/vedeu/repositories/repository.rb +4 -0
  43. data/lib/vedeu/support/bounding_area.rb +1 -1
  44. data/lib/vedeu/support/position_validator.rb +18 -0
  45. data/test/lib/vedeu/buffers/buffer_test.rb +8 -8
  46. data/test/lib/vedeu/cursor/move_cursor_test.rb +3 -6
  47. data/test/lib/vedeu/dsl/components/border_test.rb +53 -4
  48. data/test/lib/vedeu/dsl/components/geometry_test.rb +0 -24
  49. data/test/lib/vedeu/dsl/interface_test.rb +11 -3
  50. data/test/lib/vedeu/events/event_test.rb +2 -2
  51. data/test/lib/vedeu/models/view/interface_test.rb +1 -25
  52. data/test/lib/vedeu/models/view/stream_test.rb +8 -0
  53. data/test/lib/vedeu/output/border_test.rb +159 -81
  54. data/test/lib/vedeu/output/output_test.rb +1 -2
  55. data/test/lib/vedeu/output/viewport_test.rb +3 -10
  56. data/test/lib/vedeu/repositories/all_test.rb +128 -0
  57. data/test/lib/vedeu/support/content_geometry_test.rb +1 -2
  58. data/vedeu.gemspec +1 -1
  59. metadata +3 -13
  60. data/lib/vedeu/repositories/menus.rb +0 -13
  61. data/test/lib/vedeu/buffers/all_test.rb +0 -11
  62. data/test/lib/vedeu/cursor/all_test.rb +0 -33
  63. data/test/lib/vedeu/events/all_test.rb +0 -11
  64. data/test/lib/vedeu/input/all_test.rb +0 -11
  65. data/test/lib/vedeu/repositories/menus_test.rb +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 522afbcf7e2a24c1059b645ad484d1508f665c89
4
- data.tar.gz: 33f8e2f388e083fc3f2e18638ced642692047b62
3
+ metadata.gz: 2990a71171d7d18e057affb7e509d13267efbcfb
4
+ data.tar.gz: 65566020c8f8fa0a069bcf3d8ebff832e5ac378d
5
5
  SHA512:
6
- metadata.gz: 03e7507a1f364b8c5c6c236a98a7a48ca5a86ac2985f1f3856af4ba9e314eafa546e3a02c7e861182a665c14d69e290fc8f87496c32da1bdb2718dece6cd8c33
7
- data.tar.gz: 96249c16c65ca1b929e2d0b20a1e1330902338fc3cf04fede864918760bbcefc41b511634c14318624ba750a0669b3d6c865ae69891696fd47685c04578208d5
6
+ metadata.gz: c2a5b89fc277c8200f574717dd643c2c9b1b689f15f9a913a13ad67ac6f275fa4c7755493eb7452022a53e0941bb97574bdf2e692a1bbdabb93001a2d9a5e674
7
+ data.tar.gz: a1259cc57c8a5425171af9f16707ea73daa66e709e71dc5ea78ce3d9af756976d55aa8cb3b659cab92469edd1896174ce948984b1e4cda4fc529221d34a24f61
@@ -164,10 +164,23 @@ class VedeuBordersApp
164
164
  key('r') { Vedeu.trigger(:_refresh_) }
165
165
  end
166
166
 
167
+ # Borders can be defined as part of a view (see below), or standalone.
168
+ border 'no_bottom' do
169
+ show_bottom false
170
+ end
171
+ border 'no_left' do
172
+ show_left false
173
+ end
174
+ border 'no_right' do
175
+ show_right false
176
+ end
177
+ border 'no_top' do
178
+ show_top false
179
+ end
180
+
167
181
  renders do
168
182
  view('default_border') do
169
- border do
170
- end
183
+ border!
171
184
  lines do
172
185
  line 'on'
173
186
  end
@@ -178,33 +191,21 @@ class VedeuBordersApp
178
191
  end
179
192
  end
180
193
  view('no_top') do
181
- border do
182
- show_top false
183
- end
184
194
  lines do
185
195
  line 'no t'
186
196
  end
187
197
  end
188
198
  view('no_bottom') do
189
- border do
190
- show_bottom false
191
- end
192
199
  lines do
193
200
  line 'no b'
194
201
  end
195
202
  end
196
203
  view('no_left') do
197
- border do
198
- show_left false
199
- end
200
204
  lines do
201
205
  line 'no l'
202
206
  end
203
207
  end
204
208
  view('no_right') do
205
- border do
206
- show_right false
207
- end
208
209
  lines do
209
210
  line 'no r'
210
211
  end
@@ -20,8 +20,6 @@ class VedeuColoursApp
20
20
  bind(:_initialize_) { Vedeu.trigger(:_refresh_) }
21
21
 
22
22
  interface 'colours' do
23
- border do
24
- end
25
23
  geometry do
26
24
  centred!
27
25
  height 8
@@ -32,6 +30,7 @@ class VedeuColoursApp
32
30
 
33
31
  renders do
34
32
  view('colours') do
33
+ border!
35
34
  lines do
36
35
 
37
36
  end
@@ -20,12 +20,8 @@ class VedeuCursorApp
20
20
  bind(:_initialize_) { Vedeu.trigger(:_refresh_) }
21
21
 
22
22
  interface 'main_interface' do
23
- border do
24
- # adds default border
25
- end
26
-
27
- cursor true
28
23
  colour foreground: '#ff0000', background: '#000000'
24
+ cursor!
29
25
 
30
26
  geometry do
31
27
  centred true
@@ -43,6 +39,7 @@ class VedeuCursorApp
43
39
 
44
40
  renders do
45
41
  view 'main_interface' do
42
+ border!
46
43
  lines do
47
44
  streams do
48
45
  text 'A.3456789 '
@@ -0,0 +1,141 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib_dir = File.dirname(__FILE__) + '/../lib'
4
+ $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
5
+
6
+ -> { its -> { a } }
7
+ trap('INT') { exit! }
8
+
9
+ require 'vedeu'
10
+
11
+ class VedeuGeometryApp
12
+ include Vedeu
13
+
14
+ configure do
15
+ colour_mode 16777216
16
+ debug!
17
+ log '/tmp/vedeu_geometry_app.log'
18
+ end
19
+
20
+ bind(:_initialize_) { Vedeu.trigger(:_refresh_) }
21
+
22
+ interface 'main_interface' do
23
+ colour foreground: '#ff0000', background: '#000000'
24
+ cursor!
25
+
26
+ # Geometry can be defined within the interface.
27
+ geometry do
28
+ height 8
29
+ width 8
30
+ x 2
31
+ y 2
32
+ end
33
+ end
34
+
35
+ interface 'second' do
36
+ colour foreground: '#0000ff', background: '#000000'
37
+ cursor!
38
+ end
39
+
40
+ # Geometry can be defined either before or after the interface.
41
+ geometry 'second' do
42
+ height 8
43
+ width 8
44
+ x 12
45
+ y 2
46
+ end
47
+
48
+ keymap('_global_') do
49
+ key(:up, 'k') { Vedeu.trigger(:_cursor_up_) }
50
+ key(:right, 'l') { Vedeu.trigger(:_cursor_right_) }
51
+ key(:down, 'j') { Vedeu.trigger(:_cursor_down_) }
52
+ key(:left, 'h') { Vedeu.trigger(:_cursor_left_) }
53
+ end
54
+
55
+ renders do
56
+ view 'second' do
57
+ border!
58
+ lines do
59
+ line 'A.987654321'
60
+ line 'B.987654321'
61
+ line 'C.987654321'
62
+ line 'D.987654321'
63
+ line 'E.987654321'
64
+ line 'F.987654321'
65
+ line 'G.987654321'
66
+ line 'H.987654321'
67
+ end
68
+ end
69
+ view 'main_interface' do
70
+ border!
71
+ lines do
72
+ streams do
73
+ text 'A.3456789 '
74
+ end
75
+ streams do
76
+ background '#550000'
77
+ foreground '#ffff00'
78
+ text 'hydrogen'
79
+ end
80
+ streams do
81
+ text ' helium'
82
+ end
83
+ end
84
+ lines do
85
+ streams do
86
+ text 'B.3456789 lithium beryllium boron nitrogen'
87
+ end
88
+ end
89
+ lines do
90
+ streams do
91
+ text 'C.3456789'
92
+ text ' carbon oxygen '
93
+ end
94
+ streams do
95
+ background '#aadd00'
96
+ foreground '#000000'
97
+ text 'fluorine'
98
+ end
99
+ end
100
+ lines do
101
+ streams do
102
+ text 'D.3456789'
103
+ end
104
+ end
105
+ lines do
106
+ streams do
107
+ text 'E.3456789 neon sodium'
108
+ end
109
+ end
110
+ lines do
111
+ streams do
112
+ text 'F.3456789 magnesium '
113
+ end
114
+ streams do
115
+ foreground '#00aaff'
116
+ text 'aluminium'
117
+ end
118
+ end
119
+ lines do
120
+ streams do
121
+ text 'G.3456789 silicon'
122
+ end
123
+ end
124
+ lines do
125
+ streams do
126
+ background '#550000'
127
+ foreground '#ff00ff'
128
+ text 'H.34'
129
+ end
130
+ end
131
+ end
132
+ end
133
+
134
+ focus_by_name 'main_interface'
135
+
136
+ def self.start(argv = ARGV)
137
+ Vedeu::Launcher.new(argv).execute!
138
+ end
139
+ end
140
+
141
+ VedeuGeometryApp.start(ARGV)
data/lib/vedeu.rb CHANGED
@@ -16,8 +16,6 @@ require 'vedeu/support/log'
16
16
  #
17
17
  module Vedeu
18
18
 
19
- DOCS_URL = 'http://www.rubydoc.info/github/gavinlaking/vedeu/master'
20
-
21
19
  extend Forwardable
22
20
  extend self
23
21
 
@@ -28,21 +26,6 @@ module Vedeu
28
26
  @_focusable ||= Vedeu::Focus
29
27
  end
30
28
 
31
- # @return [Vedeu::Repository]
32
- def self.geometries
33
- @_geometries ||= Vedeu::Repository.new(Vedeu::Geometry)
34
- end
35
-
36
- # @return [Vedeu::Repository]
37
- def self.groups
38
- @_groups ||= Vedeu::Repository.new(Vedeu::Group)
39
- end
40
-
41
- # @return [Vedeu::Repository]
42
- def self.interfaces
43
- @_interfaces ||= Vedeu::Repository.new(Vedeu::Interface)
44
- end
45
-
46
29
  # When Vedeu is included within one of your classes, you should have all
47
30
  # API methods at your disposal.
48
31
  #
data/lib/vedeu/api.rb CHANGED
@@ -3,6 +3,7 @@ require 'vedeu/support/terminal'
3
3
  require 'vedeu/events/all'
4
4
  require 'vedeu/models/all'
5
5
  require 'vedeu/input/all'
6
+ require 'vedeu/dsl/components/border'
6
7
  require 'vedeu/dsl/composition'
7
8
  require 'vedeu/dsl/shared/all'
8
9
  require 'vedeu/dsl/view'
@@ -18,18 +19,32 @@ module Vedeu
18
19
  extend Forwardable
19
20
  extend self
20
21
 
22
+ def_delegators Vedeu::Borders, :borders
23
+ def_delegators Vedeu::Buffers, :buffers
24
+ def_delegators Vedeu::Cursors, :cursors
25
+ def_delegators Vedeu::Cursors, :cursor
26
+ def_delegators Vedeu::Events, :events
27
+ def_delegators Vedeu::Geometries, :geometries
28
+ def_delegators Vedeu::Groups, :groups
29
+ def_delegators Vedeu::InterfacesRepository, :interfaces
30
+
31
+ def_delegators Vedeu::Keymaps, :keymaps
32
+ def_delegators Vedeu::Mapper, :keypress
33
+ def_delegators Vedeu::Menus, :menus
34
+
21
35
  def_delegators Vedeu::Event, :bind, :trigger, :unbind
22
36
  def_delegators Vedeu::Configuration, :configure, :configuration
37
+ def_delegators Vedeu::DSL::Border, :border
38
+ def_delegators Vedeu::DSL::Geometry, :geometry
39
+ def_delegators Vedeu::DSL::Keymap, :keymap
23
40
  def_delegators Vedeu::DSL::Use, :use
24
41
  def_delegators Vedeu::DSL::View, :interface, :renders, :views
25
42
 
26
43
  def_delegators Vedeu::Focus, :focus, :focus_by_name, :focussed?,
27
44
  :focus_next, :focus_previous
28
- def_delegators Vedeu::Keymap, :keymap
45
+
29
46
  def_delegators Vedeu::Log, :log
30
- def_delegators Vedeu::Mapper, :keypress
31
47
  def_delegators Vedeu::Menu, :menu
32
- def_delegators Vedeu::Menus, :menus
33
48
  def_delegators Vedeu::Terminal, :height, :width, :resize
34
49
 
35
50
  end # API
@@ -2,10 +2,4 @@ require 'vedeu/buffers/buffer'
2
2
  require 'vedeu/buffers/display_buffer'
3
3
 
4
4
  module Vedeu
5
-
6
- # @return [Vedeu::Repository]
7
- def self.buffers
8
- @_buffers ||= Vedeu::Repository.new(Vedeu::Buffer)
9
- end
10
-
11
5
  end # Vedeu
@@ -16,8 +16,11 @@ module Vedeu
16
16
 
17
17
  include Vedeu::Model
18
18
 
19
- attr_accessor :back, :front, :previous
20
- attr_reader :name, :repository
19
+ attr_accessor :back,
20
+ :front,
21
+ :previous
22
+
23
+ attr_reader :name
21
24
 
22
25
  # Return a new instance of Buffer.
23
26
  #
@@ -4,17 +4,4 @@ require 'vedeu/cursor/move_cursor'
4
4
  require 'vedeu/cursor/toggle_cursor'
5
5
 
6
6
  module Vedeu
7
-
8
- extend self
9
-
10
- # @return [Vedeu::Repository]
11
- def cursors
12
- @_cursors ||= Vedeu::Repository.new(Vedeu::Cursor)
13
- end
14
-
15
- # @return [Vedeu::Cursor|NilClass]
16
- def cursor
17
- cursors.current
18
- end
19
-
20
7
  end # Vedeu
@@ -17,7 +17,7 @@ module Vedeu
17
17
 
18
18
  include Vedeu::Model
19
19
 
20
- attr_reader :attributes, :name, :ox, :oy, :repository, :state, :x, :y
20
+ attr_reader :attributes, :name, :ox, :oy, :state, :x, :y
21
21
 
22
22
  # Provides a new instance of Cursor.
23
23
  #
@@ -1,3 +1,4 @@
1
+ require 'vedeu/output/border'
1
2
  require 'vedeu/dsl/shared/all'
2
3
 
3
4
  module Vedeu
@@ -11,17 +12,42 @@ module Vedeu
11
12
  # drawn or not.
12
13
  #
13
14
  # @example
15
+ # # Borders can be defined as part of a view definition...
14
16
  # Vedeu.renders do
15
17
  # view 'border_demo' do
16
18
  # border do
17
19
  # # ...
18
20
  #
21
+ # # ...or standalone; referencing the target interface or view.
22
+ # Vedeu.border 'some_interface' do
23
+ # # ...
24
+ #
19
25
  class Border
20
26
 
21
27
  include Vedeu::DSL
22
28
  include Vedeu::DSL::Colour
23
29
  include Vedeu::DSL::Style
24
30
 
31
+ class << self
32
+
33
+ # Specify the border of an interface or view with a simple DSL.
34
+ #
35
+ # @example
36
+ # Vedeu.border 'some_interface' do
37
+ # # ...
38
+ #
39
+ # @param name [String] The name of the interface or view to which this
40
+ # border belongs.
41
+ # @param block [Proc]
42
+ # @return [Vedeu::Border]
43
+ def border(name, &block)
44
+ fail InvalidSyntax, 'block not given' unless block_given?
45
+
46
+ Vedeu::Border.build({ enabled: true, name: name }, &block).store
47
+ end
48
+
49
+ end
50
+
25
51
  # Returns an instance of DSL::Border.
26
52
  #
27
53
  # @param model [Border]
@@ -86,15 +112,29 @@ module Vedeu
86
112
  # Vedeu.renders do
87
113
  # view 'border_demo' do
88
114
  # border do
89
- # show_bottom false
90
- # # ...
115
+ # bottom false
116
+ # # ... or
117
+ # hide_bottom!
118
+ # # ... or
119
+ # show_bottom!
91
120
  #
92
121
  # @param boolean [Boolean] All values evaluate as true except nil and
93
122
  # false.
94
123
  # @return [Boolean]
95
- def show_bottom(boolean)
124
+ def bottom(boolean)
96
125
  model.attributes[:show_bottom] = !!boolean
97
126
  end
127
+ alias_method :show_bottom, :bottom
128
+
129
+ # @see #bottom
130
+ def hide_bottom!
131
+ bottom(false)
132
+ end
133
+
134
+ # @see #bottom
135
+ def show_bottom!
136
+ bottom(true)
137
+ end
98
138
 
99
139
  # Enable/disable the left border.
100
140
  #
@@ -102,15 +142,29 @@ module Vedeu
102
142
  # Vedeu.renders do
103
143
  # view 'border_demo' do
104
144
  # border do
105
- # show_left false
106
- # # ...
145
+ # left false
146
+ # # ... or
147
+ # hide_left!
148
+ # # ... or
149
+ # show_left!
107
150
  #
108
151
  # @param boolean [Boolean] All values evaluate as true except nil and
109
152
  # false.
110
153
  # @return [Boolean]
111
- def show_left(boolean)
154
+ def left(boolean)
112
155
  model.attributes[:show_left] = !!boolean
113
156
  end
157
+ alias_method :show_left, :left
158
+
159
+ # @see #left
160
+ def hide_left!
161
+ left(false)
162
+ end
163
+
164
+ # @see #left
165
+ def show_left!
166
+ left(true)
167
+ end
114
168
 
115
169
  # Enable/disable the right border.
116
170
  #
@@ -118,15 +172,29 @@ module Vedeu
118
172
  # Vedeu.renders do
119
173
  # view 'border_demo' do
120
174
  # border do
121
- # show_right false
122
- # # ...
175
+ # right false
176
+ # # ... or
177
+ # hide_right!
178
+ # # ... or
179
+ # show_right!
123
180
  #
124
181
  # @param boolean [Boolean] All values evaluate as true except nil and
125
182
  # false.
126
183
  # @return [Boolean]
127
- def show_right(boolean)
184
+ def right(boolean)
128
185
  model.attributes[:show_right] = !!boolean
129
186
  end
187
+ alias_method :show_right, :right
188
+
189
+ # @see #right
190
+ def hide_right!
191
+ right(false)
192
+ end
193
+
194
+ # @see #right
195
+ def show_right!
196
+ right(true)
197
+ end
130
198
 
131
199
  # Enable/disable the top border.
132
200
  #
@@ -134,15 +202,29 @@ module Vedeu
134
202
  # Vedeu.renders do
135
203
  # view 'border_demo' do
136
204
  # border do
137
- # show_top false
138
- # # ...
205
+ # top false
206
+ # # ... or
207
+ # hide_top!
208
+ # # ... or
209
+ # show_top!
139
210
  #
140
211
  # @param boolean [Boolean] All values evaluate as true except nil and
141
212
  # false.
142
213
  # @return [Boolean]
143
- def show_top(boolean)
214
+ def top(boolean)
144
215
  model.attributes[:show_top] = !!boolean
145
216
  end
217
+ alias_method :show_top, :top
218
+
219
+ # @see #top
220
+ def hide_top!
221
+ top(false)
222
+ end
223
+
224
+ # @see #top
225
+ def show_top!
226
+ top(true)
227
+ end
146
228
 
147
229
  # Set the character to be used to draw the top left corner of the border.
148
230
  #