vedeu 0.1.15 → 0.1.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +2 -0
  3. data/README.md +116 -98
  4. data/lib/vedeu.rb +24 -11
  5. data/lib/vedeu/api/api.rb +174 -33
  6. data/lib/vedeu/api/composition.rb +2 -13
  7. data/lib/vedeu/api/helpers.rb +41 -0
  8. data/lib/vedeu/api/interface.rb +147 -34
  9. data/lib/vedeu/api/line.rb +47 -0
  10. data/lib/vedeu/api/stream.rb +41 -0
  11. data/lib/vedeu/application.rb +9 -2
  12. data/lib/vedeu/configuration.rb +66 -8
  13. data/lib/vedeu/launcher.rb +11 -0
  14. data/lib/vedeu/models/attributes/background.rb +29 -0
  15. data/lib/vedeu/models/attributes/coercions.rb +30 -0
  16. data/lib/vedeu/models/attributes/colour_translator.rb +106 -16
  17. data/lib/vedeu/models/attributes/foreground.rb +29 -0
  18. data/lib/vedeu/models/attributes/presentation.rb +15 -0
  19. data/lib/vedeu/models/colour.rb +12 -7
  20. data/lib/vedeu/models/composition.rb +23 -5
  21. data/lib/vedeu/models/geometry.rb +101 -16
  22. data/lib/vedeu/models/interface.rb +36 -28
  23. data/lib/vedeu/models/line.rb +16 -14
  24. data/lib/vedeu/models/stream.rb +17 -25
  25. data/lib/vedeu/models/style.rb +29 -0
  26. data/lib/vedeu/support/buffer.rb +36 -21
  27. data/lib/vedeu/support/buffers.rb +88 -0
  28. data/lib/vedeu/{output → support}/clear.rb +9 -2
  29. data/lib/vedeu/support/esc.rb +16 -2
  30. data/lib/vedeu/support/event.rb +104 -0
  31. data/lib/vedeu/support/events.rb +61 -0
  32. data/lib/vedeu/support/focus.rb +69 -0
  33. data/lib/vedeu/{api → support}/grid.rb +29 -25
  34. data/lib/vedeu/support/groups.rb +51 -0
  35. data/lib/vedeu/support/input.rb +5 -0
  36. data/lib/vedeu/support/log.rb +105 -0
  37. data/lib/vedeu/support/menu.rb +19 -0
  38. data/lib/vedeu/support/position.rb +7 -0
  39. data/lib/vedeu/{output → support}/render.rb +12 -6
  40. data/lib/vedeu/support/terminal.rb +21 -0
  41. data/lib/vedeu/support/trace.rb +54 -0
  42. data/lib/vedeu/{output → support}/view.rb +15 -10
  43. data/test/lib/vedeu/api/api_test.rb +55 -29
  44. data/test/lib/vedeu/api/interface_test.rb +3 -49
  45. data/test/lib/vedeu/api/line_test.rb +71 -0
  46. data/test/lib/vedeu/api/stream_test.rb +25 -0
  47. data/test/lib/vedeu/models/attributes/background_test.rb +83 -0
  48. data/test/lib/vedeu/models/attributes/coercer_test.rb +52 -0
  49. data/test/lib/vedeu/models/attributes/foreground_test.rb +83 -0
  50. data/test/lib/vedeu/models/attributes/presentation_test.rb +30 -0
  51. data/test/lib/vedeu/models/composition_test.rb +6 -6
  52. data/test/lib/vedeu/models/geometry_test.rb +34 -0
  53. data/test/lib/vedeu/models/interface_test.rb +0 -12
  54. data/test/lib/vedeu/models/line_test.rb +1 -13
  55. data/test/lib/vedeu/models/stream_test.rb +4 -50
  56. data/test/lib/vedeu/models/style_test.rb +39 -0
  57. data/test/lib/vedeu/support/buffer_test.rb +7 -3
  58. data/test/lib/vedeu/support/buffers_test.rb +15 -0
  59. data/test/lib/vedeu/{output → support}/clear_test.rb +8 -1
  60. data/test/lib/vedeu/support/esc_test.rb +2 -2
  61. data/test/lib/vedeu/support/event_test.rb +41 -0
  62. data/test/lib/vedeu/support/events_test.rb +70 -0
  63. data/test/lib/vedeu/support/focus_test.rb +114 -0
  64. data/test/lib/vedeu/support/grid_test.rb +31 -0
  65. data/test/lib/vedeu/support/groups_test.rb +65 -0
  66. data/test/lib/vedeu/{output → support}/render_test.rb +8 -1
  67. data/test/lib/vedeu/{output → support}/view_test.rb +1 -1
  68. data/test/test_helper.rb +3 -1
  69. data/vedeu.gemspec +3 -2
  70. metadata +67 -31
  71. data/lib/vedeu/api/events.rb +0 -46
  72. data/lib/vedeu/api/log.rb +0 -84
  73. data/lib/vedeu/models/attributes/attributes.rb +0 -25
  74. data/lib/vedeu/models/store.rb +0 -29
  75. data/lib/vedeu/output/buffers.rb +0 -65
  76. data/test/lib/vedeu/api/events_test.rb +0 -36
  77. data/test/lib/vedeu/api/grid_test.rb +0 -33
  78. data/test/lib/vedeu/models/attributes/attributes_test.rb +0 -39
  79. data/test/lib/vedeu/models/attributes/colour_translator_test.rb +0 -78
  80. data/test/lib/vedeu/models/store_test.rb +0 -57
  81. data/test/lib/vedeu/output/buffers_test.rb +0 -35
