vedeu 0.4.26 → 0.4.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/examples/material_colours_app.rb +5 -3
  3. data/examples/panel_app.rb +61 -0
  4. data/lib/vedeu/bindings.rb +10 -0
  5. data/lib/vedeu/cursor/cursor.rb +6 -0
  6. data/lib/vedeu/cursor/move.rb +20 -14
  7. data/lib/vedeu/dsl/interface.rb +56 -0
  8. data/lib/vedeu/models/escape_char.rb +7 -7
  9. data/lib/vedeu/models/interface.rb +14 -17
  10. data/lib/vedeu/models/panel.rb +17 -0
  11. data/lib/vedeu/models/stream.rb +1 -1
  12. data/lib/vedeu/output/border.rb +17 -37
  13. data/lib/vedeu/output/esc.rb +17 -16
  14. data/lib/vedeu/output/html_char.rb +18 -15
  15. data/lib/vedeu/output/refresh.rb +8 -2
  16. data/lib/vedeu/output/viewport.rb +3 -1
  17. data/lib/vedeu/repositories/repositories/cursors.rb +1 -1
  18. data/lib/vedeu/repositories/repositories/interfaces_repository.rb +8 -0
  19. data/lib/vedeu/repositories/repository.rb +9 -0
  20. data/lib/vedeu/storage/store.rb +1 -0
  21. data/lib/vedeu/support/terminal.rb +7 -0
  22. data/lib/vedeu/support/visibility.rb +15 -4
  23. data/test/lib/vedeu/buffers/buffer_test.rb +1 -0
  24. data/test/lib/vedeu/dsl/components/border_test.rb +1 -0
  25. data/test/lib/vedeu/dsl/interface_test.rb +35 -5
  26. data/test/lib/vedeu/models/escape_char_test.rb +7 -2
  27. data/test/lib/vedeu/models/focus_test.rb +6 -11
  28. data/test/lib/vedeu/models/interface_test.rb +12 -9
  29. data/test/lib/vedeu/output/border_test.rb +3 -0
  30. data/test/lib/vedeu/output/esc_test.rb +4 -0
  31. data/test/lib/vedeu/repositories/repositories/interfaces_repositories_test.rb +19 -0
  32. data/test/lib/vedeu/repositories/repository_test.rb +34 -0
  33. data/test/lib/vedeu/storage/store_test.rb +4 -4
  34. data/test/lib/vedeu/support/terminal_test.rb +22 -13
  35. data/test/test_helper.rb +6 -6
  36. data/vedeu.gemspec +4 -4
  37. metadata +10 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2bba3e9391ad8c7f14484b09adc03826c64cdff5
4
- data.tar.gz: 166ea2c63e70165ec7a7b33902e8946d7f14c3b5
3
+ metadata.gz: 74b7a510a12140180d027df9a11090a30a05c9a6
4
+ data.tar.gz: 22694b40928d66db21201bf4ba5e4db403b25d32
5
5
  SHA512:
6
- metadata.gz: b18d838e63f6d47ed70ad102e5db5157bbebebbf34faf0acdcc7cbdc34cfbf13348ee2d24cb3e765d478d1f7076290c5053c1092f60d1087bf8093c97d42b603
7
- data.tar.gz: c10f07257a95dde84f961448fe4ba6d07a2539235258be5163792eeb1c345af2052786d2e006a1dd54f3452cf931aa10faf037e9fd559ef7073803186e98c393
6
+ metadata.gz: 3559b8cbb66f263c3ae5ba69057003c076a471b64344356283fee0ea65f1a37517408c9b7efe7f256f79d03ebcf628534c71f7479a8a317a8d8d605438c6cdb7
7
+ data.tar.gz: 62aa833e9ff4e93306294626b982da0b44bdcfbffe03d9cb77e227440d8c8872a13830a733a7408d5f3b4efb437d0d50e519ba1191463576b9b5db6be5861da6
@@ -25,11 +25,12 @@ class VedeuMaterialColoursApp
25
25
  colour foreground: '#ffffff', background: :default
26
26
  cursor!
27
27
  geometry 'main_interface' do
