vedeu 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/docs/dsl.md +3 -3
  3. data/examples/borders_app.rb +2 -0
  4. data/examples/colours_app.rb +2 -0
  5. data/examples/configuration_app.rb +2 -0
  6. data/examples/drb_app.rb +2 -0
  7. data/examples/focus_app.rb +2 -0
  8. data/examples/hello_world.rb +2 -0
  9. data/examples/material_colours_app.rb +2 -0
  10. data/lib/vedeu.rb +2 -0
  11. data/lib/vedeu/all.rb +4 -13
  12. data/lib/vedeu/api.rb +7 -6
  13. data/lib/vedeu/borders/border.rb +1 -1
  14. data/lib/vedeu/borders/render_border.rb +18 -18
  15. data/lib/vedeu/buffers/buffer.rb +18 -28
  16. data/lib/vedeu/colours/colour.rb +1 -1
  17. data/lib/vedeu/colours/colour_translator.rb +1 -1
  18. data/lib/vedeu/cursor/cursor.rb +9 -6
  19. data/lib/vedeu/dsl/border.rb +1 -1
  20. data/lib/vedeu/dsl/composition.rb +5 -5
  21. data/lib/vedeu/dsl/geometry.rb +1 -1
  22. data/lib/vedeu/dsl/group.rb +1 -1
  23. data/lib/vedeu/dsl/interface.rb +69 -93
  24. data/lib/vedeu/dsl/keymap.rb +1 -1
  25. data/lib/vedeu/dsl/line.rb +11 -11
  26. data/lib/vedeu/dsl/shared.rb +81 -0
  27. data/lib/vedeu/dsl/stream.rb +3 -3
  28. data/lib/vedeu/dsl/view.rb +76 -64
  29. data/lib/vedeu/models/escape.rb +1 -1
  30. data/lib/vedeu/models/interface.rb +3 -57
  31. data/lib/vedeu/models/menu.rb +1 -1
  32. data/lib/vedeu/models/views/all.rb +22 -0
  33. data/lib/vedeu/models/views/char.rb +175 -0
  34. data/lib/vedeu/models/views/chars.rb +13 -0
  35. data/lib/vedeu/models/views/composition.rb +73 -0
  36. data/lib/vedeu/models/views/line.rb +111 -0
  37. data/lib/vedeu/models/views/lines.rb +13 -0
  38. data/lib/vedeu/models/views/stream.rb +122 -0
  39. data/lib/vedeu/models/views/streams.rb +13 -0
  40. data/lib/vedeu/models/views/view.rb +157 -0
  41. data/lib/vedeu/models/views/view_collection.rb +13 -0
  42. data/lib/vedeu/null/view.rb +67 -0
  43. data/lib/vedeu/output/clear/named_interface.rb +4 -4
  44. data/lib/vedeu/output/compressor.rb +6 -6
  45. data/lib/vedeu/output/html_char.rb +6 -6
  46. data/lib/vedeu/output/output.rb +3 -3
  47. data/lib/vedeu/output/presentation.rb +1 -1
  48. data/lib/vedeu/output/renderers/escape_sequence.rb +1 -1
  49. data/lib/vedeu/output/renderers/file.rb +1 -1
  50. data/lib/vedeu/output/renderers/html.rb +3 -3
  51. data/lib/vedeu/output/renderers/json.rb +4 -4
  52. data/lib/vedeu/output/renderers/null.rb +1 -1
  53. data/lib/vedeu/output/renderers/terminal.rb +5 -5
  54. data/lib/vedeu/output/renderers/text.rb +3 -3
  55. data/lib/vedeu/output/style.rb +1 -1
  56. data/lib/vedeu/output/text.rb +20 -15
  57. data/lib/vedeu/output/viewport.rb +16 -23
  58. data/lib/vedeu/output/virtual_buffer.rb +9 -8
  59. data/lib/vedeu/output/virtual_terminal.rb +11 -11
  60. data/lib/vedeu/output/wordwrap.rb +5 -5
  61. data/lib/vedeu/runtime/application.rb +1 -1
  62. data/lib/vedeu/runtime/main_loop.rb +1 -1
  63. data/lib/vedeu/templating/helpers.rb +11 -10
  64. data/lib/vedeu/templating/template.rb +1 -1
  65. data/lib/vedeu/templating/view_template.rb +6 -6
  66. data/lib/vedeu/version.rb +1 -2
  67. data/test/lib/vedeu/api_test.rb +30 -30
  68. data/test/lib/vedeu/buffers/buffer_test.rb +5 -139
  69. data/test/lib/vedeu/colours/colour_translator_test.rb +3 -3
  70. data/test/lib/vedeu/configuration/api_test.rb +3 -3
  71. data/test/lib/vedeu/cursor/refresh_cursor_test.rb +1 -1
  72. data/test/lib/vedeu/dsl/composition_test.rb +7 -7
  73. data/test/lib/vedeu/dsl/group_test.rb +2 -2
  74. data/test/lib/vedeu/dsl/interface_test.rb +31 -21
  75. data/test/lib/vedeu/dsl/keymap_test.rb +4 -4
  76. data/test/lib/vedeu/dsl/line_test.rb +8 -8
  77. data/test/lib/vedeu/dsl/stream_test.rb +4 -4
  78. data/test/lib/vedeu/dsl/text_test.rb +11 -11
  79. data/test/lib/vedeu/dsl/view_test.rb +24 -29
  80. data/test/lib/vedeu/geometry/grid_test.rb +4 -4
  81. data/test/lib/vedeu/input/key_test.rb +1 -1
  82. data/test/lib/vedeu/internal_api_test.rb +18 -18
  83. data/test/lib/vedeu/models/focus_test.rb +54 -54
  84. data/test/lib/vedeu/models/interface_test.rb +11 -105
  85. data/test/lib/vedeu/models/menu_test.rb +1 -1
  86. data/test/lib/vedeu/models/views/char_test.rb +257 -0
  87. data/test/lib/vedeu/models/views/chars_test.rb +22 -0
  88. data/test/lib/vedeu/models/views/composition_test.rb +61 -0
  89. data/test/lib/vedeu/models/views/line_test.rb +189 -0
  90. data/test/lib/vedeu/models/views/lines_test.rb +22 -0
  91. data/test/lib/vedeu/models/views/stream_test.rb +138 -0
  92. data/test/lib/vedeu/models/views/streams_test.rb +22 -0
  93. data/test/lib/vedeu/models/views/view_test.rb +40 -0
  94. data/test/lib/vedeu/null/view_test.rb +12 -0
  95. data/test/lib/vedeu/output/clear/named_interface_test.rb +4 -4
  96. data/test/lib/vedeu/output/compressor_test.rb +28 -28
  97. data/test/lib/vedeu/output/html_char_test.rb +2 -2
  98. data/test/lib/vedeu/output/presentation_test.rb +10 -14
  99. data/test/lib/vedeu/output/renderers/escape_sequence_test.rb +20 -4
  100. data/test/lib/vedeu/output/renderers/html_test.rb +4 -4
  101. data/test/lib/vedeu/output/renderers/json_test.rb +3 -3
  102. data/test/lib/vedeu/output/text_test.rb +10 -10
  103. data/test/lib/vedeu/output/viewport_test.rb +21 -23
  104. data/test/lib/vedeu/output/virtual_buffer_test.rb +1 -1
  105. data/test/lib/vedeu/output/virtual_terminal_test.rb +1 -1
  106. data/test/lib/vedeu/output/wordwrap_test.rb +9 -9
  107. data/test/lib/vedeu/repositories/repository_test.rb +2 -2
  108. data/test/lib/vedeu/templating/helpers_test.rb +6 -39
  109. data/test/lib/vedeu/templating/template_test.rb +2 -2
  110. data/test/lib/vedeu/templating/view_template_test.rb +91 -91
  111. data/test/lib/vedeu/terminal_test.rb +1 -1
  112. metadata +33 -27
  113. data/lib/vedeu/buffers/display_buffer.rb +0 -39
  114. data/lib/vedeu/models/char.rb +0 -170
  115. data/lib/vedeu/models/chars.rb +0 -9
  116. data/lib/vedeu/models/composition.rb +0 -66
  117. data/lib/vedeu/models/line.rb +0 -112
  118. data/lib/vedeu/models/lines.rb +0 -9
  119. data/lib/vedeu/models/stream.rb +0 -122
  120. data/lib/vedeu/models/streams.rb +0 -9
  121. data/test/lib/vedeu/buffers/display_buffer_test.rb +0 -61
  122. data/test/lib/vedeu/models/char_test.rb +0 -253
  123. data/test/lib/vedeu/models/chars_test.rb +0 -18
  124. data/test/lib/vedeu/models/composition_test.rb +0 -57
  125. data/test/lib/vedeu/models/line_test.rb +0 -189
  126. data/test/lib/vedeu/models/lines_test.rb +0 -18
  127. data/test/lib/vedeu/models/stream_test.rb +0 -141
  128. data/test/lib/vedeu/models/streams_test.rb +0 -18
