vedeu 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vedeu.rb +1 -1
  3. data/lib/vedeu/all.rb +2 -0
  4. data/lib/vedeu/buffers/buffer.rb +0 -11
  5. data/lib/vedeu/configuration/api.rb +4 -6
  6. data/lib/vedeu/configuration/cli.rb +1 -3
  7. data/lib/vedeu/configuration/configuration.rb +15 -0
  8. data/lib/vedeu/cursor/cursor.rb +2 -9
  9. data/lib/vedeu/cursor/move_cursor.rb +7 -9
  10. data/lib/vedeu/cursor/toggle_cursor.rb +2 -2
  11. data/lib/vedeu/debug.rb +3 -0
  12. data/lib/vedeu/distributed/test_application.rb +4 -8
  13. data/lib/vedeu/dsl/components/keymap.rb +1 -3
  14. data/lib/vedeu/dsl/composition.rb +2 -2
  15. data/lib/vedeu/dsl/interface.rb +2 -2
  16. data/lib/vedeu/dsl/shared/text.rb +2 -2
  17. data/lib/vedeu/events/event.rb +1 -1
  18. data/lib/vedeu/geometry/all.rb +10 -0
  19. data/lib/vedeu/{support → geometry}/bounding_area.rb +1 -0
  20. data/lib/vedeu/{support → geometry}/content_geometry.rb +0 -7
  21. data/lib/vedeu/{support → geometry}/coordinate.rb +0 -14
  22. data/lib/vedeu/{support → geometry}/grid.rb +0 -0
  23. data/lib/vedeu/{support → geometry}/limit.rb +0 -0
  24. data/lib/vedeu/{support → geometry}/position.rb +3 -5
  25. data/lib/vedeu/{support → geometry}/position_validator.rb +2 -0
  26. data/lib/vedeu/input/input.rb +1 -1
  27. data/lib/vedeu/input/key.rb +0 -13
  28. data/lib/vedeu/input/keymap.rb +1 -1
  29. data/lib/vedeu/models/focus.rb +2 -2
  30. data/lib/vedeu/models/geometry.rb +4 -51
  31. data/lib/vedeu/models/menu.rb +1 -1
  32. data/lib/vedeu/models/model.rb +1 -1
  33. data/lib/vedeu/models/view/char.rb +2 -9
  34. data/lib/vedeu/models/view/composition.rb +3 -10
  35. data/lib/vedeu/models/view/interface.rb +5 -13
  36. data/lib/vedeu/models/view/line.rb +3 -10
  37. data/lib/vedeu/models/view/stream.rb +18 -11
  38. data/lib/vedeu/output/background.rb +6 -21
  39. data/lib/vedeu/output/border.rb +26 -17
  40. data/lib/vedeu/output/colour.rb +1 -1
  41. data/lib/vedeu/output/foreground.rb +6 -21
  42. data/lib/vedeu/output/html_renderer.rb +3 -9
  43. data/lib/vedeu/output/output.rb +38 -11
  44. data/lib/vedeu/output/style.rb +1 -1
  45. data/lib/vedeu/output/translator.rb +45 -15
  46. data/lib/vedeu/output/viewport.rb +1 -1
  47. data/lib/vedeu/output/virtual_buffer.rb +2 -2
  48. data/lib/vedeu/output/wordwrap.rb +1 -1
  49. data/lib/vedeu/repositories/all.rb +9 -9
  50. data/lib/vedeu/repositories/repository.rb +0 -7
  51. data/lib/vedeu/support/all.rb +1 -7
  52. data/lib/vedeu/support/esc.rb +33 -11
  53. data/lib/vedeu/support/template.rb +39 -0
  54. data/lib/vedeu/support/terminal.rb +3 -3
  55. data/lib/vedeu/support/text.rb +1 -1
  56. data/lib/vedeu/support/trace.rb +4 -4
  57. data/lib/vedeu/support/visible.rb +2 -7
  58. data/test/lib/vedeu/buffers/buffer_test.rb +0 -6
  59. data/test/lib/vedeu/cursor/cursor_test.rb +0 -6
  60. data/test/lib/vedeu/{support → geometry}/bounding_area_test.rb +0 -0
  61. data/test/lib/vedeu/{support → geometry}/content_geometry_test.rb +0 -6
  62. data/test/lib/vedeu/{support → geometry}/coordinate_test.rb +0 -8
  63. data/test/lib/vedeu/{support → geometry}/grid_test.rb +0 -0
  64. data/test/lib/vedeu/{support → geometry}/limit_test.rb +0 -0
  65. data/test/lib/vedeu/{support → geometry}/position_test.rb +8 -6
  66. data/test/lib/vedeu/{support → geometry}/position_validator_test.rb +0 -0
  67. data/test/lib/vedeu/input/key_test.rb +0 -12
  68. data/test/lib/vedeu/models/geometry_test.rb +0 -47
  69. data/test/lib/vedeu/models/view/char_test.rb +5 -9
  70. data/test/lib/vedeu/models/view/composition_test.rb +2 -8
  71. data/test/lib/vedeu/models/view/interface_test.rb +2 -8
  72. data/test/lib/vedeu/models/view/line_test.rb +0 -6
  73. data/test/lib/vedeu/models/view/stream_test.rb +0 -6
  74. data/test/lib/vedeu/output/border_test.rb +2 -2
  75. data/test/lib/vedeu/output/html_renderer_test.rb +0 -1
  76. data/test/lib/vedeu/output/output_test.rb +39 -0
  77. data/test/lib/vedeu/repositories/repository_test.rb +0 -6
  78. data/test/lib/vedeu/support/template_test.rb +24 -0
  79. data/test/lib/vedeu/support/visible_test.rb +0 -6
  80. data/test/support/helpers/model_test_class.rb +1 -1
  81. data/vedeu.gemspec +1 -1
  82. metadata +27 -23
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 12b0fae6d703370299d64a60380bda994664cf33
4
- data.tar.gz: fb74af1f981c87f9bc09df39f5b111c24e4b42b3
3
+ metadata.gz: 194c0ec69e43bc4197b9cbd3be152b8be8c66ca5
4
+ data.tar.gz: 58b06a162a3b038247f82d69714e0a8cc601a38d
5
5
  SHA512:
6
- metadata.gz: 861586738502f76491398375e341d13e6ac35d90d0a04d229760e654ef00fbf3a00d64dea83915fc6c6d9d7d941abf8b013b14eeb6b9e7ccf84c7f0e72c7610e
7
- data.tar.gz: cab8c0a2fe8d6fa5612e44199986d24c22b60719568a83aba280ec3a02951049141b507c5fabd9d12c1051e0dda432f3231386741cde6d470da5474e86763d7d
6
+ metadata.gz: 6438bc4ad946856c2a3f552e8256c9aeb05413d3f8d5d1a055a27fc7d7b88c08eeb1dbbf4d30c7aebd59852cb70b524d868dbbf89742eb64b3694acf41eb34c2
7
+ data.tar.gz: 8ff06714885c53271469daaa1a0b09825ad2aa1829090e66100c3820f03a7d7d3cca1a72d851f4512f57ea11217401389ecb1b2c9cf02cd586a1dfde18cf6673
data/lib/vedeu.rb CHANGED
@@ -23,7 +23,7 @@ module Vedeu
23
23
 
24
24
  # @return [Vedeu::Focus]
25
25
  def self.focusable
26
- @_focusable ||= Vedeu::Focus
26
+ @focusable ||= Vedeu::Focus
27
27
  end
28
28
 
29
29
  # When Vedeu is included within one of your classes, you should have all
data/lib/vedeu/all.rb CHANGED
@@ -7,6 +7,8 @@ require 'vedeu/exceptions'
7
7
 
8
8
  require 'vedeu/repositories/all'
9
9
 
10
+ require 'vedeu/geometry/all'
11
+
10
12
  require 'vedeu/api'
11
13
  require 'vedeu/bindings'
12
14
 
@@ -38,17 +38,6 @@ module Vedeu
38
38
  @repository = repository || Vedeu.buffers
39
39
  end
40
40
 
41
- # Returns log friendly output.
42
- #
43
- # @return [String]
44
- def inspect
45
- "<#{self.class.name} ( " \
46
- "back?:#{content_for?(:back)} " \
47
- "front?:#{content_for?(:front)} " \
48
- "previous?:#{content_for?(:previous)} " \
49
- ")>"
50
- end
51
-
52
41
  # Add the content to the back buffer, then update the repository. Returns
53
42
  # boolean indicating that the repository was updated.
54
43
  #
@@ -40,12 +40,10 @@ module Vedeu
40
40
  # @return [Hash]
41
41
  def configuration
42
42
  options.merge!({
43
- system_keys: Configuration.default_system_keys.merge(system_keys)
43
+ system_keys: Configuration.default_system_keys.merge!(system_keys)
44
44
  }) if system_keys.any?