28
- x 5
29
- xn 25
30
- y 3
28
+ x 3
29
+ xn 24
30
+ y 2
31
31
  yn 13
32
32
  end
33
+ zindex 2
33
34
  end
34
35
 
35
36
  interface 'other_interface' do
@@ -45,6 +46,7 @@ class VedeuMaterialColoursApp
45
46
  y 3
46
47
  yn 13
47
48
  end
49
+ zindex 1
48
50
  end
49
51
 
50
52
  keymap('_global_') do
@@ -0,0 +1,61 @@
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
+ require 'vedeu'
7
+
8
+ # An example application to demonstrate colours, cursor and interface movement,
9
+ # maximising/unmaximising of interfaces and toggling of cursors and interfaces.
10
+ class VedeuPanelApp
11
+
12
+ include Vedeu
13
+
14
+ configure do
15
+ debug!
16
+ log '/tmp/vedeu_panel_app.log'
17
+ # renderers Vedeu::Renderers::File
18
+ end
19
+
20
+ # line { centre 'Blue', width: 20, background: '#2196f3' }
21
+ interface 'main_interface' do
22
+ border 'main_interface' do
23
+ colour foreground: '#000000', background: '#cddc39' # lime
24
+ title 'Panel: Yes/No'
25
+ end
26
+ colour foreground: '#000000', background: '#cddc39'
27
+ cursor!
28
+ geometry 'main_interface' do
29
+ centred!
30
+ width columns(10)
31
+ height 9
32
+ end
33
+ end
34
+
35
+ keymap('_global_') do
36
+ key(:up) { Vedeu.trigger(:_cursor_up_) }
37
+ key(:right) { Vedeu.trigger(:_cursor_right_) }
38
+ key(:down) { Vedeu.trigger(:_cursor_down_) }
39
+ key(:left) { Vedeu.trigger(:_cursor_left_) }
40
+ end
41
+
42
+ renders do
43
+ view 'main_interface' do
44
+ lines do
45
+ line ' '
46
+ line 'This is an example panel. It should be used for Yes/No questions.'
47
+ line 'Do you like it?'
48
+ end
49
+ button('Yes!', :confirm, true)
50
+ end
51
+ end
52
+
53
+ focus_by_name 'main_interface'
54
+
55
+ def self.start(argv = ARGV)
56
+ Vedeu::Launcher.execute!(argv)
57
+ end
58
+
59
+ end
60
+
61
+ VedeuPanelApp.start(ARGV)
@@ -110,6 +110,16 @@ module Vedeu
110
110
  Vedeu::Move.by_name(Vedeu::Cursor, :origin, name)
111
111
  end
112
112
 
113
+ # When triggered will return the current position of the cursor.
114
+ Vedeu.bind(:_cursor_position_) do |name|
115
+ named = name ? name : Vedeu.focus
116
+ cursor = Vedeu.cursors.by_name(named)
117
+
118
+ Vedeu.log(type: :debug, message: cursor.inspect)
119
+
120
+ Vedeu::Position.new(cursor.y, cursor.x) if cursor
121
+ end
122
+
113
123
  # @see {Vedeu::Move}
114
124
  Vedeu.bind(:_cursor_reset_) { |name| Vedeu.trigger(:_cursor_origin_, name) }
115
125
 
@@ -106,6 +106,12 @@ module Vedeu
106
106
  @show_cursor ||= Vedeu::EscapeChar.new(Vedeu::Esc.show_cursor)
107
107
  end
108
108
 
109
+ # @param value [Boolean]
110
+ # @return [void]
111
+ def visible=(value)
112
+ @visible = @attributes[:visible] = value
113
+ end
114
+
109
115
  private
110
116
 
111
117
  # Return the position of this cursor.
@@ -148,22 +148,10 @@ module Vedeu
148
148
  # @return [Hash<Symbol => Boolean,Fixnum, String>]
149
149
  def merged_attributes
150
150
  if entity.to_s == 'Vedeu::Geometry'
151
- {
152
- centred: false,
153
- maximised: false,
154
- name: name,
155
- x: (x + dx),
156
- y: (y + dy),
157
- xn: (xn + dx),
158
- yn: (yn + dy),
159
- }
151
+ geometry_attributes
160
152
 