@@ -1,20 +1,36 @@
1
1
  module Vedeu
2
2
  class Composition
3
- def initialize(attributes = {})
4
- @attributes = attributes
3
+
4
+ attr_reader :attributes
5
+
6
+ # @param attributes [Hash]
7
+ # @param block [Proc]
8
+ # @return [Hash]
9
+ def self.build(attributes = {}, &block)
10
+ new(attributes, &block).attributes
5
11
  end
6
12
 
7
- def attributes
8
- @_attributes ||= defaults.merge!(@attributes)
13
+ # @param attributes [Hash]
14
+ # @param block [Proc]
15
+ # @return [Composition]
16
+ def initialize(attributes = {}, &block)
17
+ @attributes = defaults.merge!(attributes)
18
+
19
+ if block_given?
20
+ @self_before_instance_eval = eval('self', block.binding)
21
+
22
+ instance_eval(&block)
23
+ end
9
24
  end
10
25
 
26
+ # @return [Array]
11
27
  def interfaces
12
28
  @interfaces ||= if attributes[:interfaces].nil? || attributes[:interfaces].empty?
13
29
  []
14
30
 
15
31
  else
16
32
  [ attributes[:interfaces] ].flatten.map do |attrs|
17
- stored = Store.query(attrs[:name])
33
+ stored = Buffers.retrieve_attributes(attrs[:name])
18
34
 
19
35
  combined = stored.merge(attrs) do |key, s, a|
20
36
  key == :lines && s.empty? ? a : s
@@ -26,6 +42,7 @@ module Vedeu
26
42
  end
27
43
  end
28
44
 
45
+ # @return [String]
29
46
  def to_s
30
47
  interfaces.map(&:to_s).join
31
48
  end
@@ -37,5 +54,6 @@ module Vedeu
37
54
  interfaces: []
38
55
  }
39
56
  end
57
+
40
58
  end
41
59
  end
@@ -1,73 +1,157 @@
1
1
  module Vedeu
2
2
  class Geometry
3
+
4
+ attr_reader :attributes, :centred, :height, :width
5
+
6
+ # @param attributes [Hash]
7
+ # @return [Geometry]
3
8
  def initialize(attributes = {})
