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
@@ -1,5 +1,5 @@
1
1
  require 'vedeu/models/geometry'
2
- require 'vedeu/dsl/shared/use'
2
+ require 'vedeu/dsl/shared/all'
3
3
 
4
4
  module Vedeu
5
5
 
@@ -14,6 +14,16 @@ module Vedeu
14
14
 
15
15
  class << self
16
16
 
17
+ # Specify the geometry of an interface or view with a simple DSL.
18
+ #
19
+ # @example
20
+ # Vedeu.geometry 'some_interface' do
21
+ # # ...
22
+ #
23
+ # @param name [String] The name of the interface or view to which this
24
+ # geometry belongs.
25
+ # @param block [Proc]
26
+ # @return [Vedeu::Geometry]
17
27
  def geometry(name, &block)
18
28
  fail InvalidSyntax, 'block not given' unless block_given?
19
29
 
@@ -37,14 +47,13 @@ module Vedeu
37
47
  # to true.
38
48
  #
39
49
  # @example
40
- # interface 'my_interface' do
41
- # geometry do
42
- # centred!
50
+ # geometry 'some_interface' do
51
+ # centred!
52
+ # # ...
43
53
  #
44
- # interface 'my_interface' do
45
- # geometry do
46
- # centred false
47
- # ...
54
+ # geometry 'some_interface' do
55
+ # centred false
56
+ # # ...
48
57
  #
49
58
  # @return [Boolean]
50
59
  def centred(value = true)
@@ -57,39 +66,23 @@ module Vedeu
57
66
  # @param value [Fixnum]
58
67
  #
59
68
  # @example
60
- # interface 'my_interface' do
61
- # geometry do
62
- # height 8
63
- # ...
69
+ # geometry 'some_interface' do
70
+ # height 8
71
+ # # ...
64
72
  #
65
73
  # @return [Fixnum]
66
74
  def height(value)
67
75
  model.height = value
68
76
  end
69
77
 
70
- # Specify the name of the interface for which the geometry belongs.
71
- #
72
- # @example
73
- # interface 'my_interface' do
74
- # geometry do
75
- # name 'my_interface'
76
- # ...
77
- #
78
- # @param value [String]
79
- # @return [String]
80
- def name(value)
81
- model.name = value
82
- end
83
-
84
78
  # Specify the number of characters/columns wide the interface will be.
85
79
  #
86
80
  # @param value [Fixnum]
87
81
  #
88
82
  # @example
89
- # interface 'my_interface' do
90
- # geometry do
91
- # width 25
92
- # ...
83
+ # geometry 'some_interface' do
84
+ # width 25
85
+ # # ...
93
86
  #
94
87
  # @return [Fixnum]
95
88
  def width(value)
@@ -102,15 +95,15 @@ module Vedeu
102
95
  # @param block [Proc]
103
96
  #
104
97
  # @example
105
- # interface 'my_interface' do
106
- # geometry do
107
- # x 7 # start on column 7.
98
+ # geometry 'some_interface' do
99
+ # x 7 # start on column 7.
100
+ # # ...
108
101
  #
109
- # interface 'other_interface' do
110
- # geometry do
111
- # x { use('my_interface').east } # start on column 8, if
112
- # # `my_interface` changes position,
113
- # # `other_interface` will too.
102
+ # geometry 'some_interface' do
103
+ # x { use('other_interface').east } # start on column 8, if
104
+ # # ... # `other_interface` changes
105
+ # # position, `some_interface` will
106
+ # # too.
114
107
  #
115
108
  # @return [Fixnum]
116
109
  def x(value = 0, &block)
@@ -125,16 +118,15 @@ module Vedeu
125
118
  # @param block [Proc]
126
119
  #
127
120
  # @example
128
- # interface 'my_interface' do
129
- # geometry do
130
- # y 4
131
- # ...
132
- #
133
- # interface 'other_interface' do
134
- # geometry do
135
- # y { use('my_interface').north } # start on row/line 3, if
136
- # ... # `my_interface` changes position,
137
- # # `other_interface` will too.
121
+ # geometry 'some_interface' do
122
+ # y 4
123
+ # # ...
124
+ #
125
+ # geometry 'some_interface' do
126
+ # y { use('other_interface').north } # start on row/line 3, if
127
+ # # ... # `other_interface` changes
128
+ # # position, `some_interface`
129
+ # # will too.
138
130
  #
