vedeu 0.5.5 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/examples/material_colours_app.rb +25 -0
  3. data/lib/vedeu/all.rb +0 -1
  4. data/lib/vedeu/colours/colour_translator.rb +6 -6
  5. data/lib/vedeu/cursor/cursor.rb +0 -12
  6. data/lib/vedeu/dsl.rb +23 -0
  7. data/lib/vedeu/dsl/border.rb +0 -10
  8. data/lib/vedeu/dsl/composition.rb +1 -19
  9. data/lib/vedeu/dsl/geometry.rb +0 -10
  10. data/lib/vedeu/dsl/group.rb +0 -10
  11. data/lib/vedeu/dsl/interface.rb +0 -20
  12. data/lib/vedeu/dsl/keymap.rb +0 -10
  13. data/lib/vedeu/dsl/line.rb +3 -21
  14. data/lib/vedeu/dsl/menu.rb +0 -10
  15. data/lib/vedeu/dsl/stream.rb +4 -10
  16. data/lib/vedeu/dsl/view.rb +0 -20
  17. data/lib/vedeu/geometry/geometry.rb +0 -13
  18. data/lib/vedeu/geometry/position.rb +11 -0
  19. data/lib/vedeu/models/escape.rb +0 -7
  20. data/lib/vedeu/models/interface.rb +4 -16
  21. data/lib/vedeu/models/views/all.rb +4 -5
  22. data/lib/vedeu/models/views/char.rb +21 -22
  23. data/lib/vedeu/models/views/{chars.rb → collections/chars.rb} +0 -0
  24. data/lib/vedeu/models/views/{lines.rb → collections/lines.rb} +0 -0
  25. data/lib/vedeu/models/views/{streams.rb → collections/streams.rb} +0 -0
  26. data/lib/vedeu/models/views/{view_collection.rb → collections/view_collection.rb} +0 -0
  27. data/lib/vedeu/models/views/composition.rb +17 -19
  28. data/lib/vedeu/models/views/line.rb +19 -31
  29. data/lib/vedeu/models/views/stream.rb +7 -20
  30. data/lib/vedeu/models/views/view.rb +22 -35
  31. data/lib/vedeu/output/html_char.rb +38 -28
  32. data/lib/vedeu/output/presentation/colour.rb +15 -44
  33. data/lib/vedeu/output/presentation/style.rb +7 -14
  34. data/lib/vedeu/output/viewport.rb +0 -3
  35. data/lib/vedeu/output/virtual_terminal.rb +2 -2
  36. data/lib/vedeu/repositories/repository.rb +0 -7
  37. data/lib/vedeu/version.rb +1 -1
  38. data/test/lib/vedeu/buffers/buffer_test.rb +4 -4
  39. data/test/lib/vedeu/colours/colour_translator_test.rb +14 -0
  40. data/test/lib/vedeu/cursor/cursor_test.rb +0 -9
  41. data/test/lib/vedeu/dsl/line_test.rb +15 -13
  42. data/test/lib/vedeu/geometry/geometry_test.rb +0 -13
  43. data/test/lib/vedeu/geometry/position_test.rb +18 -0
  44. data/test/lib/vedeu/models/escape_test.rb +0 -8
  45. data/test/lib/vedeu/models/interface_test.rb +0 -12
  46. data/test/lib/vedeu/models/views/char_test.rb +4 -23
  47. data/test/lib/vedeu/models/views/{chars_test.rb → collections/chars_test.rb} +0 -0
  48. data/test/lib/vedeu/models/views/{lines_test.rb → collections/lines_test.rb} +0 -0
  49. data/test/lib/vedeu/models/views/{streams_test.rb → collections/streams_test.rb} +0 -0
  50. data/test/lib/vedeu/models/views/collections/view_collection_test.rb +22 -0
  51. data/test/lib/vedeu/models/views/composition_test.rb +23 -17
  52. data/test/lib/vedeu/models/views/line_test.rb +13 -42
  53. data/test/lib/vedeu/models/views/stream_test.rb +4 -33
  54. data/test/lib/vedeu/output/html_char_test.rb +16 -39
  55. data/test/lib/vedeu/output/presentation/colour_test.rb +63 -60
  56. data/test/lib/vedeu/output/presentation/style_test.rb +30 -29
  57. data/test/lib/vedeu/output/presentation_test.rb +1 -1
  58. data/test/lib/vedeu/output/renderers/html_test.rb +4 -8
  59. data/test/lib/vedeu/output/renderers/json_test.rb +37 -3
  60. data/test/lib/vedeu/output/wordwrap_test.rb +4 -4
  61. data/test/lib/vedeu/repositories/repository_test.rb +0 -26
  62. data/test/lib/vedeu/templating/view_template_test.rb +8 -8
  63. metadata +13 -17
  64. data/lib/vedeu/geometry/position_index.rb +0 -68
  65. data/lib/vedeu/models/interface_collection.rb +0 -9
  66. data/test/lib/vedeu/geometry/position_index_test.rb +0 -82
  67. data/test/lib/vedeu/models/interface_collection_test.rb +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b010b9db3a29aed26083a27acd4d7843e0ba8a86
