vedeu 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/docs/borders.md +2 -2
  3. data/examples/284_slow_rendering.rb +2 -2
  4. data/examples/dsl_alignment.rb +9 -9
  5. data/examples/dsl_colours.rb +13 -13
  6. data/examples/dsl_editor.rb +10 -10
  7. data/lib/vedeu/borders/dsl.rb +84 -0
  8. data/lib/vedeu/buffers/empty.rb +3 -3
  9. data/lib/vedeu/buffers/terminal.rb +1 -1
  10. data/lib/vedeu/buffers/view.rb +1 -1
  11. data/lib/vedeu/cells/borders/all.rb +1 -0
  12. data/lib/vedeu/cells/borders/bottom_left.rb +1 -6
  13. data/lib/vedeu/cells/borders/bottom_right.rb +1 -6
  14. data/lib/vedeu/cells/borders/corner.rb +20 -0
  15. data/lib/vedeu/cells/borders/top_left.rb +1 -6
  16. data/lib/vedeu/cells/borders/top_right.rb +1 -6
  17. data/lib/vedeu/cells/empty.rb +22 -0
  18. data/lib/vedeu/cells/escape.rb +47 -0
  19. data/lib/vedeu/cursors/cursor.rb +6 -6
  20. data/lib/vedeu/dsl/text.rb +12 -1
  21. data/lib/vedeu/events/trigger.rb +4 -2
  22. data/lib/vedeu/input/capture.rb +1 -1
  23. data/lib/vedeu/input/mouse.rb +3 -2
  24. data/lib/vedeu/models/all.rb +0 -2
  25. data/lib/vedeu/models/row.rb +1 -1
  26. data/lib/vedeu/output/output.rb +8 -8
  27. data/lib/vedeu/output/text.rb +23 -2
  28. data/lib/vedeu/renderers/html.rb +4 -4
  29. data/lib/vedeu/runtime/launcher.rb +1 -1
  30. data/lib/vedeu/version.rb +1 -1
  31. data/test/lib/vedeu/borders/dsl_test.rb +40 -0
  32. data/test/lib/vedeu/buffers/empty_test.rb +1 -1
  33. data/test/lib/vedeu/cells/borders/bottom_left_test.rb +0 -14
  34. data/test/lib/vedeu/cells/borders/bottom_right_test.rb +0 -14
  35. data/test/lib/vedeu/cells/borders/corner_test.rb +57 -0
  36. data/test/lib/vedeu/cells/borders/top_left_test.rb +0 -14
  37. data/test/lib/vedeu/cells/borders/top_right_test.rb +0 -14
  38. data/test/lib/vedeu/cells/empty_test.rb +33 -0
  39. data/test/lib/vedeu/cells/escape_test.rb +74 -0
  40. data/test/lib/vedeu/cursors/cursor_test.rb +17 -11
  41. data/test/lib/vedeu/dsl/text_test.rb +1 -0
  42. data/test/lib/vedeu/models/row_test.rb +1 -1
  43. data/test/lib/vedeu/output/compressor_test.rb +2 -2
  44. data/test/lib/vedeu/output/output_test.rb +2 -2
  45. data/test/lib/vedeu/renderers/all_test.rb +2 -2
  46. data/test/lib/vedeu/renderers/terminal_test.rb +6 -6
  47. data/test/support/examples/material_colours_app.rb +13 -10
  48. metadata +4 -7
  49. data/lib/vedeu/models/cell.rb +0 -91
  50. data/lib/vedeu/models/escape.rb +0 -90
  51. data/test/lib/vedeu/models/cell_test.rb +0 -117
  52. data/test/lib/vedeu/models/escape_test.rb +0 -87
@@ -17,6 +17,53 @@ module Vedeu
17
17
  #
18
18
  class Escape < Vedeu::Cells::Empty
19
19
 