161
153
  else
162
- cursor.attributes.merge!(
163
- x: x_position,
164
- y: y_position,
165
- ox: ox,
166
- oy: oy)
154
+ cursor_attributes
167
155
 
168
156
  end
169
157
  end
@@ -212,11 +200,29 @@ module Vedeu
212
200
  @cursor ||= Vedeu.cursors.by_name(name)
213
201
  end
214
202
 
203
+ # @return [Hash<Symbol => void>]
204
+ def cursor_attributes
205
+ cursor.attributes.merge!(x: x_position, y: y_position, ox: ox, oy: oy)
206
+ end
207
+
215
208
  # @return (see Vedeu::Geometries#by_name)
216
209
  def geometry
217
210
  @geometry ||= Vedeu.geometries.by_name(name)
218
211
  end
219
212
 
213
+ # @return [Hash<Symbol => FalseClass,String,Fixnum>]
214
+ def geometry_attributes
215
+ {
216
+ centred: false,
217
+ maximised: false,
218
+ name: name,
219
+ x: (x + dx),
220
+ y: (y + dy),
221
+ xn: (xn + dx),
222
+ yn: (yn + dy),
223
+ }
224
+ end
225
+
220
226
  # Apply the direction amount to the cursor offset. If the offset is less
221
227
  # than 0, correct to 0.
222
228
  #
@@ -198,6 +198,13 @@ module Vedeu
198
198
  model.name = value
199
199
  end
200
200
 
201
+ # Set the cursor to invisible for the interface.
202
+ #
203
+ # @return [Vedeu::Cursor]
204
+ def no_cursor!
205
+ cursor(false)
206
+ end
207
+
201
208
  # Set the interface to visible.
202
209
  #
203
210
  # @return [void]
@@ -238,6 +245,55 @@ module Vedeu
238
245
  model.visible = boolean
239
246
  end
240
247
 
248
+ # Set the zindex of the interface. This controls the render order of
249
+ # interfaces. Interfaces with a lower zindex will render before those
250
+ # with a higher zindex.
251
+ #
252
+ # @example
253
+ # --4-- # rendered last
254
+ # --3--
255
+ # --2--
256
+ # --1-- # rendered first
257
+ #
258
+ # interface 'my_interface' do
259
+ # zindex 3
260
+ # # ...
261
+ #
262
+ # @param value [Fixnum]
263
+ # @return [void]
264
+ def zindex(value)
265
+ model.zindex = value
266
+ end
267
+ alias_method :z_index, :zindex
268
+ alias_method :z, :zindex
269
+
270
+ # @param label [String]
271
+ # @param name [String|Symbol]
272
+ # @param value [Boolean|void]
273
+ # @return [void]
274
+ def button(label, name, value = true)
275
+ button_name = "button_#{model.name}_#{name}"
276
+ button_label = " #{label} "
277
+ button_height = 3
278
+ button_width = button_label.size + 2
279
+
280
+ Vedeu.interface button_name do
281
+ border {}
282
+ cursor
283
+ geometry do
284
+ height(button_height)
285
+ width(button_width)
286
+ end
287
+ end
288
+ Vedeu.renders do
289
+ view button_name do
290
+ lines do
291
+ line button_label
292
+ end
293
+ end
294
+ end
295
+ end
296
+
241
297
  protected
242
298
 
243
299
  # @!attribute [r] client
@@ -1,7 +1,14 @@
1
1
  module Vedeu
2
2
 
3
+ # Represents an invisible escape character sequence.
3
4
  class EscapeChar
4
5
 
6
+ # @!attribute [r] value
7
+ # @return [String]
8
+ attr_reader :value
9
+ alias_method :to_s, :value
10
+ alias_method :to_str, :value
11
+
5
12
  # @param value [String]
6
13
  # @return [Vedeu::EscapeChar]
7
14
  def initialize(value)
@@ -37,13 +44,6 @@ module Vedeu
37
44
  ''
38
45
  end
39
46
 
