vedeu 0.4.44 → 0.4.45

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/README.md +3 -2
  4. data/Rakefile +0 -6
  5. data/docs/api.md +56 -53
  6. data/docs/applications.md +1 -1
  7. data/docs/dsl.md +2 -0
  8. data/docs/getting_started.md +1 -1
  9. data/docs/object_graph.md +1 -1
  10. data/docs/views.md +1 -1
  11. data/lib/vedeu.rb +4 -0
  12. data/lib/vedeu/api.rb +75 -13
  13. data/lib/vedeu/application/application_view.rb +3 -0
  14. data/lib/vedeu/application/controller.rb +13 -0
  15. data/lib/vedeu/bootstrap.rb +11 -0
  16. data/lib/vedeu/buffers/buffer.rb +2 -0
  17. data/lib/vedeu/configuration/api.rb +1 -15
  18. data/lib/vedeu/configuration/configuration.rb +1 -0
  19. data/lib/vedeu/cursor/cursor.rb +2 -0
  20. data/lib/vedeu/geometry/dimension.rb +2 -0
  21. data/lib/vedeu/geometry/geometry.rb +4 -0
  22. data/lib/vedeu/input/keymap.rb +2 -0
  23. data/lib/vedeu/launcher.rb +14 -0
  24. data/lib/vedeu/main_loop.rb +2 -0
  25. data/lib/vedeu/models/cell.rb +2 -0
  26. data/lib/vedeu/models/char.rb +2 -0
  27. data/lib/vedeu/models/escape_char.rb +2 -0
  28. data/lib/vedeu/models/group.rb +2 -0
  29. data/lib/vedeu/output/clear.rb +2 -0
  30. data/lib/vedeu/output/esc.rb +8 -16
  31. data/lib/vedeu/output/render_border.rb +43 -19
  32. data/lib/vedeu/output/renderers/file.rb +2 -0
  33. data/lib/vedeu/output/wordwrap.rb +2 -0
  34. data/lib/vedeu/repositories/repositories/backgrounds.rb +1 -3
  35. data/lib/vedeu/repositories/repositories/borders.rb +0 -4
  36. data/lib/vedeu/repositories/repositories/buffers.rb +0 -4
  37. data/lib/vedeu/repositories/repositories/cursors.rb +1 -7
  38. data/lib/vedeu/repositories/repositories/events.rb +0 -4
  39. data/lib/vedeu/repositories/repositories/foregrounds.rb +1 -3
  40. data/lib/vedeu/repositories/repositories/geometries.rb +0 -4
  41. data/lib/vedeu/repositories/repositories/groups.rb +0 -4
  42. data/lib/vedeu/repositories/repositories/interfaces.rb +0 -4
  43. data/lib/vedeu/repositories/repositories/keymaps.rb +0 -4
  44. data/lib/vedeu/repositories/repositories/menus.rb +0 -4
  45. data/lib/vedeu/repositories/repository.rb +6 -0
  46. data/lib/vedeu/templating/directive.rb +3 -0
  47. data/lib/vedeu/traps.rb +2 -0
  48. data/lib/vedeu/version.rb +1 -1
  49. data/test/lib/vedeu/cli/generator/helpers_test.rb +33 -1
  50. data/test/lib/vedeu/distributed/client_test.rb +10 -0
  51. data/test/lib/vedeu/output/text_test.rb +18 -12
  52. data/test/lib/vedeu/repositories/repository_test.rb +11 -2
  53. data/test/support/helpers/model_test_class.rb +2 -0
  54. data/test/test_helper.rb +7 -2
  55. data/vedeu.gemspec +2 -3
  56. metadata +5 -21
  57. data/inch.yml +0 -5
  58. data/logs/.gitkeep +0 -0
@@ -6,12 +6,14 @@ module Vedeu
6
6
  # Vedeu with this data, then starts the client application.
7
7
  class Bootstrap
8
8
 
9
+ # :nocov:
9
10
  # @param argv [Array<String>]
10
11
  # @param entry_point [void]
11
12
  # @return [void]
12
13
  def self.start(argv = ARGV, entry_point = nil)
13
14
  new(argv, entry_point).start
14
15
  end
16
+ # :nocov:
15
17
 
16
18
  # Returns a new instance of Vedeu::Bootstrap.
17
19
  #
@@ -23,6 +25,10 @@ module Vedeu
23
25
  @entry_point = entry_point
24
26
  end
25
27
 
28
+ # Loads all of the client application files so that Vedeu has access to
29
+ # them, calls the 'entry_point' controller, ready to start the application,
30
+ # then launches the client application.
31
+ #
26
32
  # @return [void]
27
33
  def start
28
34
  Vedeu.configure { log('/tmp/vedeu_bootstrap.log') }
