vedeu 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +3 -0
  3. data/Rakefile +16 -7
  4. data/examples/borders_app.rb +58 -55
  5. data/lib/vedeu/api.rb +1 -1
  6. data/lib/vedeu/application.rb +25 -25
  7. data/lib/vedeu/bindings.rb +5 -7
  8. data/lib/vedeu/configuration/api.rb +0 -2
  9. data/lib/vedeu/configuration/cli.rb +0 -2
  10. data/lib/vedeu/configuration/configuration.rb +0 -2
  11. data/lib/vedeu/cursor/cursor.rb +0 -2
  12. data/lib/vedeu/debug.rb +2 -2
  13. data/lib/vedeu/distributed/server.rb +0 -2
  14. data/lib/vedeu/dsl/components/border.rb +15 -19
  15. data/lib/vedeu/dsl/components/geometry.rb +14 -18
  16. data/lib/vedeu/dsl/components/keymap.rb +28 -32
  17. data/lib/vedeu/dsl/composition.rb +27 -9
  18. data/lib/vedeu/events/all.rb +1 -0
  19. data/lib/vedeu/events/event.rb +6 -8
  20. data/lib/vedeu/events/events.rb +10 -0
  21. data/lib/vedeu/events/trigger.rb +6 -12
  22. data/lib/vedeu/geometry/grid.rb +0 -2
  23. data/lib/vedeu/geometry/position.rb +0 -2
  24. data/lib/vedeu/geometry/position_validator.rb +0 -14
  25. data/lib/vedeu/input/input.rb +0 -2
  26. data/lib/vedeu/models/collection.rb +0 -2
  27. data/lib/vedeu/models/focus.rb +0 -1
  28. data/lib/vedeu/models/geometry.rb +7 -3
  29. data/lib/vedeu/models/group.rb +0 -2
  30. data/lib/vedeu/models/menu.rb +23 -29
  31. data/lib/vedeu/models/model.rb +0 -2
  32. data/lib/vedeu/models/view/char.rb +14 -10
  33. data/lib/vedeu/models/view/composition.rb +7 -9
  34. data/lib/vedeu/models/view/interface.rb +0 -1
  35. data/lib/vedeu/models/view/line.rb +2 -3
  36. data/lib/vedeu/models/view/stream.rb +0 -3
  37. data/lib/vedeu/output/all.rb +1 -0
  38. data/lib/vedeu/output/background.rb +0 -2
  39. data/lib/vedeu/output/colour.rb +0 -2
  40. data/lib/vedeu/output/compositor.rb +0 -2
  41. data/lib/vedeu/output/foreground.rb +0 -2
  42. data/lib/vedeu/output/html_renderer.rb +6 -0
  43. data/lib/vedeu/output/index_position.rb +35 -0
  44. data/lib/vedeu/output/output.rb +3 -1
  45. data/lib/vedeu/output/position_index.rb +2 -2
  46. data/lib/vedeu/output/presentation.rb +0 -2
  47. data/lib/vedeu/output/style.rb +0 -1
  48. data/lib/vedeu/output/translator.rb +18 -20
  49. data/lib/vedeu/output/viewport.rb +76 -51
  50. data/lib/vedeu/output/virtual_terminal.rb +2 -1
  51. data/lib/vedeu/repositories/all.rb +4 -4
  52. data/lib/vedeu/repositories/repository.rb +0 -2
  53. data/lib/vedeu/support/coercions.rb +0 -2
  54. data/lib/vedeu/support/common.rb +0 -2
  55. data/lib/vedeu/support/esc.rb +0 -2
  56. data/lib/vedeu/support/log.rb +86 -3
  57. data/lib/vedeu/support/refresh.rb +0 -2
  58. data/lib/vedeu/support/sentence.rb +5 -9
  59. data/lib/vedeu/support/terminal.rb +0 -2
  60. data/lib/vedeu/support/trace.rb +0 -2
  61. data/lib/vedeu/support/visible.rb +1 -1
  62. data/test/lib/vedeu/configuration/api_test.rb +14 -0
  63. data/test/lib/vedeu/configuration/configuration_test.rb +10 -0
  64. data/test/lib/vedeu/distributed/server_test.rb +5 -0
  65. data/test/lib/vedeu/dsl/components/border_test.rb +7 -0
  66. data/test/lib/vedeu/dsl/components/geometry_test.rb +8 -3
  67. data/test/lib/vedeu/dsl/interface_test.rb +5 -0
  68. data/test/lib/vedeu/dsl/line_test.rb +4 -0
  69. data/test/lib/vedeu/dsl/shared/colour_test.rb +7 -7
  70. data/test/lib/vedeu/dsl/shared/style_test.rb +5 -2
  71. data/test/lib/vedeu/dsl/stream_test.rb +4 -1
  72. data/test/lib/vedeu/events/event_test.rb +6 -0
  73. data/test/lib/vedeu/geometry/bounding_area_test.rb +30 -30
  74. data/test/lib/vedeu/geometry/position_test.rb +5 -0
  75. data/test/lib/vedeu/models/view/char_test.rb +1 -14
  76. data/test/lib/vedeu/output/index_position_test.rb +64 -0
  77. data/test/lib/vedeu/output/style_test.rb +4 -0
  78. data/test/lib/vedeu/output/translator_test.rb +4 -0
  79. data/test/lib/vedeu/output/virtual_terminal_test.rb +2 -0
  80. data/test/lib/vedeu/output/wordwrap_test.rb +5 -0
  81. data/test/lib/vedeu/repositories/all_test.rb +3 -3
  82. data/test/lib/vedeu/repositories/repository_test.rb +8 -0
  83. data/test/lib/vedeu/support/console_test.rb +14 -0
  84. data/test/lib/vedeu/support/esc_test.rb +6 -0
  85. data/test/lib/vedeu/support/terminal_test.rb +13 -0
  86. data/vedeu.gemspec +4 -4
  87. metadata +12 -24
  88. data/test/integration/distributed_test.rb +0 -16
  89. data/test/integration/dsl/compositions_test.rb +0 -19
  90. data/test/integration/dsl/interfaces_test.rb +0 -193
  91. data/test/integration/dsl/keymaps_test.rb +0 -30
  92. data/test/integration/dsl/lines_test.rb +0 -104
  93. data/test/integration/dsl/menus_test.rb +0 -59
  94. data/test/integration/dsl/streams_test.rb +0 -103
  95. data/test/integration/dsl/views_test.rb +0 -45