@@ -0,0 +1,13 @@
1
+ module Vedeu
2
+
3
+ module Views
4
+
5
+ # A collection of {Vedeu::Views::Line} instances.
6
+ #
7
+ class Lines < Vedeu::Collection
8
+
9
+ end # Lines
10
+
11
+ end # Views
12
+
13
+ end # Vedeu
@@ -0,0 +1,122 @@
1
+ module Vedeu
2
+
3
+ module Views
4
+
5
+ # Represents a character or collection of characters as part of a
6
+ # {Vedeu::Views::Line} which you wish to colour and style independently of
7
+ # the other characters in that line.
8
+ #
9
+ class Stream
10
+
11
+ include Vedeu::Model
12
+ include Vedeu::Presentation
13
+
14
+ collection Vedeu::Views::Chars
15
+ member Vedeu::Views::Char
16
+
17
+ # @!attribute [rw] parent
18
+ # @return [Vedeu::Views::Line]
19
+ attr_accessor :parent
20
+
21
+ # @!attribute [rw] value
22
+ # @return [String]
23
+ attr_accessor :value
24
+ alias_method :content, :value
25
+ alias_method :data, :value
26
+ alias_method :text, :value
27
+
28
+ # @!attribute [r] attributes
29
+ # @return [Hash]
30
+ attr_reader :attributes
31
+
32
+ # Returns a new instance of Vedeu::Views::Stream.
33
+ #
34
+ # @param attributes [Hash]
35
+ # @option attributes value [String]
36
+ # @option attributes parent [Vedeu::Views::Line]
37
+ # @option attributes colour [Vedeu::Colour]
38
+ # @option attributes style [Vedeu::Style]
39
+ # @return [Vedeu::Views::Stream]
40
+ def initialize(attributes = {})
41
+ @attributes = defaults.merge!(attributes)
42
+
43
+ @attributes.each do |key, value|
44
+ instance_variable_set("@#{key}", value)
45
+ end
46
+ end
47
+
48
+ # @param child [Vedeu::Views::Stream]
49
+ # @return [Vedeu::Views::Streams]
50
+ def add(child)
51
+ parent.add(child)
52
+ end
53
+ alias_method :<<, :add
54
+
55
+ # Returns an array of characters, each element is the escape sequences of
56
+ # colours and styles for this stream, the character itself, and the escape
57
+ # sequences of colours and styles for the parent of the stream
58
+ # ({Vedeu::Views::Line}).
59
+ #
60
+ # @return [Array]
61
+ def chars
62
+ return [] if empty?
63
+
64
+ @chars ||= value.chars.map do |char|
65
+ member.new(value: char,
66
+ parent: parent,
67
+ colour: colour,
68
+ style: style,
69
+ position: nil)
70
+ end
71
+ end
72
+
73
+ # Returns a boolean indicating whether the stream has content.
74
+ #
75
+ # @return [Boolean]
76
+ def empty?
77
+ value.empty?
78
+ end
79
+
80
+ # An object is equal when its values are the same.
81
+ #
82
+ # @param other [Vedeu::Views::Char]
83
+ # @return [Boolean]
84
+ def eql?(other)
85
+ self.class == other.class && value == other.value &&
86
+ colour == other.colour && style == other.style &&
87
+ parent == other.parent
88
+ end
89
+ alias_method :==, :eql?
90
+
91
+ # @return [NilClass|String]
92
+ def name
93
+ parent.name if parent
94
+ end
95
+
96
+ # Returns the size of the content in characters without formatting.
97
+ #
98
+ # @return [Fixnum]
99
+ def size
100
+ value.size
101
+ end
102
+
103
+ private
104
+
105
+ # The default values for a new instance of this class.
106
+ #
107
+ # @return [Hash]
108
+ def defaults
109
+ {
110
+ client: nil,
111
+ colour: nil,
112
+ parent: nil,
113
+ style: nil,
114
+ value: '',
115
+ }
116
+ end
117
+
118
+ end # Stream
119
+
120
+ end # Views
121
+
122
+ end # Vedeu
@@ -0,0 +1,13 @@
1
+ module Vedeu
2
+
3
+ module Views
4
+
5
+ # A collection of {Vedeu::Views::Stream} instances.
6
+ #
7
+ class Streams < Vedeu::Collection
8
+
9
+ end # Streams
10
+
11
+ end # Views
12
+
13
+ end # Vedeu
@@ -0,0 +1,157 @@
1
+ module Vedeu
2
+
3
+ module Views
4
+
5
+ # Represents a container for {Vedeu::Views::Line} and {Vedeu::Views::Stream}
6
+ # objects.
7
+ #
8
+ class View
9
+
10
+ include Vedeu::Model
11
+ include Vedeu::Presentation
12
+
13
+ collection Vedeu::Views::Lines
14
+ member Vedeu::Views::Line
15
+
16
+ # @!attribute [rw] client
17
+ # @return [Fixnum|Float]
18
+ attr_accessor :client
19
+
20
+ # @!attribute [rw] name
21
+ # @return [String]
22
+ attr_accessor :name
23
+
24
+ # @!attribute [rw] parent
25
+ # @return [Vedeu::Views::Composition]
26
+ attr_accessor :parent
27
+
28
+ # @!attribute [rw] zindex
29
+ # @return [Fixnum]
30
+ attr_accessor :zindex
31
+
32
+ # @!attribute [r] attributes
33
+ # @return [Hash]
34
+ attr_reader :attributes
35
+
36
+ # @!attribute [w] lines
37
+ # @return [Array<Vedeu::Views::Line>]
38
+ attr_writer :lines
39
+
40
+ # Return a new instance of Vedeu::Views::View.
41
+ #
42
+ # @param attributes [Hash]
43
+ # @option attributes client [Vedeu::Client]
44
+ # @option attributes colour [Vedeu::Colour]
45
+ # @option attributes lines [Vedeu::Views::Lines]
46
+ # @option attributes name [String]
47
+ # @option attributes parent [Vedeu::Views::Composition]
48
+ # @option attributes style [Vedeu::Style]
49
+ # @option attributes zindex [Fixnum]
50
+ # @return [Vedeu::Views::View]
51
+ def initialize(attributes = {})
52
+ @attributes = defaults.merge!(attributes)
53
+
54
+ @attributes.each do |key, value|
55
+ instance_variable_set("@#{key}", value)
56
+ end
57
+ end
58
+
59
+ # @param child [Vedeu::Views::Line]
60
+ # @return [void]
61
+ def add(child)
62
+ @lines = lines.add(child)
63
+ end
64
+ alias_method :<<, :add
65
+
66
+ # Override Ruby's Object#inspect method to provide a more helpful output.
67
+ #
68
+ # @return [String]
69
+ def inspect
70
+ "<Vedeu::Views::View name: '#{name}', zindex: '#{zindex}'>"
71
+ end
72
+
73
+ # @return [Vedeu::Views::Lines]
74
+ def lines
75
+ collection.coerce(@lines, self)
76
+ end
77
+ alias_method :value, :lines
78
+
79
+ # Returns a boolean indicating whether the interface has content.
80
+ #
81
+ # @return [Boolean]
82
+ def lines?
83
+ lines.any?
84
+ end
85
+
86
+ # @return [Array<Array<Vedeu::Views::Char>>]
87
+ def render
88
+ return [] unless visible?
89
+
90
+ output = [
91
+ Vedeu::Cursor.hide_cursor(name),
92
+ Vedeu::Clear::NamedInterface.render(name),
93
+ Vedeu::Viewport.render(self),
94
+ Vedeu.borders.by_name(name).render,
95
+ Vedeu::Cursor.show_cursor(name),
96
+ ]
97
+
98
+ output
99
+ end
100
+
101
+ # Store the view and immediately refresh it; causing to be pushed to the
102
+ # Terminal. Called by {Vedeu::DSL::View.renders}.
103
+ #
104
+ # @return [Vedeu::Views::View]
105
+ def store_immediate
106
+ store_deferred
107
+
108
+ Vedeu::Refresh.by_name(name)
109
+
110
+ self
111
+ end
112
+
113
+ # When a name is given, the view is stored with this name. This view will
114
+ # be shown next time a refresh event is triggered with this name.
115
+ # Called by {Vedeu::DSL::View.views}.
116
+ #
117
+ # @raise [Vedeu::InvalidSyntax] The name is not defined.
118
+ # @return [Vedeu::Views::View]
119
+ def store_deferred
120
+ unless present?(name)
121
+ fail Vedeu::InvalidSyntax, 'Cannot store an interface without a name.'
122
+ end
123
+
124
+ Vedeu.buffers.by_name(name).add(self)
125
+
126
+ self
127
+ end
128
+
129
+ # Returns a boolean indicating whether the view is visible.
130
+ #
131
+ # @return [Boolean]
132
+ def visible?
133
+ Vedeu.interfaces.by_name(name).visible?
134
+ end
135
+
136
+ private
137
+
138
+ # The default values for a new instance of this class.
139
+ #
140
+ # @return [Hash]
141
+ def defaults
142
+ {
143
+ client: nil,
144
+ colour: Vedeu::Colour.coerce(background: :default,
145
+ foreground: :default),
146
+ name: '',
147
+ parent: nil,
148
+ style: :normal,
149
+ zindex: 0,
150
+ }
151
+ end
152
+
153
+ end # View
154
+
155
+ end # Views
156
+
157
+ end # Vedeu
@@ -0,0 +1,13 @@
1
+ module Vedeu
2
+
3
+ module Views
4
+
5
+ # A collection of {Vedeu::Views::View} instances.
6
+ #
7
+ class ViewCollection < Vedeu::Collection
8
+
9
+ end # ViewCollection
10
+
11
+ end # Views
12
+
13
+ end # Vedeu
@@ -0,0 +1,67 @@
1
+ require 'vedeu/output/presentation'
2
+
3
+ module Vedeu
4
+
5
+ module Null
6
+
7
+ # Provides a non-existent model to swallow messages.
8
+ #
9
+ class View
10
+
11
+ include Vedeu::Presentation
12
+
13
+ # @!attribute [r] name,
14
+ # @return [String]
15
+ attr_reader :name
16
+
17
+ # @!attribute [r] attributes
18
+ # @return [String]
19
+ attr_reader :attributes
20
+
21
+ # @!attribute [rw] visible
22
+ # @return [String]
23
+ attr_accessor :visible
24
+ alias_method :visible?, :visible
25
+
26
+ # Returns a new instance of Vedeu::Null::View.
27
+ #
28
+ # @param attributes [Hash<Symbol => void>]
29
+ # @option attributes name [String]
30
+ # @return [Vedeu::Null::View]
31
+ def initialize(attributes = {})
32
+ @attributes = attributes
33
+ @name = @attributes[:name]
34
+ @visible = @attributes[:visible]
35
+ end
36
+
37
+ # @return [NilClass]
38
+ def null
39
+ nil
40
+ end
41
+ alias_method :parent, :null
42
+ alias_method :zindex, :null
43
+
44
+ # @return [Boolean]
45
+ def null?
46
+ true
47
+ end
48
+
49
+ # Pretend to store this model in the repository.
50
+ #
51
+ # @return [Vedeu::Null::View]
52
+ def store
53
+ self
54
+ end
55
+
56
+ # The null interface should not be visible.
57
+ #
58
+ # @return [FalseClass]
59
+ def visible?
60
+ false
61
+ end
62
+
63
+ end # View
64
+
65
+ end # Null
66
+
67
+ end # Vedeu
@@ -56,7 +56,7 @@ module Vedeu
56
56
  # then starting write space characters over the area which the interface