4
- data.tar.gz: f5487a4cdfe1bcd1339bdc8f8eedd96f9f96e768
3
+ metadata.gz: 09870ba45d07181770a6a5ce2cb4d76791e4407c
4
+ data.tar.gz: a8fc2634c87ee748a2ef2088f9ec1e0ffa9bf4a8
5
5
  SHA512:
6
- metadata.gz: 419e080ddd2be42371edea189cbb56bf8ef02b8ba1b928aaa1a47790e4cf0da4b7ebfc82a09658cf0cc30a5af04b883f68051ad65a34a1f4070345821ca4fe97
7
- data.tar.gz: c226c7c8af7ddcaa58f83abbb20372d8578843a4ecb246d932c48e8f80c037ad23302a0d563740b3f23ae03546dbe69518b5f0030ed7c00e983bfd7503e4133a
6
+ metadata.gz: f1fa1db173f45c407e2430aa91b34a2ba4e01e7153add82561928c7369fbd16b11ac23f8f21264407f7ea1fd2ff89986a11a1174911e9e85950440286549d93f
7
+ data.tar.gz: d6520ef6b775f1d5413271fba57b2c28394428fc41af772742c1b92aad2beed4b4c8c72dd939687a3b845465ddb3353e20910fe6cdb22a995ea110f45a7bbefa
@@ -70,6 +70,27 @@ class VedeuMaterialColoursApp
70
70
  zindex(1)
71
71
  end
72
72
 
73
+ Vedeu.interface 'empty_interface' do
74
+ border 'empty_interface' do
75
+ colour(foreground: '#ffffff', background: :default)
76
+ title('Empty!')
77
+ horizontal('-')
78
+ top_right('+')
79
+ top_left('+')
80
+ bottom_right('+')
81
+ bottom_left('+')
82
+ end
83
+ colour(foreground: '#ffffff', background: :default)
84
+ cursor!
85
+ geometry 'empty_interface' do
86
+ x(50)
87
+ xn(64)
88
+ y(5)
89
+ yn(13)
90
+ end
91
+ zindex(1)
92
+ end
93
+
73
94
  Vedeu.keymap('_global_') do
74
95
  key(:up) { Vedeu.trigger(:_cursor_up_) }
75
96
  key(:right) { Vedeu.trigger(:_cursor_right_) }
@@ -149,6 +170,10 @@ class VedeuMaterialColoursApp
149
170
  line { centre 'Pink', width: 20, background: '#e91e63' }
150
171
  line { centre 'Red', width: 20, background: '#f44336' }
151
172
  end