@@ -3,8 +3,6 @@ module Vedeu
3
3
  # Interfaces can be associated with one another by being members of the same
4
4
  # Group. A Group is a collection of interface names.
5
5
  #
6
- # @api private
7
- #
8
6
  class Group
9
7
 
10
8
  include Vedeu::Model
@@ -5,8 +5,6 @@ module Vedeu
5
5
  # Converts the collection passed into a list of menu items which can be
6
6
  # navigated using the instance methods or events provided.
7
7
  #
8
- # @api private
9
- #
10
8
  class Menu
11
9
 
12
10
  include Vedeu::Model
@@ -25,34 +23,30 @@ module Vedeu
25
23
  # @return [Fixnum]
26
24
  attr_accessor :selected
27
25
 
28
- class << self
29
-
30
- # Register a menu by name which will display a collection of items for
31
- # your users to select; and provide interactivity within your application.
32
- #
33
- # @param name [String] The name of the menu. Used to reference the
34
- # menu throughout your application's execution lifetime.
35
- # @param block [Proc] A set of attributes which define the features of the
36
- # menu. See {Vedeu::DSL::Menu#items} and {Vedeu::DSL::Menu#name}.
37
- #
38
- # @example
39
- # Vedeu.menu 'my_interface' do
40
- # items [:item_1, :item_2, :item_3]
41
- # ...
42
- #
43
- # Vedeu.menu do
44
- # name 'menus_must_have_a_name'
45
- # items Track.all_my_favourites
46
- # ...
47
- #
48
- # @raise [InvalidSyntax] The required block was not given.
49
- # @return [API::Menu]
50
- def menu(name = '', &block)
51
- fail InvalidSyntax, 'block not given' unless block_given?
52
-
53
- build({ name: name }, &block).store
54
- end
26
+ # Register a menu by name which will display a collection of items for
27
+ # your users to select; and provide interactivity within your application.
28
+ #
29
+ # @param name [String] The name of the menu. Used to reference the
30
+ # menu throughout your application's execution lifetime.
31
+ # @param block [Proc] A set of attributes which define the features of the
32
+ # menu. See {Vedeu::DSL::Menu#items} and {Vedeu::DSL::Menu#name}.
33
+ #
34
+ # @example
35
+ # Vedeu.menu 'my_interface' do
36
+ # items [:item_1, :item_2, :item_3]
37
+ # ...
38
+ #
39
+ # Vedeu.menu do
40
+ # name 'menus_must_have_a_name'
41
+ # items Track.all_my_favourites
42
+ # ...
43
+ #
44
+ # @raise [InvalidSyntax] The required block was not given.
45
+ # @return [API::Menu]
46
+ def self.menu(name = '', &block)
47
+ fail InvalidSyntax, 'block not given' unless block_given?
55
48
 