20
+ include Vedeu::Geometries::Positionable
21
+
22
+ # @return [Boolean]
23
+ def cell?
24
+ false
25
+ end
26
+
27
+ # @return [NilClass]
28
+ def null
29
+ nil
30
+ end
31
+ alias_method :background, :null
32
+ alias_method :colour, :null
33
+ alias_method :foreground, :null
34
+ alias_method :style, :null
35
+
36
+ # Return an empty hash as most escape sequences won't make
37
+ # sense as JSON.
38
+ #
39
+ # @return [Hash<void>]
40
+ def to_h
41
+ {}
42
+ end
43
+ alias_method :to_hash, :to_h
44
+
45
+ # Return an empty string as most escape sequences won't make
46
+ # sense as HTML.
47
+ #
48
+ # @param _options [Hash] Ignored.
49
+ # @return [String]
50
+ def to_html(_options = {})
51
+ ''.freeze
52
+ end
53
+
54
+ # @return [String]
55
+ def to_s
56
+ "#{position}#{value}".freeze
57
+ end
58
+ alias_method :to_str, :to_s
59
+
60
+ private
61
+
62
+ # @return [Hash]
63
+ def defaults
64
+ super.merge!(position: [1, 1], value: '')
65
+ end
66
+
20
67
  end # Escape
21
68
 
22
69
  end # Cells
@@ -88,7 +88,7 @@ module Vedeu
88
88
  # @return [String]
89
89
  def inspect
90
90
  "<#{self.class.name} name:'#{name}', x:#{x}, y:#{y}, ox:#{ox}, " \
91
- "oy:#{oy}, visible:#{visible}>"
91
+ "oy:#{oy}, visible:#{visible}>".freeze
92
92
  end
93
93
 
94
94
  # Moves the cursor down by one row.
@@ -160,7 +160,7 @@ module Vedeu
160
160
 
161
161
  # Renders the cursor.
162
162
  #
163
- # @return [Array<Vedeu::Models::Escape>]
163
+ # @return [Array<Vedeu::Cells::Escape>]
164
164
  def render
165
165
  Vedeu.render_output(escape_sequence)
166
166
  end
@@ -193,7 +193,7 @@ module Vedeu
193
193
  # Vedeu.hide_cursor(Vedeu.focus)
194
194
  # Vedeu.hide_cursor
195
195
  #
196
- # @return [Vedeu::Models::Escape]
196
+ # @return [Vedeu::Cells::Escape]
197
197
  def hide
198
198
  super
199
199
 
@@ -230,7 +230,7 @@ module Vedeu
230
230
  # Vedeu.show_cursor(Vedeu.focus)
231
231
  # Vedeu.show_cursor
232
232
  #
233
- # @return [Vedeu::Models::Escape]
233
+ # @return [Vedeu::Cells::Escape]
234
234
  def show
235
235
  super
236
236
 
@@ -287,9 +287,9 @@ module Vedeu
287
287
  }
288
288
  end
289
289
 
290
- # @return [Vedeu::Models::Escape]
290
+ # @return [Vedeu::Cells::Escape]
291
291
  def escape_sequence
292
- Vedeu::Models::Escape.new(position: position, value: visibility)
292
+ Vedeu::Cells::Escape.new(position: position, value: visibility)
293
293
  end
294
294
 
295
295
  # @return [Hash<Symbol => Fixnum>]
@@ -64,7 +64,7 @@ module Vedeu
64
64
  # string is shorter than the specified width.
65
65
  # @return [String]
66
66
  def text(value = '', options = {})
67
- options.merge!(anchor: __callee__, model: model, client: client)
67
+ options.merge!(text_options).merge!(anchor: __callee__)
68
68
 
69
69
  Vedeu::Output::Text.add(value, options)
70
70
  end
@@ -80,6 +80,17 @@ module Vedeu
80
80
  alias_method :left=, :text
81
81
  alias_method :right=, :text
82
82
 
83
+ private
84
+
85
+ # @return [Hash<Symbol => void>]
86
+ def text_options
87
+ {
88
+ client: client,
89
+ model: model,
90
+ name: model.name,
91
+ }
92
+ end
93
+
83
94
  end # Text
84
95
 
85
96
  end # DSL
@@ -38,8 +38,10 @@ module Vedeu
38
38
  #
39
39
  # @return [Array]
40
40
  def trigger
41
- Vedeu.log(type: :event,
42
- message: "No action for: '#{name.inspect}'") if results.empty?
41
+ if results.empty?
42
+ Vedeu.log(type: :event,
43
+ message: "No action for: '#{name.inspect}'".freeze)
44
+ end
43
45
 
44
46
  return results[0] if results.one?
45
47
 