173
+
174
+ view 'empty_interface' do
175
+ line { line '' }
176
+ end
152
177
  end
153
178
 
154
179
  Vedeu.focus_by_name 'main_interface'
data/lib/vedeu/all.rb CHANGED
@@ -46,7 +46,6 @@ require 'vedeu/geometry/dimension'
46
46
  require 'vedeu/geometry/geometry'
47
47
  require 'vedeu/geometry/geometries'
48
48
  require 'vedeu/geometry/grid'
49
- require 'vedeu/geometry/position_index'
50
49
  require 'vedeu/geometry/position'
51
50
 
52
51
  require 'vedeu/colours/escape_sequences'
@@ -50,6 +50,11 @@ module Vedeu
50
50
  @colour = colour || ''
51
51
  end
52
52
 
53
+ # @return [Boolean]
54
+ def empty?
55
+ colour.nil? || colour.to_s.empty?
56
+ end
57
+
53
58
  # An object is equal when its values are the same.
54
59
  #
55
60
  # @param other [Vedeu::Views::Char]
@@ -62,7 +67,7 @@ module Vedeu
62
67
  # @return [String]
63
68
  # @see Vedeu::ColourTranslator
64
69
  def escape_sequence
65
- if no_colour?
70
+ if empty?
66
71
  ''
67
72
 
68
73
  elsif registered?(colour)
@@ -124,11 +129,6 @@ module Vedeu
124
129
  repository.registered?(colour)
125
130
  end
126
131
 
127
- # @return [Boolean]
128
- def no_colour?
129
- colour.nil? || colour.to_s.empty?
130
- end
131
-
132
132
  # @return [Boolean]
133
133
  def named?
134
134
  colour.is_a?(Symbol) && valid_name?
@@ -62,18 +62,6 @@ module Vedeu
62
62
  @attributes.each { |key, value| instance_variable_set("@#{key}", value) }
63
63
  end
64
64
 
65
- # Override Ruby's Object#inspect method to provide a more helpful output.
66
- #
67
- # @return [String]
68
- def inspect
69
- "<Vedeu::Cursor (#{name}, " \
70
- "#{visible}, " \
71
- "x:#{x}, " \
72
- "y:#{y}, " \
73
- "ox:#{ox}, " \
74
- "oy:#{oy})>"
75
- end
76
-
77
65
  # Renders the cursor.
78
66
  #
79
67
  # @return [void]
data/lib/vedeu/dsl.rb CHANGED
@@ -4,8 +4,31 @@ module Vedeu
4
4
  #
5
5
  module DSL
6
6
 
7
+ protected
8
+
9
+ # @!attribute [r] client
10
+ # @return [Object] The object instance where the DSL is being used.
11
+ attr_reader :client
12
+
13
+ # @!attribute [r] model
14
+ # @return [void] The new model object which the DSL is constructing.
15
+ attr_reader :model
16
+
7
17
  private
8
18
 
19
+ # Returns the default attributes for the new model.
20
+ #
21
+ # @note
22
+ # Specific DSL classes may be overriding this method.
23
+ #
24
+ # @return [Hash<Symbol => void>]
25
+ def attributes
26
+ {
27
+ client: client,
28
+ parent: model,
29
+ }
30
+ end
31
+
9
32
  # :nocov:
10
33
  # Attempts to find the missing method on the client object.
11
34
  #
@@ -337,16 +337,6 @@ module Vedeu
337
337
  model.vertical = char
338
338
  end
339
339
 
340
- protected
341
-
342
- # @!attribute [r] client
343
- # @return [Object]
344
- attr_reader :client
345
-
346
- # @!attribute [r] model
347
- # @return [Vedeu::Border]
348
- attr_reader :model
349
-
350
340
  end # Border
351
341
 
352
342
  end # DSL
@@ -117,23 +117,13 @@ module Vedeu
117
117
  model.add(new_model)
118
118
  end
119
119
 