49
+ build({ name: name }, &block).store
56
50
  end
57
51
 
58
52
  # Returns a new instance of Menu.
@@ -3,8 +3,6 @@ module Vedeu
3
3
  # When included into a class, provides the mechanism to store the class in a
4
4
  # repository for later retrieval.
5
5
  #
6
- # @api private
7
- #
8
6
  module Model
9
7
 
10
8
  attr_reader :repository
@@ -9,15 +9,14 @@ module Vedeu
9
9
  # Though a multi-character String can be passed as a value, only the first
10
10
  # character is returned in the escape sequence.
11
11
  #
12
- # @api private
13
- #
14
12
  class Char
15
13
 
16
14
  include Vedeu::Presentation
17
15
 
18
16
  attr_accessor :border,
19
- :parent,
20
- :position
17
+ :parent
18
+
19
+ attr_reader :value
21
20
 
22
21
  # Returns a new instance of Char.
23
22
  #
@@ -35,7 +34,6 @@ module Vedeu
35
34
  @border = @attributes[:border]
36
35
  @colour = @attributes[:colour]
37
36
  @parent = @attributes[:parent]
38
- @position = Vedeu::Position.coerce(@attributes[:position])
39
37
  @style = @attributes[:style]
40
38
  @value = @attributes[:value]
41
39
  end
@@ -52,11 +50,15 @@ module Vedeu
52
50
  self.class == other.class && value == other.value
53
51
  end
54
52
 
55
- # @return [String] The character.
56
- def value
57
- return '' unless @value
53
+ # @return [Vedeu::Position]
54
+ def position
55
+ @position ||= Vedeu::Position.coerce(attributes[:position])
56
+ end
58
57
 
59
- @value
58
+ # @param value [Vedeu::Position]
59
+ # @return [Vedeu::Position]
60
+ def position=(value)
61
+ @position = Vedeu::Position.coerce(value)
60
62
  end
61
63
 
62
64
  # @return [Fixnum|NilClass]
@@ -76,6 +78,8 @@ module Vedeu
76
78
 
77
79
  private
78
80
 
81
+ attr_reader :attributes
82
+
79
83
  # The default values for a new instance of this class.
80
84
  #
81
85
  # @return [Hash]
@@ -86,7 +90,7 @@ module Vedeu
86
90
  parent: nil,
87
91
  position: nil,
88
92
  style: nil,
89
- value: nil,
93
+ value: '',
90
94
  }
91
95
  end
92
96
 
@@ -10,30 +10,27 @@ module Vedeu
10
10
 
11
11
  # A composition is a collection of interfaces.
12
12
  #
13
- # @api private
14
- #
15
13
  class Composition
16
14
 
17
- include Vedeu::Presentation
18
15
  include Vedeu::Model
16
+ include Vedeu::Presentation
19
17
 
20
18
  collection Vedeu::Interfaces
21
19
  member Vedeu::Interface
22
20
 
23
- attr_reader :interfaces
24
- alias_method :value, :interfaces
25
-
26
21
  # Returns a new instance of Composition.
27
22
  #
28
23
  # @param attributes [Hash]
29
- # @option attributes colour []
24
+ # @option attributes colour [Vedeu::Colour]
30
25
  # @option attributes interfaces []
31
- # @option attributes style []
26
+ # @option attributes style [Vedeu::Style]
32
27
  # @return [Composition]
33
28
  def initialize(attributes = {})
34
29
  @attributes = defaults.merge!(attributes)
35
- @interfaces = @attributes[:interfaces]
30
+
36
31
  @colour = @attributes[:colour]
32
+ @interfaces = @attributes[:interfaces]
33
+ @repository = Vedeu.interfaces
37
34
  @style = @attributes[:style]
38
35
  end
39
36
 
@@ -47,6 +44,7 @@ module Vedeu
47
44
  def interfaces
48
45
  collection.coerce(@interfaces, self)
49
46
  end
47
+ alias_method :value, :interfaces
50
48
 
51
49
  private
52
50
 
@@ -13,7 +13,6 @@ module Vedeu
13
13
  # {Vedeu::Geometry}. It is a container for {Vedeu::Line} and {Vedeu::Stream}
14
14
  # objects.
15
15
  #
16
- # @api private
17
16
  class Interface
18
17
 
19
18
  extend Forwardable