4
- @attributes = attributes
5
- end
9
+ @attributes = defaults.merge!(attributes)
6
10
 
7
- def attributes
8
- defaults.merge!(@attributes)
11
+ @centred = @attributes[:centred]
12
+ @height = @attributes[:height]
13
+ @width = @attributes[:width]
9
14
  end
10
15
 
16
+ # @return [Fixnum]
11
17
  def y
12
- @y ||= attributes[:y]
18
+ if attributes[:y].is_a?(Proc)
19
+ attributes[:y].call
20
+
21
+ else
22
+ attributes[:y]
23
+
24
+ end
13
25
  end
14
26
 
27
+ # @return [Fixnum]
15
28
  def x
16
- @x ||= attributes[:x]
17
- end
29
+ if attributes[:x].is_a?(Proc)
30
+ attributes[:x].call
31
+
32
+ else
33
+ attributes[:x]
18
34
 
19
- def width
20
- @width ||= attributes[:width]
35
+ end
21
36
  end
22
37
 
23
- def height
24
- @height ||= attributes[:height]
38
+ # @return [Fixnum]
39
+ def viewport_width
40
+ if (x + width) > Terminal.width
41
+ width - ((x + width) - Terminal.width)
42
+
43
+ else
44
+ width
45
+
46
+ end
25
47
  end
26
48
 
27
- def centred
28
- @centred ||= attributes[:centred]
49
+ # @return [Fixnum]
50
+ def viewport_height
51
+ if (y + height) > Terminal.height
52
+ height - ((y + height) - Terminal.height)
53
+
54
+ else
55
+ height
56
+
57
+ end
29
58
  end
30
59
 
60
+ # @param index [Fixnum]
61
+ # @param block [Proc]
62
+ # @return [String]
31
63
  def origin(index = 0, &block)
32
64
  Esc.set_position(virtual_y[index], left, &block)
33
65
  end
34
66
 
67
+ # @return [Fixnum]
35
68
  def top
36
69
  if centred
37
- centre_y - (height / 2)
70
+ centre_y - (viewport_height / 2)
71
+
38
72
  else
39
73
  y
74
+
40
75
  end
41
76
  end
42
77
 
78
+ # Returns the row above the top by default.
79
+ #
80
+ # @example
81
+ # `top` is 4.
82
+ #
83
+ # north # => 3
84
+ # north(2) # => 2
85
+ # north(-4) # => 8
86
+ #
87
+ # @param value [Fixnum]
88
+ # @return [Fixnum]
43
89
  def north(value = 1)
44
90
  top - value
45
91
  end
46
92
 
93
+ # @return [Fixnum]
47
94
  def left
48
95
  if centred
49
- centre_x - (width / 2)
96
+ centre_x - (viewport_width / 2)
97
+
50
98
  else
51
99
  x
100
+
52
101
  end
53
102
  end
54
103
 
104
+ # Returns the column before left by default.
105
+ #
106
+ # @example
107
+ # `left` is 8.
108
+ #
109
+ # west # => 7
110
+ # west(2) # => 6
111
+ # west(-4) # => 12
112
+ #
113
+ # @param value [Fixnum]
114
+ # @return [Fixnum]
55
115
  def west(value = 1)
56
116
  left - value
57
117
  end
58
118
 
119
+ # @return [Fixnum]
59
120
  def bottom
60
121
  top + height
61
122
  end
62
123
 
124
+ # Returns the row below the bottom by default.
125
+ #
126
+ # @example
127
+ # `bottom` is 12.
128
+ #
129
+ # south # => 13
130
+ # south(2) # => 14
131
+ # south(-4) # => 8
132
+ #
133
+ # @param value [Fixnum]
134
+ # @return [Fixnum]
63
135
  def south(value = 1)
64
136
  bottom + value
65
137
  end
66
138
 
139
+ # @return [Fixnum]
67
140
  def right
68
141
  left + width
69
142
  end