139
131
  # @return [Fixnum]
140
132
  def y(value = 0, &block)
@@ -14,6 +14,42 @@ module Vedeu
14
14
  include Vedeu::Common
15
15
  include Vedeu::DSL
16
16
 
17
+ class << self
18
+
19
+ # Define actions for keypresses for when specific interfaces are in focus.
20
+ # Unless an interface is specified, the key will be assumed to be global,
21
+ # meaning its action will happen regardless of the interface in focus.
22
+ #
23
+ # @note
24
+ # When defining an interface, there is no need to provide a name since
25
+ # this can be discerned from the interface itself, e.g:
26
+ #
27
+ # Vedeu.interface 'my_interface' do
28
+ # keymap do
29
+ # ...
30
+ #
31
+ # @param name [String] The name of the interface which this keymap relates
32
+ # to.
33
+ # @param block [Proc]
34
+ #
35
+ # @example
36
+ # keymap 'my_interface' do
37
+ # ...
38
+ #
39
+ # @raise [InvalidSyntax] The required block was not given.
40
+ # @return [Keymap]
41
+ def keymap(name, &block)
42
+ # fail InvalidSyntax, 'block not given' unless block_given?
43
+
44
+ # @todo Try to remember why we need to pre-create the keymap in the
45
+ # repository.
46
+ Vedeu::Keymap.new(name).store
47
+
48
+ Vedeu::Keymap.build({ name: name }, &block).store
49
+ end
50
+
51
+ end
52
+
17
53
  # Returns an instance of DSL::Keymap.
18
54
  #
19
55
  # @param model [Keymap]
@@ -34,13 +34,23 @@ module Vedeu
34
34
  #
35
35
  # @param block [Proc]
36
36
  # @raise [InvalidSyntax] The required block was not given.
37
- # @return [Hash]
37
+ # @return [Vedeu::Border]
38
38
  def border(&block)
39
39
  fail InvalidSyntax, 'block not given' unless block_given?
40
40
 
41
- border_attrs = attributes.merge({ enabled: true, interface: model })
41
+ border_attrs = attributes.merge({ enabled: true,
42
+ name: model.name })
42
43
 
43
- model.border = Vedeu::Border.build(border_attrs, &block)
44
+ Vedeu::Border.build(border_attrs, &block).store
45
+ end
46
+
47
+ # Applies the default border to the interface.
48
+ #
49
+ # @return [Vedeu::Border]
50
+ def border!
51
+ border do
52
+ # adds default border
53
+ end
44
54
  end
45
55
 
46
56
  # Set the cursor visibility on an interface.
@@ -69,6 +79,9 @@ module Vedeu
69
79
  Vedeu::Cursor.new({ name: model.name, state: value }).store
70
80
  end
71
81
 
82
+ # Set the cursor to visible for the interface.
83
+ #
84
+ # @return [Vedeu::Cursor]
72
85
  def cursor!
73
86
  cursor(true)
74
87
  end
@@ -114,7 +127,7 @@ module Vedeu
114
127
  def geometry(&block)
115
128
  fail InvalidSyntax, 'block not given' unless block_given?
116
129
 
117
- model.geometry = Vedeu::Geometry.build(attributes, &block)
130
+ Vedeu::Geometry.build({ name: model.name }, &block).store
118
131
  end
119
132
 
120
133
  # Specify a group for an interface. Interfaces of the same group can be
@@ -130,6 +143,8 @@ module Vedeu
130
143
  #
131
144
  # @return [String]
132
145
  def group(value)
146
+ return false unless defined_value?(value)
147
+
133
148
  if defined_value?(model.name)
134
149
  if Vedeu.groups.registered?(value)
135
150
  Vedeu.groups.find(value).add(model.name)
@@ -143,7 +158,7 @@ module Vedeu
143
158
  model.group = value
