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
@@ -55,7 +55,8 @@ module Vedeu
55
55
  # @return [Hash]
56
56
  def defaults
57
57
  {
58
- client: nil
58
+ client: nil,
59
+ name: '',
59
60
  }
60
61
  end
61
62
 
@@ -23,6 +23,10 @@ module Vedeu
23
23
 
24
24
  end # ClassMethods
25
25
 
26
+ # When this module is included in a class, provide ClassMethods as class
27
+ # methods for the class.
28
+ #
29
+ # @param klass [Class]
26
30
  def self.included(klass)
27
31
  klass.send :extend, ClassMethods
28
32
  end
@@ -17,6 +17,13 @@ module Vedeu
17
17
  attr_reader :position
18
18
 
19
19
  class << self
20
+
21
+ # @param value []
22
+ # @param parent []
23
+ # @param colour []
24
+ # @param style []
25
+ # @param position []
26
+ # @return [Vedeu::Char]
20
27
  def coerce(value = nil, parent = nil, colour = nil, style = nil, position = nil)
21
28
  if value.is_a?(self)
22
29
  value
@@ -37,6 +44,7 @@ module Vedeu
37
44
 
38
45
  end
39
46
  end
47
+
40
48
  end
41
49
 
42
50
  # Returns a new instance of Char.
@@ -62,11 +70,13 @@ module Vedeu
62
70
  "<#{self.class.name} (value:#{@value})>"
63
71
  end
64
72
 
73
+ # @param other []
65
74
  # @return [Boolean]
66
75
  def ==(other)
67
76
  eql?(other)
68
77
  end
69
78
 
79
+ # @param other []
70
80
  # @return [Boolean]
71
81
  def eql?(other)
72
82
  self.class == other.class && value == other.value
@@ -2,7 +2,8 @@ require 'vedeu/models/collection'
2
2
 
3
3
  module Vedeu
4
4
 
5
+ # A collection of {Vedeu::Char} instances.
5
6
  class Chars < Vedeu::Model::Collection
6
- end
7
+ end # Chars
7
8
 
8
- end
9
+ end # Vedeu
@@ -25,10 +25,8 @@ module Vedeu
25
25
  collection Vedeu::Lines
26
26
  member Vedeu::Line
27
27
 
28
- attr_accessor :border,
29
- :colour,
28
+ attr_accessor :colour,
30
29
  :delay,
31
- :geometry,
32
30
  :group,
33
31
  :name,
34
32
  :parent,
@@ -108,10 +106,8 @@ module Vedeu
108
106
  @colour = colour
109
107
  @style = style
110
108
 
111
- @border = nil
112
- @delay = 0.0
113
- @geometry = nil
114
- @group = ''
109
+ @delay = 0.0
110
+ @group = ''
115
111
 
116
112
  @repository = Vedeu.interfaces
117
113
  end
@@ -125,10 +121,8 @@ module Vedeu
125
121
  # @return [Hash]
126
122
  def attributes