70
143
 
144
+ # Returns the column after right by default.
145
+ #
146
+ # @example
147
+ # `right` is 19.
148
+ #
149
+ # east # => 20
150
+ # east(2) # => 21
151
+ # east(-4) # => 15
152
+ #
153
+ # @param value [Fixnum]
154
+ # @return [Fixnum]
71
155
  def east(value = 1)
72
156
  right + value
73
157
  end
@@ -75,7 +159,7 @@ module Vedeu
75
159
  private
76
160
 
77
161
  def centre
78
- @_centre ||= Terminal.centre
162
+ Terminal.centre
79
163
  end
80
164
 
81
165
  def centre_y
@@ -99,5 +183,6 @@ module Vedeu
99
183
  centred: false,
100
184
  }
101
185
  end
186
+
102
187
  end
103
188
  end
@@ -1,45 +1,54 @@
1
1
  module Vedeu
2
2
  class Interface
3
+ include Coercions
4
+ include Presentation
5
+
3
6
  extend Forwardable
4
7
 
5
8
  def_delegators :geometry, :north, :east, :south, :west,
6
9
  :top, :right, :bottom, :left,
7
- :width, :height, :origin
10
+ :width, :height, :origin,
11
+ :viewport_width, :viewport_height
8
12
 
9
- def initialize(attributes = {})
10
- @attributes = attributes
11
- end
13
+ attr_reader :attributes, :delay, :group, :name
12
14
 
13
- def attributes
14
- @_attributes ||= defaults.merge!(@attributes)
15
+ # @param attributes [Hash]
16
+ # @param block [Proc]
17
+ # @return [Hash]
18
+ def self.build(attributes = {}, &block)
19
+ new(attributes, &block).attributes
15
20
  end
16
21
 
17
- def name
18
- @name ||= attributes[:name]
19
- end
22
+ # @param attributes [Hash]
23
+ # @param block [Proc]
24
+ # @return [Interface]
25
+ def initialize(attributes = {}, &block)
26
+ @attributes = defaults.merge!(attributes)
20
27
 
21
- def group
22
- @group ||= attributes[:group]
23
- end
28
+ @name = @attributes[:name]
29
+ @group = @attributes[:group]
30
+ @delay = @attributes[:delay]
24
31
 
25
- def lines
26
- @lines ||= Attributes.coercer(attributes[:lines], Line, :streams)
27
- end
32
+ if block_given?
33
+ @self_before_instance_eval = eval('self', block.binding)
28
34
 
29
- def colour
30
- @colour ||= Colour.new(attributes[:colour])
35
+ instance_eval(&block)
36
+ end
31
37
  end
32
38
 
33
- def style
34
- @style ||= Attributes.coerce_styles(attributes[:style])
39
+ # @return [Array]
40
+ def lines
41
+ @lines ||= Line.coercer(attributes[:lines])
35
42
  end
36
43
 
44
+ # @return [Geometry]
37
45
  def geometry
38
46
  @geometry ||= Geometry.new(attributes[:geometry])
39
47
  end
40
48
 
49
+ # @return [String]
41
50
  def cursor
42
- @cursor ||= if cursor?
51
+ @cursor ||= if attributes[:cursor] == true
43
52
  Esc.string('show_cursor')
44
53
 
45
54
  else
@@ -48,20 +57,18 @@ module Vedeu
48
57
  end
49
58
  end
50
59
 
51
- def delay
52
- @delay || attributes[:delay]
53
- end
54
-
60
+ # @return [String]
55
61
  def to_s
56
62
  Render.call(self)
57
63
  end
58
64
 
59
- private
60
-
61
- def cursor?
62
- attributes[:cursor] == true
65
+ # @return [String]
66
+ def clear
67
+ Clear.call(self)
63
68
  end
64
69
 
70
+ private
71
+
65
72
  def defaults