144
159
  end
145
160
 
146
- # @see Vedeu::Keymap.keymap
161
+ # @see Vedeu::DSL::Keymap.keymap
147
162
  def keymap(name = model.name, &block)
148
163
  Vedeu.keymap(name, &block)
149
164
  end
@@ -22,6 +22,8 @@ module Vedeu
22
22
  @client = client
23
23
  end
24
24
 
25
+ # @param block [Proc]
26
+ # @return []
25
27
  def stream(&block)
26
28
  fail InvalidSyntax, 'block not given' unless block_given?
27
29
 
@@ -2,9 +2,4 @@ require 'vedeu/events/event'
2
2
  require 'vedeu/events/trigger'
3
3
 
4
4
  module Vedeu
5
-
6
- def self.events
7
- @_events ||= Vedeu::Repository.new(Vedeu::Model::Collection)
8
- end
9
-
10
5
  end # Vedeu
@@ -101,6 +101,7 @@ module Vedeu
101
101
  @repository = Vedeu.events
102
102
  end
103
103
 
104
+ # @see Vedeu::Event.bind
104
105
  def bind
105
106
  if repository.registered?(name)
106
107
  collection = repository.find(name)
@@ -117,7 +118,7 @@ module Vedeu
117
118
  end
118
119
 
119
120
  # Triggers the event based on debouncing and throttling conditions.
120
-
121
+ #
121
122
  # @param args [Array]
122
123
  # @return []
123
124
  def trigger(*args)
@@ -38,9 +38,7 @@ module Vedeu
38
38
 
39
39
  collection = repository.find(name)
40
40
 
41
- results = collection.map do |event|
42
- event.trigger(*args)
43
- end
41
+ results = collection.map { |event| event.trigger(*args) }
44
42
 
45
43
  return results.first if results.one?
46
44
 
@@ -1,4 +1,4 @@
1
- require 'vedeu/repositories/repository'
1
+ require 'vedeu/repositories/all'
2
2
  require 'vedeu/input/mapper'
3
3
  require 'vedeu/input/keys'
4
4
  require 'vedeu/input/key'
@@ -7,22 +7,17 @@ require 'vedeu/input/keymap'
7
7
 
8
8
  module Vedeu
9
9
 
10
- extend self
11
-
12
- def keymaps
13
- @_keymaps ||= Vedeu::Repository.new(Vedeu::Keymap)
14
- end
15
-
16
- def_delegators Vedeu::Keymap, :keymap
17
- def_delegators Vedeu::Keymap, :keypress
18
-
19
- Vedeu.keymap('_system_') do |keymap|
10
+ # Define a keymap called '_system_' which will hold some vital keys needed by
11
+ # Vedeu to run effectively.
12
+ Vedeu::DSL::Keymap.keymap('_system_') do |keymap|
20
13
  Vedeu::Configuration.system_keys.each do |label, keypress|
21
14
  keymap.key(keypress) { Vedeu.trigger(("_" + label.to_s + "_").to_sym) }
22
15
  end
23
16
  end
24
17
 
25
- Vedeu.keymap('_global_') do
18
+ # Define a keymap called '_global_' which will respond no matter which
19
+ # interface is in focus.
20
+ Vedeu::DSL::Keymap.keymap('_global_') do
26
21
 
27
22
  end
28
23
 
@@ -12,14 +12,16 @@ module Vedeu
12
12
  member Vedeu::Key
13
13
 
14
14
  attr_accessor :name
15
- attr_reader :repository
16
15
 
17
16
  class << self
18
17
 
18
+ # @param attributes [Hash]
19
+ # @param block [Proc]
19
20
  # @option attributes client []
20
21
  # @option attributes keys []
21
- # @option attributes name []
22
- # @option attributes repository []
22
+ # @option attributes name [String]
23
+ # @option attributes repository [Vedeu::Repository]
24
+ # @return [Vedeu::Keymap]
23
25
  def build(attributes = {}, &block)
24
26
  fail InvalidSyntax, 'block not given' unless block_given?
25
27
 