40
- # @return [String]
41
- def value
42
- @value
43
- end
44
- alias_method :to_s, :value
45
- alias_method :to_str, :value
46
-
47
47
  end # EscapeChar
48
48
 
49
49
  end # Vedeu
@@ -36,6 +36,10 @@ module Vedeu
36
36
  # @return [Vedeu::Composition]
37
37
  attr_accessor :parent
38
38
 
39
+ # @!attribute [rw] zindex
40
+ # @return [Fixnum]
41
+ attr_accessor :zindex
42
+
39
43
  # @!attribute [rw] visible
40
44
  # @return [Boolean] Whether the interface is visible.
41
45
  attr_accessor :visible
@@ -62,6 +66,7 @@ module Vedeu
62
66
  # @option attributes repository [Vedeu::InterfacesRepository]
63
67
  # @option attributes style [Vedeu::Style]
64
68
  # @option attributes visible [Boolean]
69
+ # @option attributes zindex [Fixnum]
65
70
  # @return [Vedeu::Interface]
66
71
  def initialize(attributes = {})
67
72
  @attributes = defaults.merge!(attributes)
@@ -74,6 +79,7 @@ module Vedeu
74
79
  @parent = @attributes[:parent]
75
80
  @repository = @attributes[:repository]
76
81
  @visible = @attributes[:visible]
82
+ @zindex = @attributes[:zindex]
77
83
  end
78
84
 
79
85
  # @param child [Vedeu::Line]
@@ -110,13 +116,17 @@ module Vedeu
110
116
  def render
111
117
  return [] unless visible?
112
118
 
113
- [
114
- hide_cursor,
119
+ Vedeu.trigger(:_cursor_hide_, name)
120
+
121
+ output = [
115
122
  Vedeu::Clear.new(self).render,
116
123
  Vedeu.borders.by_name(name).render,
117
124
  Vedeu::Viewport.render(self),
118
- show_cursor,
119
125
  ]
126
+
127
+ Vedeu.trigger(:_cursor_show_, name)
128
+
129
+ output
120
130
  end
121
131
 
122
132
  # @return [Interface]
@@ -150,23 +160,10 @@ module Vedeu
150
160
  repository: Vedeu.interfaces,
151
161
  style: nil,
152
162
  visible: true,
163
+ zindex: 0,
153
164
  }
154
165
  end
155
166
 
156
- # @return [String]
157
- def hide_cursor
158
- return cursor.hide_cursor if cursor.visible?
159
-
160
- ''
161
- end
162
-
163
- # @return [String]
164
- def show_cursor
165
- return cursor.show_cursor if cursor.visible?
166
-
167
- ''
168
- end
169
-
170
167
  end # Interface
171
168
 
172
169
  end # Vedeu
@@ -0,0 +1,17 @@
1
+ module Vedeu
2
+
3
+ class Panel
4
+
5
+ def initialize
6
+ end
7
+
8
+ private
9
+
10
+ # @return [Vedeu::Area]
11
+ def area
12
+ @area = Vedeu::Area.from_dimensions(y_yn: y_yn, x_xn: x_xn)
13
+ end
14
+
15
+ end # Panel
16
+
17
+ end # Vedeu
@@ -55,7 +55,7 @@ module Vedeu
55
55
  def chars
56
56
  return [] if empty?
57
57
 