66
73
  {
67
74
  name: '',
@@ -74,5 +81,6 @@ module Vedeu
74
81
  delay: 0.0
75
82
  }
76
83
  end
84
+
77
85
  end
78
86
  end
@@ -1,11 +1,22 @@
1
1
  module Vedeu
2
2
  class Line
3
+ include Coercions
4
+ include Presentation
5
+
6
+ attr_reader :attributes
7
+
8
+ # @param attributes [Hash]
9
+ # @param block [Proc]
10
+ # @return [Hash]
3
11
  def self.build(attributes = {}, &block)
4
12
  new(attributes, &block).attributes
5
13
  end
6
14
 
15
+ # @param attributes [Hash]
16
+ # @param block [Proc]
17
+ # @return [Line]
7
18
  def initialize(attributes = {}, &block)
8
- @attributes = attributes
19
+ @attributes = defaults.merge!(attributes)
9
20
 
10
21
  if block_given?
11
22
  @self_before_instance_eval = eval('self', block.binding)
@@ -14,22 +25,12 @@ module Vedeu
14
25
  end
15
26
  end
16
27
 
17
- def attributes
18
- @_attributes ||= defaults.merge!(@attributes)
19
- end
20
-
21
- def colour
22
- @colour ||= Colour.new(attributes[:colour])
23
- end
24
-
28
+ # @return [Array]
25
29
  def streams
26
- @streams ||= Attributes.coercer(attributes[:streams], Stream, :text)
27
- end
28
-
29
- def style
30
- @style ||= Attributes.coerce_styles(attributes[:style])
30
+ @streams ||= Stream.coercer(attributes[:streams])
31
31
  end
32
32
 
33
+ # @return [String]
33
34
  def to_s
34
35
  [ colour, style, streams ].join
35
36
  end
@@ -47,5 +48,6 @@ module Vedeu
47
48
  def method_missing(method, *args, &block)
48
49
  @self_before_instance_eval.send(method, *args, &block)
49
50
  end
51
+
50
52
  end
51
53
  end
@@ -1,11 +1,25 @@
1
1
  module Vedeu
2
2
  class Stream
3
+ include Coercions
4
+ include Presentation
5
+
6
+ attr_reader :attributes, :align, :text, :width
7
+
8
+ # @param attributes [Hash]
9
+ # @param block [Proc]
10
+ # @return [Hash]
3
11
  def self.build(attributes = {}, &block)
4
12
  new(attributes, &block).attributes
5
13
  end
6
14
 
15
+ # @param attributes [Hash]
16
+ # @param block [Proc]
17
+ # @return [Stream]
7
18
  def initialize(attributes = {}, &block)
8
- @attributes = attributes
19
+ @attributes = defaults.merge!(attributes)
20
+ @align = @attributes[:align]
21
+ @text = @attributes[:text]
22
+ @width = @attributes[:width]
9
23
 
10
24
  if block_given?
11
25
  @self_before_instance_eval = eval('self', block.binding)
@@ -14,30 +28,7 @@ module Vedeu
14
28
  end
15
29
  end
16
30
 
17
- def attributes
18
- @_attributes ||= defaults.merge!(@attributes)
19
- end
20
-
21
- def colour
22
- @colour ||= Colour.new(attributes[:colour])
23
- end
24
-
25
- def style
26
- @style ||= Attributes.coerce_styles(attributes[:style])
27
- end
28
-
29
- def text
30
- @text ||= attributes[:text]
31
- end
32
-
33
- def width
34
- @width ||= attributes[:width]
35
- end
36
-
37
- def align
38
- @align ||= attributes[:align]
39
- end
40
-
31
+ # @return [String]
41
32
  def to_s
42
33
  [ colour, style, data ].join
43
34
  end
@@ -73,5 +64,6 @@ module Vedeu
73
64
  def method_missing(method, *args, &block)
74
65
  @self_before_instance_eval.send(method, *args, &block)
75
66
  end
67
+
76
68
  end
77
69
  end