@@ -111,7 +111,7 @@ module Vedeu
111
111
  def click?(input)
112
112
  return false if input.nil? || input.is_a?(Symbol)
113
113
 
114
- input.is_a?(Vedeu::Cursors::Cursor) || input.start_with?("\e[M")
114
+ input.is_a?(Vedeu::Cursors::Cursor) || input.start_with?("\e[M".freeze)
115
115
  end
116
116
 
117
117
  # @return [IO]
@@ -27,7 +27,8 @@ module Vedeu
27
27
  # @return [void]
28
28
  def click
29
29
  Vedeu.log(type: :input,
30
- message: "Mouse pressed: '#{button}' (x: #{x}, y: #{y})")
30
+ message: "Mouse pressed: '#{button}' " \
31
+ "(x: #{x}, y: #{y})".freeze)
31
32
 
32
33
  Vedeu.trigger(:_mouse_event_, input)
33
34
 
@@ -43,7 +44,7 @@ module Vedeu
43
44
  else
44
45
  Vedeu.log(type: :input,
45
46
  message: 'Vedeu does not support mouse button ' \
46
- "'#{button}' yet.")
47
+ "'#{button}' yet.".freeze)
47
48
 
48
49
  end
49
50
  end
@@ -9,8 +9,6 @@ module Vedeu
9
9
  end # Vedeu
10
10
 
11
11
  require 'vedeu/models/toggleable'
12
- require 'vedeu/models/cell'
13
- require 'vedeu/models/escape'
14
12
  require 'vedeu/models/focus'
15
13
  require 'vedeu/models/row'
16
14
  require 'vedeu/models/page'
@@ -2,7 +2,7 @@ module Vedeu
2
2
 
3
3
  module Models
4
4
 
5
- # A Row represents an array of Vedeu::Models::Cell objects.
5
+ # A Row represents an array of Vedeu::Cells::Empty objects.
6
6
  #
7
7
  class Row
8
8
 
@@ -10,7 +10,7 @@ module Vedeu
10
10
  class Output
11
11
 
12
12
  # @param output [Array<Array<Vedeu::Views::Char>>|
13
- # NilClass|Vedeu::Models::Escape]
13
+ # NilClass|Vedeu::Cells::Escape]
14
14
  # @return [Array]
15
15
  def self.buffer_update(output)
16
16
  return nil if output.nil?
@@ -19,7 +19,7 @@ module Vedeu
19
19
  end
20
20
 
21
21
  # @param output [Array<Array<Vedeu::Views::Char>>|
22
- # NilClass|Vedeu::Models::Escape]
22
+ # NilClass|Vedeu::Cells::Escape]
23
23
  # @return [Array]
24
24
  def self.buffer_write(output)
25
25
  return nil if output.nil?
@@ -28,7 +28,7 @@ module Vedeu
28
28
  end
29
29
 
30
30
  # @param output [Array<Array<Vedeu::Views::Char>>|
31
- # NilClass|Vedeu::Models::Escape]
31
+ # NilClass|Vedeu::Cells::Escape]
32
32
  # @return [Array<String>]
33
33
  def self.direct_write(output)
34
34
  return nil if output.nil?
@@ -39,7 +39,7 @@ module Vedeu
39
39
  # Writes output to the defined renderers.
40
40
  #
41
41
  # @param output [Array<Array<Vedeu::Views::Char>>|
42
- # NilClass|Vedeu::Models::Escape]
42
+ # NilClass|Vedeu::Cells::Escape]
43
43
  # @return [Array|NilClass|String]
44
44
  def self.render_output(output)
45
45
  return nil if output.nil?
@@ -50,7 +50,7 @@ module Vedeu
50
50
  # Return a new instance of Vedeu::Output::Output.
51
51
  #
52
52
  # @param output [Array<Array<Vedeu::Views::Char>>|
53
- # NilClass|Vedeu::Models::Escape]
53
+ # NilClass|Vedeu::Cells::Escape]
54
54
  # @return [Vedeu::Output::Output]
55
55
  def initialize(output)
56
56
  @output = output
@@ -72,7 +72,7 @@ module Vedeu
72
72
  end
73
73
 
74
74
  # Send the view to the renderers. If the output is a