127
123
  {
128
- border: border,
129
124
  colour: colour,
130
125
  delay: delay,
131
- geometry: geometry,
132
126
  group: group,
133
127
  name: name,
134
128
  parent: parent,
@@ -140,7 +134,16 @@ module Vedeu
140
134
  #
141
135
  # @return [Boolean]
142
136
  def border?
143
- !!(border)
137
+ Vedeu.borders.registered?(name)
138
+ end
139
+
140
+ # Returns the border object belonging to the interface.
141
+ #
142
+ # @return [Vedeu::Border|NilClass]
143
+ def border
144
+ if border?
145
+ Vedeu.borders.find(name)
146
+ end
144
147
  end
145
148
 
146
149
  # @return [Vedeu::Cursor]
@@ -148,6 +151,11 @@ module Vedeu
148
151
  Vedeu.cursors.by_name(name)
149
152
  end
150
153
 
154
+ # @return [Vedeu::Geometry]
155
+ def geometry
156
+ Vedeu.geometries.find(name)
157
+ end
158
+
151
159
  # Returns log friendly output.
152
160
  #
153
161
  # @return [String]
@@ -169,19 +177,6 @@ module Vedeu
169
177
  lines.any?
170
178
  end
171
179
 
172
- # Renders the interface with a border if one is defined.
173
- #
174
- # @return [Array]
175
- def render
176
- if border?
177
- border.render
178
-
179
- else
180
- viewport
181
-
182
- end
183
- end
184
-
185
180
  # @return [Interface]
186
181
  def store
187
182
  super
@@ -193,11 +188,6 @@ module Vedeu
193
188
  store_group
194
189
  end
195
190
 
196
- # return [Array]
197
- def viewport
198
- Vedeu::Viewport.show(self)
199
- end
200
-
201
191
  end # Interface
202
192
 
203
193
  end # Vedeu
@@ -2,7 +2,8 @@ require 'vedeu/models/collection'
2
2
 
3
3
  module Vedeu
4
4
 
5
+ # A collection of {Vedeu::Interface} instances.
5
6
  class Interfaces < Vedeu::Model::Collection
6
- end
7
+ end # Interfaces
7
8
 
8
- end
9
+ end # Vedeu
@@ -2,7 +2,8 @@ require 'vedeu/models/collection'
2
2
 
3
3
  module Vedeu
4
4
 
5
+ # A collection of {Vedeu::Line} instances.
5
6
  class Lines < Vedeu::Model::Collection
6
- end
7
+ end # Lines
7
8
 
8
- end
9
+ end # Vedeu
@@ -73,7 +73,7 @@ module Vedeu
73
73
  end
74
74
 
75
75
  # @param child [Vedeu::Stream]
76
- # @return [Vedeu::Line]
76
+ # @return [Vedeu::Streams]
77
77
  def add(child)
78
78
  parent.add(child)
79
79
  end
@@ -2,7 +2,8 @@ require 'vedeu/models/collection'
2
2
 
3
3
  module Vedeu
4
4
 
5
+ # A collection of {Vedeu::Stream} instances.
5
6
  class Streams < Vedeu::Model::Collection
6
- end
7
+ end # Streams
7
8
 
8
- end
9
+ end # Vedeu
@@ -15,6 +15,7 @@ module Vedeu
15
15
  include Vedeu::Model
16
16
 
17
17
  attr_accessor :attributes
18
+ attr_reader :name
18
19
 
19
20
  class << self
20
21
 
@@ -22,7 +23,7 @@ module Vedeu
22
23
  def build(attributes = {}, &block)
23
24
  attributes = defaults.merge(attributes)
24
25
 
25
- model = new(attributes[:interface], attributes)
26
+ model = new(attributes)
26
27
  model.deputy(attributes[:client]).instance_eval(&block) if block_given?
27
28
  model
28
29
  end
@@ -35,7 +36,7 @@ module Vedeu
35
36
  def defaults
36
37
  {
37
38
  client: nil,
38
- interface: nil,
39
+ name: '',
39
40
  }
40
41
  end
41
42
 
@@ -43,26 +44,27 @@ module Vedeu
43
44
 
44
45
  # Returns a new instance of Border.
45
46
  #
46
- # @param interface [Interface]
47
47
  # @param attributes [Hash]
48
+ # @option attributes bottom_left [String]
49
+ # @option attributes bottom_right [String]
48
50
  # @option attributes colour
49
- # @option attributes style
50
51
  # @option attributes enabled [Boolean]
52
+ # @option attributes horizontal [String]
53
+ # @option attributes name [String]
54
+ # @option attributes style
51
55
  # @option attributes show_bottom [Boolean]
52
56
  # @option attributes show_left [Boolean]
53
57
  # @option attributes show_right [Boolean]
54
58
  # @option attributes show_top [Boolean]
55
- # @option attributes horizontal [String]
56
- # @option attributes vertical [String]
57
- # @option attributes bottom_left [String]
58
- # @option attributes bottom_right [String]
59
59
  # @option attributes top_left [String]
60
60
  # @option attributes top_right [String]
61
+ # @option attributes vertical [String]
61
62
  # @return [Border]
62
- def initialize(interface, attributes = {})
63
- @interface = interface
63
+ def initialize(attributes = {})
64
64
  @attributes = defaults.merge(attributes)
65
+ @name = @attributes[:name]
65
66
  @colour = Colour.coerce(@attributes[:colour])
67
+ @repository = Vedeu.borders
66
68
  @style = Style.coerce(@attributes[:style])
67
69
  end
68
70
 
@@ -177,13 +179,10 @@ module Vedeu
177
179
  #
178
180
  # @return [Boolean]
179
181
  def to_s
182
+ render = Vedeu::Viewport.new(interface).render
180
183
  render.map { |line| line.flatten.join }.join("\n")
181
184
  end
182
185
 
183
- private
184
-
185
- attr_reader :colour, :interface, :style
186
-
187
186
  # Renders the bottom border for the interface.
188
187
  #
189
188
  # @return [String]
@@ -235,6 +234,10 @@ module Vedeu
235
234
  out
236
235
  end
237
236
 
237
+ private
238
+
239
+ attr_reader :colour, :style
240
+
238
241
  # Renders the bottom left border character with escape codes for colour and
239
242
  # style for the interface.
240
243
  #
@@ -360,25 +363,30 @@ module Vedeu
360
363
  [interface.colour, interface.style]
361
364
  end
362
365
 
366
+ # @return [Vedeu::Interface]
367
+ def interface
368
+ @_interface ||= Vedeu.interfaces.find(name)
369
+ end
370
+
363
371
  # The default values for a new instance of this class.
364
372
  #
365
373
  # @return [Hash]
366
374
  def defaults
367
375
  {
376
+ bottom_left: "\x6D", # └
377
+ bottom_right: "\x6A", # ┘
378
+ colour: {},
368
379
  enabled: false,
380
+ horizontal: "\x71", # ─
381
+ name: '',
369
382
  show_bottom: true,
370
383
  show_left: true,
371
384
  show_right: true,
372
385
  show_top: true,
373
- bottom_right: "\x6A", # ┘
374
- top_right: "\x6B", # ┐
375
- top_left: "\x6C", # ┌
376
- bottom_left: "\x6D", # └
377
- horizontal: "\x71", # ─
378
- colour: {},
379
386
  style: [],
387
+ top_left: "\x6C", # ┌
388
+ top_right: "\x6B", # ┐
380
389
  vertical: "\x78", # │
381
- interface: nil,
382
390
  }
383
391
  end
384
392
 
@@ -47,10 +47,8 @@ module Vedeu
47
47
  # @return [Array<Interface>]
48
48
  def compose
49
49
  buffer.map do |view|
50
- view.border = interface.border unless view.border
51
50
  view.colour = interface.colour unless view.colour
52
51
  view.style = interface.style unless view.style
53
- view.geometry = interface.geometry unless view.geometry
54
52
 
55
53
  Output.render(view)
56
54
  end
@@ -60,11 +58,12 @@ module Vedeu
60
58
 
61
59
  attr_reader :name
62
60
 
61
+ # @return [Vedeu::Interface]
63
62
  def buffer
64
63
  Vedeu.buffers.find(name).content
65
64
  end
66
65
 
67
- # @return [Interface]
66
+ # @return [Vedeu::Interface]
68
67
  def interface
69
68
  @interface ||= Vedeu.interfaces.find(name)
70
69
  end
@@ -54,7 +54,7 @@ module Vedeu
54
54
 
55
55
  Vedeu.log("Rendering view: '#{interface.name}'")
56
56
 
57
- interface.render.each_with_index do |line, index|
57
+ viewport.each_with_index do |line, index|
58
58
  out << interface.origin(index)
59
59
  out << line.join
60
60
  end
@@ -62,6 +62,10 @@ module Vedeu
62
62
  out.join
63
63
  end
64
64
 
65
+ def viewport
66
+ @_viewport ||= Vedeu::Viewport.new(interface).render
67
+ end
68
+
65
69
  end # Output
66
70
 
67
71
  end # Vedeu
@@ -11,19 +11,11 @@ module Vedeu
11
11
  extend Forwardable
12
12
 
13
13
  def_delegators :interface,
14
- :border,
15
- :border?,
16
14
  :geometry,
17
15
  :lines,
18
16
  :lines?,
19
17
  :cursor
20
18
 
21
- def_delegators :border,
22
- :bottom?,
23
- :left?,
24
- :right?,
25
- :top?
26
-
27
19
  def_delegators :cursor,
28
20
  :ox,
29
21
  :oy
@@ -32,11 +24,6 @@ module Vedeu
32
24
  :height,
33
25
  :width
34
26
 
35
- # @see Viewport#show
36
- def self.show(interface)
37
- new(interface).show
38
- end
39
-
40
27
  # Returns an instance of Viewport.
41
28
  #
42
29
  # @param interface [Interface] An instance of interface.
@@ -45,31 +32,55 @@ module Vedeu
45
32
  @interface = interface
46
33
  end
47
34
 
48
- # Returns the visible content for the interface.
49
- #
50
- # @note If there are no lines of content, we return an empty array. If there
51
- # are no more columns of content we return a space enclosed in an array;
52
- # this prevents a weird line hopping bug which occurs when the current
53
- # line has no more content, but subsequent lines do.
35
+ # Returns the interface with border (if enabled) and the content for the
36
+ # interface.
54
37
  #
55
- # @return [Array]
56
- def show
57
- return [] unless lines?
38
+ # @return [Array<Array<String>>]
39
+ def render
40
+ if border?
41
+ out = []
58
42
 
59
- line_pad.map { |line| column_pad(line) }.compact
43
+ out << border.top if border.top?
44
+
45
+ show[0...bordered_height].each do |line|
46
+ out << [border.left, line[0...bordered_width], border.right].flatten
47
+ end
48
+
49
+ out << border.bottom if border.bottom?
50
+
51
+ out
52
+
53
+ else
54
+ show
55
+
56
+ end
60
57
  end
61
58
 
62
59
  # Returns a string representation of the viewport.
63
60
  #
64
61
  # @return [String]
65
62
  def to_s
66
- show.map(&:join).join("\n")
63
+ render.map(&:join).join("\n")
67
64
  end
68
65
 
69
66
  private
70
67
 
71
68
  attr_reader :interface
72
69
 
70
+ # Returns the visible content for the interface.
71
+ #
72
+ # @note If there are no lines of content, we return an empty array. If there
73
+ # are no more columns of content we return a space enclosed in an array;
74
+ # this prevents a weird line hopping bug which occurs when the current
75
+ # line has no more content, but subsequent lines do.
76
+ #
77
+ # @return [Array]
78
+ def show
79
+ return [] unless lines?
80
+
81
+ line_pad.map { |line| column_pad(line) }.compact
82
+ end
83
+
73
84
  # Pad the number of rows so that we always return an Array of the same
74
85
  # length for each viewport.
75
86
  #
@@ -169,6 +180,16 @@ module Vedeu
169
180
  height
170
181
  end
171
182
 
183
+ # @return [Vedeu::Border]
184
+ def border
185
+ @_border ||= Vedeu.borders.find(interface.name)
186
+ end
187
+
188
+ # @return [Boolean]
189
+ def border?
190
+ Vedeu.borders.registered?(interface.name)
191
+ end
192
+
172
193
  end # Viewport
173
194
 
174
195
  end # Vedeu