120
- protected
121
-
122
- # @!attribute [r] client
123
- # @return [Object]
124
- attr_reader :client
125
-
126
- # @!attribute [r] model
127
- # @return [Vedeu::Views::Composition]
128
- attr_reader :model
129
-
130
120
  private
131
121
 
132
122
  # @param name [String]
133
123
  # @param lines [Vedeu::Views::Lines]
134
124
  # @return [Hash]
135
125
  def template_attributes(name, lines)
136
- new_attributes(name).merge!(lines: lines)
126
+ new_attributes(name).merge!(value: lines)
137
127
  end
138
128
 
139
129
  # Return the current attributes combined with the existing interface
@@ -153,14 +143,6 @@ module Vedeu
153
143
  Vedeu.interfaces.by_name(name).attributes
154
144
  end
155
145
 
156
- # @return [Hash]
157
- def attributes
158
- {
159
- client: client,
160
- parent: model,
161
- }
162
- end
163
-
164
146
  end # Composition
165
147
 
166
148
  end # DSL
@@ -262,16 +262,6 @@ module Vedeu
262
262
  model.yn = value
263
263
  end
264
264
 
265
- protected
266
-
267
- # @!attribute [r] client
268
- # @return [Object]
269
- attr_reader :client
270
-
271
- # @!attribute [r] model
272
- # @return [Vedeu::Geometry]
273
- attr_reader :model
274
-
275
265
  end # Geometry
276
266
 
277
267
  end # DSL
@@ -71,16 +71,6 @@ module Vedeu
71
71
  model.add(interface_name)
72
72
  end
73
73
 
74
- protected
75
-
76
- # @!attribute [r] client
77
- # @return [Object]
78
- attr_reader :client
79
-
80
- # @!attribute [r] model
81
- # @return [Vedeu::Group]
82
- attr_reader :model
83
-
84
74
  end # Group
85
75
 
86
76
  end # DSL
@@ -307,26 +307,6 @@ module Vedeu
307
307
  alias_method :z_index, :zindex
308
308
  alias_method :z, :zindex
309
309
 
310
- protected
311
-
312
- # @!attribute [r] client
313
- # @return [Object]
314
- attr_reader :client
315
-
316
- # @!attribute [r] model
317
- # @return [Vedeu::Interface]
318
- attr_reader :model
319
-
320
- private
321
-
322
- # @return [Hash]
323
- def attributes
324
- {
325
- client: client,
326
- parent: model,
327
- }
328
- end
329
-
330
310
  end # Interface
331
311
 
332
312
  end # DSL
@@ -116,16 +116,6 @@ module Vedeu
116
116
  model.name = value
117
117
  end
118
118
 
119
- protected
120
-
121
- # @!attribute [r] client
122
- # @return [Object]
123
- attr_reader :client
124
-
125
- # @!attribute [r] model
126
- # @return [Vedeu::Keymap]
127
- attr_reader :model
128
-
129
119
  end # Keymap
130
120
 
131
121
  end # DSL
@@ -67,9 +67,9 @@ module Vedeu
67
67
  parent: model.parent, &block)
68
68
 
69
69
  elsif value
70
- content = Vedeu::Views::Line.build(client: client,
71
- parent: model.parent,
72
- streams: [build_stream(value)])
70
+ content = Vedeu::Views::Line.build(client: client,
71
+ parent: model.parent,
72
+ value: [build_stream(value)])
73
73
 
74
74
  else
75
75
  fail Vedeu::InvalidSyntax, 'block not given'
@@ -107,26 +107,8 @@ module Vedeu
107
107
  end
108
108
  alias_method :stream, :streams
109
109
 
110
- protected
111
-
112
- # @!attribute [r] client
113
- # @return [Object]
114
- attr_reader :client
115
-
116
- # @!attribute [r] model
117
- # @return [Vedeu::Views::Line]
118
- attr_reader :model
119
-
120
110
  private
121
111
 