57
57
  # occupies.
58
58
  #
59
- # @return [Array<Array<Vedeu::Char>>]
59
+ # @return [Array<Array<Vedeu::Views::Char>>]
60
60
  def output
61
61
  Vedeu.timer("Clearing: '#{name}'") do
62
62
  @y = geometry.y
@@ -67,9 +67,9 @@ module Vedeu
67
67
 
68
68
  @clear ||= Array.new(@height) do |iy|
69
69
  Array.new(@width) do |ix|
70
- Vedeu::Char.new(value: ' ',
71
- colour: @colour,
72
- position: [@y + iy, @x + ix])
70
+ Vedeu::Views::Char.new(value: ' ',
71
+ colour: @colour,
72
+ position: [@y + iy, @x + ix])
73
73
  end
74
74
  end
75
75
  end
@@ -1,12 +1,12 @@
1
1
  module Vedeu
2
2
 
3
- # During the conversion of a Vedeu::Char object into a string of escape
3
+ # During the conversion of a Vedeu::Views::Char object into a string of escape
4
4
  # sequences, this class removes multiple occurences of the same escape
5
5
  # sequence, resulting in a smaller payload being sent to the renderer.
6
6
  #
7
7
  class Compressor
8
8
 
9
- # @param output [Array<Array<Vedeu::Char>>]
9
+ # @param output [Array<Array<Vedeu::Views::Char>>]
10
10
  # @return [String]