75
- # {Vedeu::Models::Escape} object (typical when showing or
75
+ # {Vedeu::Cells::Escape} object (typical when showing or
76
76
  # hiding the cursor) then we bypass the
77
77
  # {Vedeu::Buffers::Terminal} and write directly to the terminal
78
78
  # because escape sequences only make sense to the terminal and
@@ -93,7 +93,7 @@ module Vedeu
93
93
 
94
94
  # @!attribute [r] output
95
95
  # @return [Array<Array<Vedeu::Views::Char>>|
96
- # NilClass|Vedeu::Models::Escape]
96
+ # NilClass|Vedeu::Cells::Escape]
97
97
  attr_reader :output
98
98
 
99
99
  private
@@ -115,7 +115,7 @@ module Vedeu
115
115
 
116
116
  # @return [Boolean]
117
117
  def escape_sequence?
118
- output.is_a?(Vedeu::Models::Escape)
118
+ output.is_a?(Vedeu::Cells::Escape)
119
119
  end
120
120
 
121
121
  end # Output
@@ -6,6 +6,8 @@ module Vedeu
6
6
  #
7
7
  class Text
8
8
 
9
+ include Vedeu::Common
10
+
9
11
  # @see Vedeu::DSL::Text#text
10
12
  def self.add(value = '', options = {})
11
13
  new(value, options).add
@@ -27,6 +29,7 @@ module Vedeu
27
29
  # @option options model
28
30
  # [Vedeu::Views::View|Vedeu::Views::Line|Vedeu::Views::Stream]
29
31
  # @option options mode (see Vedeu::Output::Wordwrap#mode)
32
+ # @option options name [String|Symbol]
30
33
  # @option options pad [String]
31
34
  # @option options width [Integer]
32
35
  # @return [Vedeu::Output::Text]
@@ -131,11 +134,17 @@ module Vedeu
131
134
  colour: nil,
132
135
  model: nil,
133
136
  mode: :default,
137
+ name: '',
134
138
  pad: ' ',
135
139
  width: nil,
136
140
  }
137
141
  end
138
142
 
143
+ # @return [NilClass|Vedeu::Geometries::Geometry]
144
+ def geometry
145
+ Vedeu.geometries.by_name(name)
146
+ end
147
+
139
148
  # The string padded to width, left justified.
140
149
  #
141
150
  # @return [String]
@@ -164,6 +173,11 @@ module Vedeu
164
173
  options[:mode]
165
174
  end
166
175
 
176
+ # @return [String|Symbol]
177
+ def name
178
+ options[:name]
179
+ end
180
+
167
181
  # The character to use for padding the string.
168
182
  #
169
183
  # @return [String]
@@ -225,11 +239,18 @@ module Vedeu
225
239
  string.slice(0, width)
226
240
  end
227
241
 
228
- # Return the width.
242
+ # Return the width of the interface when a name is given,
243
+ # otherwise use the given width.
229
244
  #
230
245
  # @return [Fixnum]
231
246
  def width
232
- options[:width]
247
+ if present?(options[:name])
248
+ geometry.bordered_width
249
+
250
+ elsif present?(options[:width])
251
+ options[:width]
252
+
253
+ end
233
254
  end
234
255
 
235
256
  # Return a boolean indicating whether the string should be
@@ -34,7 +34,7 @@ module Vedeu
34
34
  #
35
35
  # @return [String]
36
36
  def clear
37
- @output = Vedeu::Models::Escape.new
37
+ @output = Vedeu::Cells::Escape.new
38
38
 
39
39
  ''
40
40
  end
@@ -49,7 +49,7 @@ module Vedeu
49
49
 
50
50
  # @return [String]
51
51
  def html_body
52
- return '' if output.is_a?(Vedeu::Models::Escape)
52
+ return '' if output.is_a?(Vedeu::Cells::Escape)
53
53
 
54
54
  out = ''
55
55
 
@@ -65,12 +65,12 @@ module Vedeu
65
65
  private
66
66
 
67
67
  # Returns a boolean indicating whether the output is a
68
- # {Vedeu::Models::Escape}. If it is, it won't be rendered in
68
+ # {Vedeu::Cells::Escape}. If it is, it won't be rendered in
69
69
  # HTML.
70
70
  #
71
71
  # @return [Boolean]