122
- # @return [Hash]
123
- def attributes
124
- {
125
- client: client,
126
- parent: model,
127
- }
128
- end
129
-
130
112
  # @param value [String]
131
113
  # @return [Vedeu::Views::Stream]
132
114
  def build_stream(value)
@@ -68,16 +68,6 @@ module Vedeu
68
68
  model.name = value
69
69
  end
70
70
 
71
- protected
72
-
73
- # @!attribute [r] client
74
- # @return [Object]
75
- attr_reader :client
76
-
77
- # @!attribute [r] model
78
- # @return [Vedeu::Menu]
79
- attr_reader :model
80
-
81
71
  end # Menu
82
72
 
83
73
  end # DSL
@@ -29,18 +29,12 @@ module Vedeu
29
29
  model.add(model.class.build(attributes, &block))
30
30
  end
31
31
 
32
- protected
33
-
34
- # @!attribute [r] client
35
- # @return [Object]
36
- attr_reader :client
37
-
38
- # @!attribute [r] model
39
- # @return [Vedeu::Views::Stream]
40
- attr_reader :model
41
-
42
32
  private
43
33
 
34
+ # Returns the default attributes for the new model.
35
+ #
36
+ # Overrides {Vedeu::DSL#attributes}.
37
+ #
44
38
  # @return [Hash]
45
39
  def attributes
46
40
  {
@@ -250,26 +250,6 @@ module Vedeu
250
250
  end
251
251
  alias_method :line, :lines
252
252
 
253
- protected
254
-
255
- # @!attribute [r] client
256
- # @return [Object]
257
- attr_reader :client
258
-
259
- # @!attribute [r] model
260
- # @return [Vedeu::Views::View]
261
- attr_reader :model
262
-
263
- private
264
-
265
- # @return [Hash]
266
- def attributes
267
- {
268
- client: client,
269
- parent: model,
270
- }
271
- end
272
-
273
253
  end # View
274
254
 
275
255
  end # DSL
@@ -89,19 +89,6 @@ module Vedeu
89
89
  @attributes.each { |key, value| instance_variable_set("@#{key}", value) }
90
90
  end
91
91
 
92
- # Override Ruby's Object#inspect method to provide a more helpful output.
93
- #
94
- # @return [String]
95
- def inspect
96
- '<Vedeu::Geometry ' \
97
- "x:#{x} " \
98
- "xn:#{xn} " \
99
- "y:#{y} " \
100
- "yn:#{yn} " \
101
- "centred:#{centred} " \
102
- "maximise:#{maximised}>"
103
- end
104
-
105
92
  # Will maximise the named interface geometry. This means it will occupy all
106
93
  # of the available space on the terminal window.
107
94
  #
@@ -46,6 +46,17 @@ module Vedeu
46
46
  @x = (x.nil? || x < 1) ? 1 : x
47
47
  end
48
48
 
49
+ # Converts a position into an index for the terminal. An index is the
50
+ # position minus 1.
51
+ #
52
+ # @return [Array<Fixnum>]
53
+ def as_indices
54
+ xi = ((x - 1) <= 1) ? 0 : (x - 1)
55
+ yi = ((y - 1) <= 1) ? 0 : (y - 1)
56
+
57
+ [yi, xi]
58
+ end
59
+
49
60
  # @param other [Vedeu::Position]
50
61
  # @return [Fixnum]
51
62
  def <=>(other)
@@ -34,13 +34,6 @@ module Vedeu
34
34
  end
35
35
  alias_method :==, :eql?
36
36
 
37
- # Override Ruby's Object#inspect method to provide a more helpful output.
38
- #
39
- # @return [String]
40
- def inspect
41
- "<Vedeu::Escape '#{Vedeu::Esc.escape(to_s)}'>"
42
- end
43
-
44
37
  # @return [String]
45
38
  def position
46
39
  Vedeu::Position.coerce(@position)