@@ -57,6 +63,8 @@ module Vedeu
57
63
 
58
64
  private
59
65
 
66
+ # Load each of the loadable files.
67
+ #
60
68
  # @param path [String]
61
69
  # @return [String]
62
70
  def load(path)
@@ -65,6 +73,9 @@ module Vedeu
65
73
  path
66
74
  end
67
75
 
76
+ # Collect each of the files from the client application directories by path
77
+ # excluding '.' and '..' and only loading files with the '.rb' extension.
78
+ #
68
79
  # @param path [String]
69
80
  # @return [Array<String>]
70
81
  def loadables(path)
@@ -217,6 +217,8 @@ module Vedeu
217
217
  @clear_buffer ||= Vedeu::Clear.new(view).clear
218
218
  end
219
219
 
220
+ # Returns the default options/attributes for this class.
221
+ #
220
222
  # @return [Hash<Symbol => NilClass, String>]
221
223
  def defaults
222
224
  {
@@ -281,7 +281,7 @@ module Vedeu
281
281
  # other resources). By default the base path is just cwd but this will
282
282
  # not work for many applications.
283
283
  #
284
- # @param value [String]
284
+ # @param path [String]
285
285
  # @return [String]
286
286
  def base_path(path = nil)
287
287
  options[:base_path] = path
@@ -347,20 +347,6 @@ module Vedeu
347
347
  value.is_a?(Fixnum) && [8, 16, 256, 16_777_216].include?(value)
348
348
  end
349
349
 
350
- # Checks that the value provided to {#exit_key}, {#focus_next_key},
351
- # {#focus_prev_key} and {#mode_switch_key} is valid. Must be a Symbol or a
352
- # non-empty String.
353
- #
354
- # @param value [String|Symbol]
355
- # @return [Boolean]
356
- def valid_key?(value)
357
- return false unless value.is_a?(String) || value.is_a?(Symbol)
358
-
359
- return false if value.is_a?(String) && value.size != 1
360
-
361
- (value.is_a?(String) || value.is_a?(Symbol)) && present?(value)
362
- end
363
-
364
350
  end # API
365
351
 
366
352
  end # Config
@@ -280,6 +280,7 @@ module Vedeu
280
280
  end
281
281
  end
282
282
 
283
+ # @return [String]
283
284
  def set_base_path
284
285
  File.expand_path('.')
285
286
  end
@@ -66,6 +66,8 @@ module Vedeu
66
66
  @position = Vedeu::Position.new(@y, @x)
67
67
  end
68
68
 
69
+ # Override Ruby's Object#inspect method to provide a more helpful output.
70
+ #
69
71
  # @return [String]
70
72
  def inspect
71
73
  "<Vedeu::Cursor (#{name}, " \
@@ -143,6 +143,8 @@ module Vedeu
143
143
  defaults.merge!(@options)
144
144
  end
145
145
 
146
+ # Returns the default options/attributes for this class.
147
+ #
146
148
  # @return [Hash<Symbol => Boolean>]
147
149
  def defaults
148
150
  {
@@ -92,6 +92,8 @@ module Vedeu
92
92
  @attributes.each { |key, value| instance_variable_set("@#{key}", value) }
93
93
  end
94
94
 
95
+ # Override Ruby's Object#inspect method to provide a more helpful output.
96
+ #
95
97
  # @return [String]
96
98
  def inspect
97
99
  '<Vedeu::Geometry ' \
@@ -198,6 +200,8 @@ module Vedeu
198
200
  @xn.is_a?(Proc) ? @xn.call : @xn
199
201
  end
200
202
 
203
+ # Returns the default options/attributes for this class.
204
+ #
201
205
  # @return [Hash]
202
206
  def defaults
203
207
  {
@@ -72,6 +72,8 @@ module Vedeu
72
72
 
73
73
  private
74
74
 
75
+ # Returns the default options/attributes for this class.
76
+ #
75
77
  # @return [Hash]
76
78
  def defaults
77
79
  {
@@ -13,6 +13,7 @@ module Vedeu
13
13
  # error occurred (1).
14
14
  attr_reader :exit_code
15
15
 
16
+ # :nocov:
16
17
  # @param (see #initialize)
17
18
  def self.execute!(argv = [],
18
19
  stdin = STDIN,
@@ -21,6 +22,7 @@ module Vedeu
21
22
  kernel = Kernel)
22
23
  new(argv, stdin, stdout, stderr, kernel).debug_execute!
23
24
  end
25
+ # :nocov:
24
26
 
25
27
  # Returns a new instance of Vedeu::Launcher.
26
28
  #
@@ -43,6 +45,11 @@ module Vedeu
43
45
  @exit_code = 1
44
46
  end
45
47
 
48
+ # :nocov:
49
+ # If debugging is enabled, execute the application within the debugging
50
+ # context. At the moment, this simple uses 'ruby-prof' to profile the
51
+ # running application.
52
+ #
46
53
  # @return [void]
47
54
  def debug_execute!
48
55
  if configuration.debug?
@@ -55,7 +62,12 @@ module Vedeu
55
62
 
56
63
  terminate!
57
64
  end
65
+ # :nocov:
58
66
 
67
+ # Alters the STD[IN|OUT|ERR] to those requested by the client application,
68
+ # then starts the application. If an uncaught exception occurs during the
69
+ # application runtime, we exit ungracefully with the error message if any.
70
+ #
59
71
  # @return [void]
60
72
  def execute!
61
73
  $stdin = @stdin
@@ -79,6 +91,7 @@ module Vedeu
79
91
 
80
92
  private
81
93
 
94
+ # :nocov:
82
95
  # Terminates the application after resetting $stdin, $stdout and $stderr.
83
96
  #
84
97
  # @return [void]
@@ -91,6 +104,7 @@ module Vedeu
91
104
 
92
105
  @kernel.exit(exit_code)
93
106
  end
107
+ # :nocov:
94
108
 
95
109
  # Use the arguments passed on the command-line along with those defined by
96
110
  # the client application and Vedeu's defaults to configure the client
@@ -38,6 +38,7 @@ module Vedeu
38
38
  @loop = false
39
39
  end
40
40
 
41
+ # :nocov:
41
42
  # Check the application has started and we wish to continue running.
42
43
  #
43
44
  # @raise [VedeuInterrupt] When we wish to terminate the running
@@ -46,6 +47,7 @@ module Vedeu
46
47
  def safe_exit_point!
47
48
  fail VedeuInterrupt if @started && !@loop
48
49
  end
50
+ # :nocov:
49
51
 
50
52
  end
51
53
 
@@ -54,6 +54,8 @@ module Vedeu
54
54
 
55
55
  private
56
56
 
57
+ # Returns the default options/attributes for this class.
58
+ #
57
59
  # @return [Hash<Symbol => void>]
58
60
  def defaults
59
61
  {
@@ -72,6 +72,8 @@ module Vedeu
72
72
  end
73
73
  alias_method :==, :eql?
74
74
 
75
+ # Override Ruby's Object#inspect method to provide a more helpful output.
76
+ #
75
77
  # @return [String]
76
78
  def inspect
77
79
  "<Vedeu::Char '#{Vedeu::Esc.escape(to_s)}'>"
@@ -33,6 +33,8 @@ module Vedeu
33
33
  end
34
34
  alias_method :==, :eql?
35
35
 
36
+ # Override Ruby's Object#inspect method to provide a more helpful output.
37
+ #
36
38
  # @return [String]
37
39
  def inspect
38
40
  "<Vedeu::EscapeChar '#{Vedeu::Esc.escape(to_s)}'>"
@@ -65,6 +65,8 @@ module Vedeu
65
65
 
66
66
  private
67
67
 
68
+ # Returns the default options/attributes for this class.
69
+ #
68
70
  # @return [Hash]
69
71
  def defaults
70
72
  {
@@ -137,6 +137,8 @@ module Vedeu
137
137
  end
138
138
  end
139
139
 
140
+ # Returns the default options/attributes for this class.
141
+ #
140
142
  # @return [Hash<Symbol => Boolean>]
141
143
  def defaults
142
144
  {
@@ -122,11 +122,9 @@ module Vedeu
122
122
  # @param value [String|Symbol]
123
123
  # @return [String]
124
124
  def string(value = '')
125
- name = value.to_sym
125
+ return '' if value.empty?
126
126
 
127
- return '' if name.empty?
128
-
129
- send(name)
127
+ send(value.to_sym)
130
128
 
131
129
  rescue NoMethodError
132
130
  ''
@@ -155,11 +153,6 @@ module Vedeu
155
153
  [colour_reset, "\e[2K"].join
156
154
  end
157
155
 
158
- # @return [String]
159
- def clear_last_line
160
- Vedeu::Position.new((Vedeu::Terminal.height - 1), 1).to_s { clear_line }
161
- end
162
-
163
156
  # @return [String]
164
157
  def colour_reset
165
158
  [fg_reset, bg_reset].join
@@ -177,13 +170,12 @@ module Vedeu
177
170
 
178
171
  # @return [String]
179
172
  def screen_exit
180
- [
181
- show_cursor,
182
- colour_reset,
183
- reset,
184
- Vedeu::Position.new(Vedeu.height, Vedeu.width).to_s,
185
- "\n",
186
- ].join
173
+ [show_cursor, colour_reset, reset, last_character_position, "\n"].join
174
+ end
175
+
176
+ # @return [String]
177
+ def last_character_position
178
+ Vedeu::Position.new(Vedeu.height, Vedeu.width).to_s
187
179
  end
188
180
 
189
181
  end # Esc
@@ -92,17 +92,43 @@ module Vedeu
92
92
  border: type)
93
93
  end
94
94
 
95
+ # @return [Array<Vedeu::Char>]
96
+ def build_bottom_horizontal
97
+ horizontal_border(:bottom_horizontal, yn)
98
+ end
99
+
100
+ # @return [Vedeu::Char]
101
+ def build_bottom_left
102
+ build(bottom_left, :bottom_left, *[yn, x]) if left?
103
+ end
104
+
105
+ # @return [Vedeu::Char]
106
+ def build_bottom_right
107
+ build(bottom_right, :bottom_right, *[yn, xn]) if right?
108
+ end
109
+
110
+ # @return [Array<Vedeu::Char>]
111
+ def build_top_horizontal
112
+ horizontal_border(:top_horizontal, y)
113
+ end
114
+
115
+ # @return [Vedeu::Char]
116
+ def build_top_left
117
+ build(top_left, :top_left, *[y, x]) if left?
118
+ end
119
+
120
+ # @return [Vedeu::Char]
121
+ def build_top_right
122
+ build(top_right, :top_right, *[y, xn]) if right?
123
+ end
124
+
95
125
  # Renders the bottom border for the interface.
96
126
  #
97
127
  # @return [String]
98
128
  def bottom
99
129
  return [] unless bottom?
100
130
 
101
- out = []
102
- out << build(bottom_left, :bottom_left, *[yn, x]) if left?
103
- out << horizontal_border(:bottom_horizontal, yn)
104
- out << build(bottom_right, :bottom_right, *[yn, xn]) if right?
105
- out
131
+ [build_bottom_left, build_bottom_horizontal, build_bottom_right].compact
106
132
  end
107
133
 
108
134
  # @return [Vedeu::Geometry]
@@ -169,12 +195,22 @@ module Vedeu
169
195
  present?(title)
170
196
  end
171
197
 
198
+ # Return boolean indicating whether the title fits within the width of the
199
+ # top border.
200
+ #
201
+ # @return [Boolean]
202
+ def title_fits?
203
+ width > title_characters.size
204
+ end
205
+
172
206
  # From the second element of {#title_characters} remove the border from each
173
207
  # {#horizontal_border} Vedeu::Char, and add the title character.
174
208
  #
175
209
  # @return [Array<Vedeu::Char>]
176
210
  def titlebar
177
- horizontal_border(:top_horizontal, y).each_with_index do |char, index|
211
+ return build_top_horizontal unless title? && title_fits?
212
+
213
+ build_top_horizontal.each_with_index do |char, index|
178
214
  if index >= 1 && index <= title_characters.size
179
215
  char.border = nil
180
216
  char.value = title_characters[(index - 1)]
@@ -198,19 +234,7 @@ module Vedeu
198
234
  def top
199
235
  return [] unless top?
200
236
 
201
- out = []
202
- out << build(top_left, :top_left, *[y, x]) if left?
203
-
204
- if title? && width > title_characters.size
205
- out << titlebar
206
-
207
- else
208
- out << horizontal_border(:top_horizontal, y)
209
-
210
- end
211
-
212
- out << build(top_right, :top_right, *[y, xn]) if right?
213
- out
237
+ [build_top_left, titlebar, build_top_right].compact
214
238
  end
215
239
 
216
240
  # Truncates the title to the width of the interface, minus characters needed
@@ -75,6 +75,8 @@ module Vedeu
75
75
  defaults.merge!(@options)
76
76
  end
77
77
 
78
+ # Returns the default options/attributes for this class.
79
+ #
78
80
  # @return [Hash]
79
81
  def defaults
80
82
  {
@@ -150,6 +150,8 @@ module Vedeu
150
150
  options.fetch(:width)
151
151
  end
152
152
 
153
+ # Returns the default options/attributes for this class.
154
+ #
153
155
  # @return [Hash<Symbol => Fixnum, String, Symbol>]
154
156
  def defaults
155
157
  {
@@ -5,10 +5,8 @@ module Vedeu
5
5
  # @api public
6
6
  class Backgrounds < Colours
7
7
 
8
- # @example
9
- # Vedeu.background_colours
10
- #
11
8
  # @return [Vedeu::Backgrounds]
9
+ # @see Vedeu::Repository
12
10
  def self.background_colours
13
11
  @background_colours ||= new
14
12
  end
@@ -8,10 +8,6 @@ module Vedeu
8
8
 
9
9
  class << self
10
10
 
11
- # @example
12
- # Vedeu.borders
13
- #
14
- # @return [Vedeu::Borders]
15
11
  alias_method :borders, :repository
16
12
 
17
13
  # Remove all stored models from the repository.