45
45
 
46
- options.each do |option, value|
47
- Vedeu.log(type: :config, message: "API #{option.to_s}: #{value.to_s}")
48
- end
46
+ Vedeu::Config.log('API', options)
49
47
  end
50
48
 
51
49
  # Sets boolean to allow user input. The default behaviour of Vedeu is to
@@ -389,7 +387,7 @@ module Vedeu
389
387
  #
390
388
  # @return [Hash]
391
389
  def options
392
- @_options ||= {}
390
+ @options ||= {}
393
391
  end
394
392
 
395
393
  # Returns the system keys set via the configuration API DSL or an empty
@@ -397,7 +395,7 @@ module Vedeu
397
395
  #
398
396
  # @return [Hash]
399
397
  def system_keys
400
- @_system_keys ||= {}
398
+ @system_keys ||= {}
401
399
  end
402
400
 
403
401
  # Checks that the value provided to {#colour_mode} is valid.
@@ -121,9 +121,7 @@ module Vedeu
121
121
 
122
122
  parser.parse!(args)
123
123
 
124
- options.each do |option, value|
125
- Vedeu.log(type: :config, message: "CLI #{option.to_s}: #{value.to_s}")
126
- end
124
+ Vedeu::Config.log('CLI', options)
127
125
  end
128
126
 
129
127
  private
@@ -8,6 +8,21 @@ module Vedeu
8
8
  # Namespace for the API configuration and CLI configuration classes.
9
9
  #
10
10
  module Config
11
+
12
+ extend self
13
+
14
+ # Custom log for configuration.
15
+ #
16
+ # @param from [String] Which configuration set the options ('API' or 'CLI').
17
+ # @param options [Hash] The configuration options set.
18
+ # @return [Hash] The options param.
19
+ def log(from, options)
20
+ options.each do |option, value|
21
+ Vedeu.log(type: :config,
22
+ message: "#{from} #{option.to_s}: #{value.to_s}")
23
+ end
24
+ end
25
+
11
26
  end
12
27
 
13
28
  # Allows the customisation of Vedeu's behaviour through the configuration API
@@ -1,6 +1,6 @@
1
1
  require 'vedeu/cursor/all'
2
2
  require 'vedeu/models/model'
3
- require 'vedeu/support/position'
3
+ require 'vedeu/geometry/position'
4
4
  require 'vedeu/support/visible'
5
5
 
6
6
  module Vedeu
@@ -41,7 +41,7 @@ module Vedeu
41
41
  attributes = { name: attributes }
42
42
  end
43
43
 
44
- @attributes = defaults.merge(attributes)
44
+ @attributes = defaults.merge!(attributes)
45
45
 
46
46
  @name = @attributes.fetch(:name)
47
47
  @ox = @attributes.fetch(:ox)
@@ -54,13 +54,6 @@ module Vedeu
54
54
  @position = Vedeu::Position.new(@y, @x)
55
55
  end
56
56
 
57
- # Returns log friendly output.
58
- #
59
- # @return [String]
60
- def inspect
61
- "<#{self.class.name} (#{@name}: x:#{@x} y:#{@y} ox:#{@ox} oy:#{@oy})>"
62
- end
63
-
64
57
  # Returns an escape sequence to position the cursor and set its visibility.
65
58
  # When passed a block, will position the cursor, yield and return the
66
59
  # original position.
@@ -1,6 +1,6 @@
1
1
  require 'vedeu/cursor/cursor'
2
- require 'vedeu/support/coordinate'
3
- require 'vedeu/support/position_validator'
2
+ require 'vedeu/geometry/coordinate'
3
+ require 'vedeu/geometry/position_validator'
4
4
 
5
5
  module Vedeu
6
6
 
@@ -17,19 +17,17 @@ module Vedeu
17
17
  def_delegators :geometry, :left,
18
18
  :top,
19
19
  :height,
20
- :width,
21
- :x,
22
- :y
20
+ :width
23
21
 
24
22
  # @param cursor [Cursor]
25
23
  # @param interface [Interface]
26
24
  # @param dy [Fixnum] Move up (-1), or down (1), or no action (0).
27
25
  # @param dx [Fixnum] Move left (-1), or right (1), or no action (0).
28
26
  # @return [MoveCursor]
29
- def initialize(cursor, interface, dy, dx)
27
+ def initialize(cursor, interface, dy = 0, dx = 0)
30
28
  @cursor = cursor