58
- value.chars.map do |char|
58
+ @chars ||= value.chars.map do |char|
59
59
  member.new(value: char,
60
60
  parent: parent,
61
61
  colour: colour,
@@ -159,15 +159,13 @@ module Vedeu
159
159
  return [] unless visible?
160
160
  return [] unless enabled?
161
161
 
162
- Vedeu::Timer.for(:debug, "Border rendering: #{name}") do
163
- out = [top, bottom]
162
+ out = [top, bottom]
164
163
 
165
- height.times do |y|
166
- out << [left(y), right(y)]
167
- end
168
-
169
- out.flatten
164
+ height.times do |y|
165
+ out << [left(y), right(y)]
170
166
  end
167
+
168
+ out.flatten
171
169
  end
172
170
 
173
171
  # @return [String]
@@ -183,9 +181,9 @@ module Vedeu
183
181
  return [] unless bottom?
184
182
 
185
183
  out = []
186
- out << border(bottom_left, :bottom_left) if left?
187
- out << horizontal_border(:bottom_horizontal)
188
- out << border(bottom_right, :bottom_right) if right?
184
+ out << border(bottom_left, :bottom_left, *[yn, x]) if left?
185
+ out << horizontal_border(:bottom_horizontal, yn)
186
+ out << border(bottom_right, :bottom_right, *[yn, xn]) if right?
189
187
  out
190
188
  end
191
189
 
@@ -196,7 +194,7 @@ module Vedeu
196
194
  def left(iy = 0)
197
195
  return [] unless left?
198
196
 
199
- border(vertical, :left_vertical, iy)
197
+ border(vertical, :left_vertical, *[(by + iy), x])
200
198
  end
201
199
 
202
200
  # Renders the right border for the interface.
@@ -206,7 +204,7 @@ module Vedeu
206
204
  def right(iy = 0)
207
205
  return [] unless right?
208
206
 
209
- border(vertical, :right_vertical, iy)
207
+ border(vertical, :left_vertical, *[(by + iy), xn])
210
208
  end
211
209
 
212
210
  # Renders the top border for the interface.
@@ -216,15 +214,15 @@ module Vedeu
216
214
  return [] unless top?
217
215
 
218
216
  out = []
219
- out << border(top_left, :top_left) if left?
217
+ out << border(top_left, :top_left, *[y, x]) if left?
220
218
  if title?
221
219
  out << titlebar
222
220
 
223
221
  else
224
- out << horizontal_border(:top_horizontal)
222
+ out << horizontal_border(:top_horizontal, y)
225
223
 
226
224
  end
227
- out << border(top_right, :top_right) if right?
225
+ out << border(top_right, :top_right, *[y, xn]) if right?
228
226
  out
229
227
  end
230
228
 
@@ -239,9 +237,9 @@ module Vedeu
239
237
 
240
238
  # @param position [Symbol] Either :top_horizontal, or :bottom_horizontal.
241
239
  # @return [Array<Vedeu::Char>]
242
- def horizontal_border(position)
240
+ def horizontal_border(position, y_coordinate)
243
241
  width.times.each_with_object([]) do |ix, a|
244
- a << border(horizontal, position, nil, ix)
242
+ a << border(horizontal, position, *[y_coordinate, (bx + ix)])
245
243
  end
246
244
  end
247
245
 
@@ -250,7 +248,7 @@ module Vedeu
250
248
  #
251
249
  # @return [Array<Vedeu::Char>]
252
250
  def titlebar
253
- horizontal_border(:top_horizontal).each_with_index do |char, index|
251
+ horizontal_border(:top_horizontal, y).each_with_index do |char, index|
254
252
  if index >= 1 && index <= title_characters.size
255
253
  char.border = nil
256
254
  char.value = title_characters[(index - 1)]
@@ -313,7 +311,7 @@ module Vedeu
313
311
  parent: interface,
314
312
  colour: colour,
315
313
  style: style,
316
- position: position(type, iy, ix),
314
+ position: Vedeu::Position[iy, ix],
317
315
  border: type)
318
316
  end
319
317
 
@@ -356,24 +354,6 @@ module Vedeu
356
354
  }
357
355
  end
358
356
 
359
- # @param name [Symbol]
360
- # @param iy [Fixnum]
361
- # @param ix [Fixnum]
362
- # @return [Vedeu::Position]
363
- def position(name, iy = 0, ix = 0)
364
- coords = case name
365
- when :top_horizontal then [y, (bx + ix)]
366
- when :bottom_horizontal then [yn, (bx + ix)]
367
- when :left_vertical then [(by + iy), x]
368
- when :right_vertical then [(by + iy), xn]
369
- when :bottom_left then [yn, x]
370
- when :bottom_right then [yn, xn]
371
- when :top_left then [y, x]
372
- when :top_right then [y, xn]
373
- end
374
- Vedeu::Position.coerce(coords)
375
- end
376
-
377
357
  end # Border
378
358
 
379
359
  end # Vedeu