@@ -8,8 +8,6 @@ module Vedeu
8
8
  # {Vedeu::Stream} objects. A line's width is determined by the
9
9
  # {Vedeu::Interface} it belongs to.
10
10
  #
11
- # @api private
12
- #
13
11
  class Line
14
12
 
15
13
  include Vedeu::Model
@@ -25,11 +23,12 @@ module Vedeu
25
23
 
26
24
  # Returns a new instance of Line.
27
25
  #
26
+ # @param attributes [Hash]
28
27
  # @option attributes streams [Vedeu::Streams]
29
28
  # @option attributes parent [Vedeu::Interface]
30
29
  # @option attributes colour [Vedeu::Colour]
31
30
  # @option attributes style [Vedeu::Style]
32
- # @return [Line]
31
+ # @return [Vedeu::Line]
33
32
  def initialize(attributes = {})
34
33
  @attributes = defaults.merge!(attributes)
35
34
  @colour = @attributes[:colour]
@@ -7,8 +7,6 @@ module Vedeu
7
7
  # {Vedeu::Line} which you wish to colour and style independently of the other
8
8
  # characters in that line.
9
9
  #
10
- # @api private
11
- #
12
10
  class Stream
13
11
 
14
12
  include Vedeu::Model
@@ -31,7 +29,6 @@ module Vedeu
31
29
  # @option attributes parent [Vedeu::Line]
32
30
  # @option attributes colour [Vedeu::Colour]
33
31
  # @option attributes style [Vedeu::Style]
34
- # @option attributes client [Object]
35
32
  # @return [Vedeu::Stream]
36
33
  def initialize(attributes = {})
37
34
  @attributes = defaults.merge!(attributes)
@@ -9,6 +9,7 @@ require 'vedeu/output/compositor'
9
9
  require 'vedeu/output/presentation'
10
10
  require 'vedeu/output/style'
11
11
  require 'vedeu/output/position_index'
12
+ require 'vedeu/output/index_position'
12
13
  require 'vedeu/output/virtual_buffer'
13
14
  require 'vedeu/output/html_char'
14
15
  require 'vedeu/output/html_renderer'
@@ -3,8 +3,6 @@ module Vedeu
3
3
  # The class represents one half (the other, can be found at
4
4
  # {Vedeu::Foreground}) of a terminal colour escape sequence.
5
5
  #
6
- # @api private
7
- #
8
6
  class Background < Translator
9
7
 
10
8
  private
@@ -6,8 +6,6 @@ module Vedeu
6
6
  # foreground and background colours of a character or collection of
7
7
  # characters.
8
8
  #
9
- # @api private
10
- #
11
9
  class Colour
12
10
 
13
11
  include Vedeu::Coercions
@@ -9,8 +9,6 @@ module Vedeu
9
9
  # Combines stored interface layout/geometry with an interface view/buffer
10
10
  # to create a single view to be sent to the terminal for output.
11
11
  #
12
- # @api private
13
- #
14
12
  class Compositor
15
13
 
16
14
  # Convenience method to initialize a new Compositor and call its {#compose}
@@ -7,8 +7,6 @@ module Vedeu
7
7
  # The class represents one half (the other, can be found at
8
8
  # {Vedeu::Background}) of a terminal colour escape sequence.
9
9
  #
10
- # @api private
11
- #
12
10
  class Foreground < Translator
13
11
 
14
12
  private
@@ -8,6 +8,12 @@ module Vedeu
8
8
  new(output).render
9
9
  end
10
10
 
11
+ # @param output [Array<Array<Vedeu::Char>>]
12
+ # @return [String]
13
+ def self.to_file(output)
14
+ new(output).to_file
15
+ end
16
+
11
17
  # @param output [Array<Array<Vedeu::Char>>]
12
18
  # @return [Vedeu::HTMLRenderer]
13
19
  def initialize(output)
@@ -0,0 +1,35 @@
1
+ module Vedeu
2
+
3
+ # Converts an index into a position for the terminal.
4
+ #
5
+ class IndexPosition
6
+
7
+ attr_reader :y,
8
+ :x
9
+
10
+ alias_method :first, :y
11
+ alias_method :last, :x
12
+
13
+ # @param y [Fixnum]
14
+ # @param x [Fixnum]
15
+ # @return [Array]
16
+ def self.[](y, x)
17
+ new(y, x).[]
18
+ end
19
+
20
+ # @param y [Fixnum]
21
+ # @param x [Fixnum]
22
+ # @return [Vedeu::IndexPosition]
23
+ def initialize(y, x)
24
+ @y = (y <= 0) ? 1 : (y + 1)
25
+ @x = (x <= 0) ? 1 : (x + 1)
26
+ end
27
+
28
+ # @return [Array]
29
+ def []
30
+ [y, x]
31
+ end
32
+
33
+ end # IndexPosition
34
+
35
+ end # Vedeu
@@ -27,6 +27,8 @@ module Vedeu
27
27
  def render