31
- @dy = dy
32
- @dx = dx
29
+ @dy = dy || 0
30
+ @dx = dx || 0
33
31
  @interface = interface
34
32
  end
35
33
 
@@ -76,7 +74,7 @@ module Vedeu
76
74
  #
77
75
  # @return [Cursor]
78
76
  def move
79
- Cursor.new(cursor.attributes.merge(moved_attributes)).store
77
+ Cursor.new(cursor.attributes.merge!(moved_attributes)).store
80
78
  end
81
79
 
82
80
  private
@@ -34,14 +34,14 @@ module Vedeu
34
34
  #
35
35
  # @return [Cursor]
36
36
  def hide
37
- cursor.class.new(cursor.attributes.merge({ state: false })).store
37
+ cursor.class.new(cursor.attributes.merge!({ state: false })).store
38
38
  end
39
39
 
40
40
  # Shows the cursor.
41
41
  #
42
42
  # @return [Cursor]
43
43
  def show
44
- cursor.class.new(cursor.attributes.merge({ state: true })).store
44
+ cursor.class.new(cursor.attributes.merge!({ state: true })).store
45
45
  end
46
46
 
47
47
  private
data/lib/vedeu/debug.rb CHANGED
@@ -17,6 +17,9 @@ module Vedeu
17
17
 
18
18
  File.open('/tmp/' + filename, 'w') do |file|
19
19
  RubyProf::CallStackPrinter.new(result).print(file)
20
+
21
+ # Used with QTCacheGrind to analyse performance.
22
+ # RubyProf::CallTreePrinter.new(result).print(file)
20
23
  end
21
24
  end
22
25
 
@@ -1,5 +1,3 @@
1
- require 'erb'
2
-
3
1
  module Vedeu
4
2
 
5
3
  # Create a test application as a string.
@@ -45,7 +43,7 @@ module Vedeu
45
43
  # @option attributes views [String]
46
44
  # @return [TestApplication]
47
45
  def initialize(attributes = {})
48
- @attributes = defaults.merge(attributes)
46
+ @attributes = defaults.merge!(attributes)
49
47
 
50
48
  @attributes.each do |k, v|
51
49
  instance_variable_set("@#{k.to_s}", @attributes[k])
@@ -57,9 +55,7 @@ module Vedeu
57
55
  def build(&block)
58
56
  self.instance_eval(&block) if block_given?
59
57
 
60
- @object = self
61
-
62
- ERB.new(application, nil, '-').result(binding)
58
+ Template.parse(self, template)
63
59
  end
64
60
 
65
61
  # @return [String]
@@ -70,8 +66,8 @@ module Vedeu
70
66
  private
71
67
 
72
68
  # @return [String]
73
- def application
74
- @application ||= read('default_application.vedeu')
69
+ def template
70
+ File.dirname(__FILE__) + '/templates/default_application.vedeu'
75
71
  end
76
72
 
77
73
  # @todo Don't like all this file reading.
@@ -92,9 +92,7 @@ module Vedeu
92
92
  fail InvalidSyntax, 'An invalid value for `key` was encountered.'
93
93
  end
94
94
 
95
- unless model.key_defined?(value)
96
- model.add(model.member.build(value, &block))
97
- end
95
+ model.add(model.member.new(value, &block))
98
96
  end
99
97
  end
100
98
 
@@ -38,10 +38,10 @@ module Vedeu
38
38
 
39
39
  new_member = if Vedeu.interfaces.registered?(name)
40
40
  existing_member = Vedeu.interfaces.find(name)
41
- model.member.build(attributes.merge(existing_member.attributes), &block)
41
+ model.member.build(attributes.merge!(existing_member.attributes), &block)
42
42
 
43
43
  else
44
- model.member.build(attributes.merge({ name: name }), &block)
44
+ model.member.build(attributes.merge!({ name: name }), &block)
45
45
 
46
46
  end
47
47
 
@@ -39,8 +39,8 @@ module Vedeu
39
39
  def border(&block)
40
40
  fail InvalidSyntax, 'block not given' unless block_given?
41
41
 
42
- border_attrs = attributes.merge({ enabled: true,
43
- name: model.name })
42
+ border_attrs = attributes.merge!({ enabled: true,
43
+ name: model.name })
44
44
 
45
45
  Vedeu::Border.build(border_attrs, &block).store
46
46
  end
@@ -54,7 +54,7 @@ module Vedeu
54
54
  # than the specified width.
55
55
  # @return [String]
56
56
  def text(value = '', options = {})