11
11
  def self.render(output)
12
12
  new(output).render
@@ -14,7 +14,7 @@ module Vedeu
14
14
 
15
15
  # Returns a new instance of Vedeu::Compressor.
16
16
  #
17
- # @param output [Array<Array<Vedeu::Char>>]
17
+ # @param output [Array<Array<Vedeu::Views::Char>>]
18
18
  # @return [Vedeu::Compressor]
19
19
  def initialize(output)
20
20
  @output = output
@@ -38,7 +38,7 @@ module Vedeu
38
38
  protected
39
39
 
40
40
  # @!attribute [r] output
41
- # @return [Array<Array<Vedeu::Char>>]
41
+ # @return [Array<Array<Vedeu::Views::Char>>]
42
42
  attr_reader :output
43
43
 
44
44
  private
@@ -62,7 +62,7 @@ module Vedeu
62
62
  out
63
63
  end
64
64
 
65
- # @param char [Vedeu::Char]
65
+ # @param char [Vedeu::Views::Char]
66
66
  # @return [String]
67
67
  def colour_for(char)
68
68
  return '' if char.colour == @colour
@@ -71,7 +71,7 @@ module Vedeu
71
71
  @colour.to_s
72
72
  end
73
73
 
74
- # @param char [Vedeu::Char]
74
+ # @param char [Vedeu::Views::Char]
75
75
  # @return [String]
76
76
  def style_for(char)
77
77
  return '' if char.style == @style