28
28
  if Vedeu::Configuration.drb?
29
29
  Vedeu.trigger(:_drb_store_output_, virtual_view)
30
+
31
+ HTMLRenderer.to_file(VirtualBuffer.retrieve)
30
32
  end
31
33
 
32
34
  Terminal.output(Renderer.render(virtual_view, interface.cursor))
@@ -73,7 +75,7 @@ module Vedeu
73
75
  viewport.each_with_index do |line, iy|
74
76
  row = []
75
77
  line.each_with_index do |char, ix|
76
- row << if char.is_a?(Vedeu::Char) && char.position.nil?
78
+ row << if char.is_a?(Vedeu::Char) && (char.x != ix || char.y != iy)
77
79
  char.position = origin(iy, ix)
78
80
  char
79
81
 
@@ -21,8 +21,8 @@ module Vedeu
21
21
  # @param x [Fixnum]
22
22
  # @return [Vedeu::PositionIndex]
23
23
  def initialize(y, x)
24
- @y = [(y - 1), 1].max
25
- @x = [(x - 1), 1].max
24
+ @y = ((y - 1) <= 1) ? 1 : (y - 1)
25
+ @x = ((x - 1) <= 1) ? 1 : (x - 1)
26
26
  end
27
27
 
28
28
  # @return [Array]
@@ -3,8 +3,6 @@ module Vedeu
3
3
  # This module allows the sharing of presentation concerns between the models:
4
4
  # Interface, Line and Stream.
5
5
  #
6
- # @api private
7
- #
8
6
  module Presentation
9
7
 
10
8
  # @return [Vedeu::Background|NilClass]
@@ -6,7 +6,6 @@ module Vedeu
6
6
  # Converts the style value or value collection into a terminal escape
7
7
  # sequence. Unrecognised values are discarded- an empty string is returned.
8
8
  #
9
- # @api private
10
9
  class Style
11
10
 
12
11
  include Vedeu::Common
@@ -21,8 +21,6 @@ module Vedeu
21
21
  # a 24-bit representation.
22
22
  #
23
23
  # @todo More documentation required (create a fancy chart!)
24
- # @api private
25
- #
26
24
  class Translator
27
25
 
28
26
  include Vedeu::Coercions
@@ -52,14 +50,14 @@ module Vedeu
52
50
  if no_colour?
53
51
  ''
54
52
 
55
- elsif named?
56
- named
53
+ elsif rgb?
54
+ rgb
57
55
 
58
56
  elsif numbered?
59
57
  numbered
60
58
 
61
- elsif rgb?
62
- rgb
59
+ elsif named?
60
+ named
63
61
 
64
62
  else
65
63
  ''
@@ -124,6 +122,20 @@ module Vedeu
124
122
  [numbered_prefix, css_to_numbered, 'm'].join
125
123
  end
126
124
 
125
+ # Returns a boolean indicated whether the colour is an HTML/CSS colour.
126
+ #
127
+ # @return [Boolean]
128
+ def rgb?
129
+ colour.is_a?(String) && valid_rgb?
130
+ end
131
+
132
+ # Returns a boolean indicated whether the colour is a valid HTML/CSS colour.
133
+ #
134
+ # @return [Boolean]
135
+ def valid_rgb?
136
+ !!(colour =~ /^#([A-Fa-f0-9]{6})$/)
137
+ end
138
+
127
139
  # Returns an escape sequence.
128
140
  #
129
141
  # @return [String]
@@ -145,20 +157,6 @@ module Vedeu
145
157
  colour >= 0 && colour <= 255
146
158
  end
147
159
 
148
- # Returns a boolean indicated whether the colour is an HTML/CSS colour.
149
- #
150
- # @return [Boolean]
151
- def rgb?
152
- colour.is_a?(String) && valid_rgb?
153
- end
154
-
155
- # Returns a boolean indicated whether the colour is a valid HTML/CSS colour.
156
- #
157
- # @return [Boolean]
158
- def valid_rgb?
159
- !!(colour =~ /^#([A-Fa-f0-9]{6})$/)
160
- end
161
-
162
160
  # Returns a collection of converted HTML/CSS octets as their decimal
163
161
  # equivalents.
164
162
  #