57
- output = Vedeu::Text.with(value, options.merge({ anchor: __callee__ }))
57
+ output = Vedeu::Text.with(value, options.merge!({ anchor: __callee__ }))
58
58
 
59
59
  content = if model.is_a?(Vedeu::Interface)
60
60
  stream = stream_builder({ value: output })
@@ -94,7 +94,7 @@ module Vedeu
94
94
  colour: model.colour,
95
95
  parent: model,
96
96
  style: model.style,
97
- }.merge(attrs)
97
+ }.merge!(attrs)
98
98
  end
99
99
 
100
100
  end # Text
@@ -278,7 +278,7 @@ module Vedeu
278
278
  #
279
279
  # @return [Hash]
280
280
  def options
281
- defaults.merge(@options)
281
+ defaults.merge!(@options)
282
282
  end
283
283
 
284
284
  # The default values for a new instance of this class.
@@ -0,0 +1,10 @@
1
+ require 'vedeu/geometry/bounding_area'
2
+ require 'vedeu/geometry/content_geometry'
3
+ require 'vedeu/geometry/coordinate'
4
+ require 'vedeu/geometry/grid'
5
+ require 'vedeu/geometry/limit'
6
+ require 'vedeu/geometry/position'
7
+ require 'vedeu/geometry/position_validator'
8
+
9
+ module Vedeu
10
+ end # Vedeu
@@ -1,6 +1,7 @@
1
1
  module Vedeu
2
2
 
3
3
  # Provides coordinates based on the height and width provided.
4
+ # Coordinates always start from 1, 1.
4
5
  #
5
6
  class BoundingArea
6
7
 
@@ -23,13 +23,6 @@ module Vedeu
23
23
  @interface = interface
24
24
  end
25
25
 
26
- # Returns log friendly output.
27
- #
28
- # @return [String]
29
- def inspect
30
- "<#{self.class.name} (y:#{y} x:#{x} yn:#{yn} xn:#{xn})>"
31
- end
32
-
33
26
  # Returns the height of the content, or when no content, the visible height
34
27
  # of the interface.
35
28
  #
@@ -21,20 +21,6 @@ module Vedeu
21
21
  @y = y
22
22
  end
23
23
 
24
- # Returns log friendly output.
25
- #
26
- # @return [String]
27
- def inspect
28
- "<#{self.class.name} ( " \
29
- "height:#{height} " \
30
- "width:#{width} " \
31
- "x:#{x} " \
32
- "xn:#{xn} " \
33
- "y:#{y} " \
34
- "yn:#{yn} " \
35
- ")>"
36
- end
37
-
38
24
  # Returns the maximum y coordinate for an area.
39
25
  #
40
26
  # @example
File without changes
File without changes
@@ -21,6 +21,9 @@ module Vedeu
21
21
  elsif value.is_a?(Array)
22
22
  new(*value)
23
23
 
24
+ elsif value.is_a?(Hash)
25
+ new(value.fetch(:y, 1), value.fetch(:x, 1))
26
+
24
27
  else
25
28
  # not sure how to proceed
26
29
 
@@ -37,11 +40,6 @@ module Vedeu
37
40
  @x = (x.nil? || x < 1) ? 1 : x
38
41
  end
39
42
 
40
- # @return [String]
41
- def inspect
42
- "<#{self.class.name} (y:#{@y} x:#{@x})>"
43
- end
44
-
45
43
  # @param other [Vedeu::Position]
46
44
  # @return [Boolean]
47
45
  def ==(other)
@@ -1,3 +1,5 @@
1
+ require 'vedeu/support/terminal'
2
+
1
3
  module Vedeu
2
4
 
3
5
  # Validates that the provided coordinates are within the terminal and
@@ -40,7 +40,7 @@ module Vedeu
40
40
  #
41
41
  # @return [String]
42
42
  def input
43
- @_input ||= reader.read
43
+ @input ||= reader.read
44
44
  end
45
45
 
46
46
  # Returns the translated (if possible) keypress(es) as either a String or a
@@ -4,19 +4,6 @@ module Vedeu
4
4
  #
5
5
  class Key
6
6
 
7
- class << self
8
-
9
- # Creates a new instance of Key.
10
- #
11
- # @see Vedeu::Key#initialize
12
- def build(input = nil, &block)
13
- fail InvalidSyntax, 'block not given' unless block_given?
14
-
15
- new(input, &block)
16
- end
17
-
18
- end
19
-
20
7
  # Returns a new instance of Key.
21
8
  #
22
9
  # @param input [String|Symbol]