@@ -32,34 +34,6 @@ module Vedeu
32
34
  model.store
33
35
  end
34
36
 
35
- # Define actions for keypresses for when specific interfaces are in focus.
36
- # Unless an interface is specified, the key will be assumed to be global,
37
- # meaning its action will happen regardless of the interface in focus.
38
- #
39
- # @note
40
- # When defining an interface, there is no need to provide a name since
41
- # this can be discerned from the interface itself, e.g:
42
- #
43
- # Vedeu.interface 'my_interface' do
44
- # keymap do
45
- # ...
46
- #
47
- # @param name [String] The name of the interface which this keymap relates
48
- # to.
49
- # @param block [Proc]
50
- #
51
- # @example
52
- # keymap 'my_interface' do
53
- # ...
54
- #
55
- # @raise [InvalidSyntax] The required block was not given.
56
- # @return [Keymap]
57
- def keymap(name, &block)
58
- new(name).store
59
-
60
- build({ name: name }, &block)
61
- end
62
-
63
37
  private
64
38
 
65
39
  # The default values for a new instance of this class.
@@ -70,7 +44,7 @@ module Vedeu
70
44
  client: nil,
71
45
  keys: [],
72
46
  name: '',
73
- repository: Vedeu.keymaps,
47
+ repository: Vedeu::Keymaps.keymaps,
74
48
  }
75
49
  end
76
50
 
@@ -82,10 +56,11 @@ module Vedeu
82
56
  def initialize(name = '', keys = [], repository = nil)
83
57
  @name = name
84
58
  @keys = keys
85
- @repository = repository || Vedeu.keymaps
59
+ @repository = repository || Vedeu::Keymaps.keymaps
86
60
  end
87
61
 
88
62
  # @param key [Key]
63
+ # @return []
89
64
  def add(key)
90
65
  return false unless valid?(key)
91
66
 
@@ -94,7 +69,7 @@ module Vedeu
94
69
 
95
70
  # @return [Vedeu::Keys]
96
71
  def keys
97
- collection.coerce(@keys, self)
72
+ collection.coerce(@keys, self)
98
73
  end
99
74
 
100
75
  # @param input [String|Symbol]
@@ -119,6 +94,7 @@ module Vedeu
119
94
  private
120
95
 
121
96
  # @param key [Vedeu::Key]
97
+ # @return [Boolean]
122
98
  def valid?(key)
123
99
  return true unless key_defined?(key.input)
124
100
 
@@ -2,6 +2,7 @@ require 'vedeu/models/collection'
2
2
 
3
3
  module Vedeu
4
4
 
5
+ # A collection of {Vedeu::Key} instances.
5
6
  class Keys < Vedeu::Model::Collection
6
7
  end # Keys
7
8
 
@@ -47,11 +47,7 @@ module Vedeu
47
47
  def valid?
48
48
  return false unless key
49
49
 
50
- return false if key_defined?
51
-
52
- return false if global_key?
53
-
54
- return false if system_key?
50
+ return false if key_defined? || global_key? || system_key?
55
51
 
56
52
  true
57
53
  end
@@ -12,6 +12,7 @@ module Vedeu
12
12
 
13
13
  attr_accessor :parent, :name
14
14
 
15
+ # @return [Vedeu::Model::Collection]
15
16
  def self.coerce(collection = [], parent = nil, name = nil)
16
17
  if collection.kind_of?(Vedeu::Model::Collection)
17
18
  collection
@@ -25,6 +26,7 @@ module Vedeu
25
26
  end
26
27
  end
27
28
 
29
+ # @return [Vedeu::Model::Collection]
28
30
  def initialize(collection = [], parent = nil, name = nil)
29
31
  @collection = collection
30
32
  @parent = parent
@@ -41,10 +43,12 @@ module Vedeu
41
43
  end
42
44
  alias_method :<<, :add
43
45
 
46
+ # @return [Array]
44
47
  def all
45
48
  @collection
46
49
  end
47
50
 
51
+ # @return [Enumerator]
48
52
  def each(&block)
49
53
  @collection.each(&block)
50
54
  end