72
72
  def escape?
73
- output.is_a?(Vedeu::Models::Escape)
73
+ output.is_a?(Vedeu::Cells::Escape)
74
74
  end
75
75
 
76
76
  # @return [Array<Array<Vedeu::Views::Char>>]
@@ -70,7 +70,7 @@ module Vedeu
70
70
 
71
71
  rescue StandardError => uncaught_exception
72
72
  output = if Vedeu::Configuration.debug?
73
- uncaught_exception.message + "\n" +
73
+ uncaught_exception.message + "\n".freeze +
74
74
  uncaught_exception.backtrace.join("\n".freeze)
75
75
  else
76
76
  uncaught_exception.message
data/lib/vedeu/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Vedeu
2
2
 
3
3
  # The current version of Vedeu.
4
- VERSION = '0.7.0'.freeze
4
+ VERSION = '0.7.1'.freeze
5
5
 
6
6
  end
@@ -68,6 +68,26 @@ module Vedeu
68
68
  it { subject.must_be_instance_of(TrueClass) }
69
69
  end
70
70
 
71
+ describe '#top_horizontal' do
72
+ let(:char) { 'T' }
73
+ let(:options) { {} }
74
+
75
+ subject { instance.top_horizontal(char, options) }
76
+
77
+ it { subject.must_be_instance_of(Vedeu::Cells::TopHorizontal) }
78
+ it { instance.must_respond_to(:top_horizontal=) }
79
+ end
80
+
81
+ describe '#bottom_horizontal' do
82
+ let(:char) { 'B' }
83
+ let(:options) { {} }
84
+
85
+ subject { instance.bottom_horizontal(char, options) }
86
+
87
+ it { subject.must_be_instance_of(Vedeu::Cells::BottomHorizontal) }
88
+ it { instance.must_respond_to(:bottom_horizontal=) }
89
+ end
90
+
71
91
  describe '#horizontal' do
72
92
  let(:char) { 'H' }
73
93
  let(:options) { {} }
@@ -246,6 +266,26 @@ module Vedeu
246
266
  end
247
267
  end
248
268
 
269
+ describe '#left_vertical' do
270
+ let(:char) { 'V' }
271
+ let(:options) { {} }
272
+
273
+ subject { instance.left_vertical(char, options) }
274
+
275
+ it { subject.must_be_instance_of(Vedeu::Cells::LeftVertical) }
276
+ it { instance.must_respond_to(:left_vertical=) }
277
+ end
278
+
279
+ describe '#right_vertical' do
280
+ let(:char) { 'V' }
281
+ let(:options) { {} }
282
+
283
+ subject { instance.right_vertical(char, options) }
284
+
285
+ it { subject.must_be_instance_of(Vedeu::Cells::RightVertical) }
286
+ it { instance.must_respond_to(:right_vertical=) }
287
+ end
288
+
249
289
  describe '#vertical' do
250
290
  let(:char) { 'V' }
251
291
  let(:options) { {} }
@@ -61,7 +61,7 @@ module Vedeu
61
61
 
62
62
  it { subject.must_be_instance_of(Array) }
63
63
  it { subject.first.must_be_instance_of(Array) }
64
- it { subject.first.first.must_be_instance_of(Vedeu::Models::Cell) }
64
+ it { subject.first.first.must_be_instance_of(Vedeu::Cells::Empty) }
65
65
 
66
66
  it { subject.size.must_equal(3) }
67
67
  it { subject.first.size.must_equal(9) }
@@ -9,20 +9,6 @@ module Vedeu
9
9
  let(:described) { Vedeu::Cells::BottomLeft }
10
10
  let(:instance) { described.new }
11
11
 
12
- describe '#position' do
13
- let(:geometry) {
14
- Vedeu::Geometries::Geometry.new(x: 5, xn: 15, y: 3, yn: 9)
15
- }
16
-
17
- subject { instance.position }
18
-
19
- before { Vedeu.geometries.stubs(:by_name).returns(geometry) }
20
-
21
- it { subject.must_be_instance_of(Vedeu::Geometries::Position) }
22
- it { subject.x.must_equal(5) }
23
- it { subject.y.must_equal(9) }
24
- end
25
-
26
12
  describe '#type' do
27
13
  subject { instance.type }
28
14