vedeu 0.4.24 → 0.4.25

Sign up to get free protection for your applications and to get access to all the features.
data/lib/vedeu/debug.rb CHANGED
@@ -12,9 +12,9 @@ module Vedeu
12
12
 
13
13
  require 'ruby-prof'
14
14
 
15
- RubyProf.measure_mode = RubyProf::WALL_TIME
15
+ # RubyProf.measure_mode = RubyProf::WALL_TIME
16
16
  # RubyProf.measure_mode = RubyProf::PROCESS_TIME
17
- # RubyProf.measure_mode = RubyProf::CPU_TIME
17
+ RubyProf.measure_mode = RubyProf::CPU_TIME
18
18
  # RubyProf.measure_mode = RubyProf::ALLOCATIONS
19
19
  # RubyProf.measure_mode = RubyProf::MEMORY
20
20
  # RubyProf.measure_mode = RubyProf::GC_TIME
@@ -28,9 +28,12 @@ module Vedeu
28
28
  result.eliminate_methods!([
29
29
  /^Array/,
30
30
  /^Hash/,
31
+ /^String/,
32
+ /^Fixnum/,
31
33
  ])
32
34
 
33
35
  File.open('/tmp/' + filename, 'w') do |file|
36
+ # - Creates a HTML visualization of the Ruby stack
34
37
  RubyProf::CallStackPrinter.new(result).print(file)
35
38
 
36
39
  # Used with QTCacheGrind to analyse performance.
@@ -55,9 +58,6 @@ module Vedeu
55
58
  # - Creates a call tree report compatible with KCachegrind.
56
59
  # RubyProf::CallTreePrinter
57
60
 
58
- # - Creates a HTML visualization of the Ruby stack
59
- # RubyProf::CallStackPrinter
60
-
61
61
  # - Uses the other printers to create several reports in one profiling run
62
62
  # RubyProf::MultiPrinter
63
63
  end
@@ -31,6 +31,7 @@ module Vedeu
31
31
  def to_s
32
32
  ['druby://', host, ':', port].join
33
33
  end
34
+ alias_method :to_str, :to_s
34
35
 
35
36
  end # Uri
36
37
 
@@ -142,28 +142,6 @@ module Vedeu
142
142
  work
143
143
  end
144
144
 
145
- # @param dy [Fixnum]
146
- # @param dx [Fixnum]
147
- # @return [Vedeu::Geometry]
148
- def move(dy = 0, dx = 0)
149
- new_attrs = {
150
- centred: false,
151
- maximised: false,
152
- name: name,
153
- x: (area.x + dx),
154
- y: (area.y + dy),
155
- xn: (area.xn + dx),
156
- yn: (area.yn + dy),
157
- }
158
-
159
- work = Vedeu::Geometry.new(new_attrs).store
160
-
161
- Vedeu.trigger(:_clear_)
162
- Vedeu.trigger(:_refresh_, name)
163
-
164
- work
165
- end
166
-
167
145
  private
168
146
 
169
147
  # @return [Vedeu::Area]
@@ -74,6 +74,7 @@ module Vedeu
74
74
 
75
75
  [sequence, yield, sequence].join
76
76
  end
77
+ alias_method :to_str, :to_s
77
78
 
78
79
  private
79
80
 
@@ -2,6 +2,7 @@ require 'vedeu/repositories/all'
2
2
 
3
3
  require_relative 'cell'
4
4
  require_relative 'char'
5
+ require_relative 'escape_char'
5
6
  require_relative 'stream'
6
7
  require_relative 'line'
7
8
  require_relative 'interface'
@@ -84,7 +84,13 @@ module Vedeu
84
84
  # @param value [Vedeu::Position]
85
85
  # @return [Vedeu::Position]
86
86
  def position=(value)
87
- @position = @attributes[:position] = Vedeu::Position.coerce(value)
87
+ if value.is_a?(Vedeu::Position)
88
+ @position = @attributes[:position] = value
89
+
90
+ else
91
+ @position = @attributes[:position] = Vedeu::Position.coerce(value)
92
+
93
+ end
88
94
  end
89
95
 
90
96
  # @return [String]
@@ -0,0 +1,49 @@
1
+ module Vedeu
2
+
3
+ class EscapeChar
4
+
5
+ # @param value [String]
6
+ # @return [Vedeu::EscapeChar]
7
+ def initialize(value)
8
+ @value = value
9
+ end
10
+
11
+ # @return [String]
12
+ def colour
13
+ ''
14
+ end
15
+
16
+ # An object is equal when its values are the same.
17
+ #
18
+ # @param other [Vedeu::Char]
19
+ # @return [Boolean]
20
+ def eql?(other)
21
+ self.class == other.class && value == other.value
22
+ end
23
+ alias_method :==, :eql?
24
+
25
+ # @return [String]
26
+ def inspect
27
+ "<Vedeu::EscapeChar '#{Vedeu::Esc.escape(to_s)}'>"
28
+ end
29
+
30
+ # @return [String]
31
+ def position
32
+ ''
33
+ end
34
+
35
+ # @return [String]
36
+ def style
37
+ ''
38
+ end
39
+
40
+ # @return [String]
41
+ def value
42
+ @value
43
+ end
44
+ alias_method :to_s, :value
45
+ alias_method :to_str, :value
46
+
47
+ end # EscapeChar
48
+
49
+ end # Vedeu
@@ -174,6 +174,7 @@ module Vedeu
174
174
  def to_s
175
175
  Vedeu::Renderers::Text.render(render)
176
176
  end
177
+ alias_method :to_str, :to_s
177
178
 
178
179
  # Renders the bottom border for the interface.
179
180
  #
@@ -361,14 +362,14 @@ module Vedeu
361
362
  # @return [Vedeu::Position]
362
363
  def position(name, iy = 0, ix = 0)
363
364
  case name
364
- when :top_horizontal then [y, (bx + ix)]
365
- when :bottom_horizontal then [yn, (bx + ix)]
366
- when :left_vertical then [(by + iy), x]
367
- when :right_vertical then [(by + iy), xn]
368
- when :bottom_left then [yn, x]
369
- when :bottom_right then [yn, xn]
370
- when :top_left then [y, x]
371
- when :top_right then [y, xn]
365
+ when :top_horizontal then Vedeu::Position.coerce([y, (bx + ix)])
366
+ when :bottom_horizontal then Vedeu::Position.coerce([yn, (bx + ix)])
367
+ when :left_vertical then Vedeu::Position.coerce([(by + iy), x])
368
+ when :right_vertical then Vedeu::Position.coerce([(by + iy), xn])
369
+ when :bottom_left then Vedeu::Position.coerce([yn, x])
370
+ when :bottom_right then Vedeu::Position.coerce([yn, xn])
371
+ when :top_left then Vedeu::Position.coerce([y, x])
372
+ when :top_right then Vedeu::Position.coerce([y, xn])
372
373
  end
373
374
  end
374
375
 
@@ -59,12 +59,14 @@ module Vedeu
59
59
  def clear
60
60
  if visible?
61
61
  Vedeu::Timer.for(:debug, "Clearing: #{name}") do
62
+ y, x = *position
63
+
62
64
  @clear ||= Array.new(height) do |iy|
63
65
  Array.new(width) do |ix|
64
66
  Vedeu::Char.new(value: ' ',
65
67
  colour: clear_colour,
66
68
  style: style,
67
- position: Vedeu::IndexPosition[iy, ix, *position])
69
+ position: [y + iy, x + ix])
68
70
  end
69
71
  end
70
72
  end
@@ -114,6 +114,7 @@ module Vedeu
114
114
  def to_s
115
115
  foreground.to_s + background.to_s
116
116
  end
117
+ alias_method :to_str, :to_s
117
118
 
118
119
  private
119
120
 
@@ -17,18 +17,12 @@ module Vedeu
17
17
  # @return [String]
18
18
  def render
19
19
  Array(output).flatten.map do |char|
20
- if char.is_a?(Vedeu::Char)
21
- out = ''
22
- out << char.position.to_s
23
- out << colour_for(char)
24
- out << style_for(char)
25
- out << char.value
26
- out
27
-
28
- else
29
- char.to_s
30
-
31
- end
20
+ out = ''
21
+ out << char.position.to_s
22
+ out << colour_for(char)
23
+ out << style_for(char)
24
+ out << char.value
25
+ out
32
26
  end.join
33
27
  end
34
28
 
@@ -7,7 +7,7 @@ module Vedeu
7
7
 
8
8
  # @return [Vedeu::Background]
9
9
  def background
10
- if colour
10
+ @background ||= if colour
11
11
  colour.background
12
12
 
13
13
  else
@@ -20,7 +20,7 @@ module Vedeu
20
20
  # @return [Vedeu::Background]
21
21
  def background=(value)
22
22
  attributes[:background] = value
23
- colour.background = value
23
+ @background = colour.background = Vedeu::Background.coerce(value)
24
24
  end
25
25
 
26
26
  # @return [Vedeu::Colour]
@@ -36,7 +36,7 @@ module Vedeu
36
36
 
37
37
  # @return [Vedeu::Foreground]
38
38
  def foreground
39
- if colour
39
+ @foreground ||= if colour
40
40
  colour.foreground
41
41
 
42
42
  else
@@ -49,7 +49,7 @@ module Vedeu
49
49
  # @return [Vedeu::Foreground]
50
50
  def foreground=(value)
51
51
  attributes[:foreground] = value
52
- colour.foreground = value
52
+ @foreground = colour.foreground = Vedeu::Foreground.coerce(value)
53
53
  end
54
54
 
55
55
  # @return [Vedeu::Background]
@@ -98,10 +98,17 @@ module Vedeu
98
98
  # model has previously set the colour and style, reverts back to that for
99
99
  # consistent formatting.
100
100
  #
101
+ # @note
102
+ # Aliasing #to_str to #to_s seems to reduce rendering time by around ~20ms
103
+ # for normal sized (80x25) terminals.
104
+ # @todo
105
+ # Must investigate. (GL 2015-06-05)
106
+ #
101
107
  # @return [String] An escape sequence with value interpolated.
102
108
  def to_s
103
109
  render_position { render_colour { render_style { value } } }
104
110
  end
111
+ alias_method :to_str, :to_s
105
112
 
106
113
  private
107
114
 
@@ -110,7 +117,7 @@ module Vedeu
110
117
  if attributes[:colour]
111
118
  attributes[:colour]
112
119
 
113
- elsif parent_colour
120
+ elsif parent && parent_colour
114
121
  parent_colour
115
122
 
116
123
  end
@@ -148,7 +155,7 @@ module Vedeu
148
155
  if attributes[:style]
149
156
  attributes[:style]
150
157
 
151
- elsif parent_style
158
+ elsif parent && parent_style
152
159
  parent_style
153
160
 
154
161
  end
@@ -71,6 +71,7 @@ module Vedeu
71
71
  @sequences ||= Array(value).flatten.map { |v| Vedeu::Esc.string(v) }.join
72
72
  end
73
73
  alias_method :escape_sequences, :to_s
74
+ alias_method :to_str, :to_s
74
75
 
75
76
  end # Style
76
77
 
@@ -93,6 +93,7 @@ module Vedeu
93
93
  end
94
94
  end
95
95
  alias_method :to_s, :escape_sequence
96
+ alias_method :to_str, :escape_sequence
96
97
 
97
98
  # @return [String]
98
99
  def to_html
@@ -56,7 +56,7 @@ module Vedeu
56
56
  out = []
57
57
  show[0...height].each_with_index do |line, iy|
58
58
  line[0...width].each_with_index do |column, ix|
59
- column.position = Vedeu::IndexPosition[iy, ix, by, bx]
59
+ column.position = [by + iy, bx + ix]
60
60
  out << column
61
61
  end
62
62
  end
@@ -70,6 +70,7 @@ module Vedeu
70
70
  def to_s
71
71
  render.map(&:to_s).join("\n")
72
72
  end
73
+ alias_method :to_str, :to_s
73
74
 
74
75
  protected
75
76
 
@@ -90,6 +90,7 @@ module Vedeu
90
90
  def to_s
91
91
  collection.map(&:to_s).join
92
92
  end
93
+ alias_method :to_str, :to_s
93
94
 
94
95
  end # Collection
95
96
 
@@ -101,6 +101,8 @@ module Vedeu
101
101
  #
102
102
  # @return [String]
103
103
  def clear
104
+ virtual.clear if Vedeu::Configuration.drb?
105
+
104
106
  output(Esc.string('clear'))
105
107
  end
106
108
 
@@ -217,13 +219,9 @@ module Vedeu
217
219
  #
218
220
  # @return [Fixnum]
219
221
  def width
220
- if Vedeu::Configuration.drb?
221
- Vedeu::Configuration.drb_width
222
-
223
- else
224
- size.last
222
+ return Vedeu::Configuration.drb_width if Vedeu::Configuration.drb?
225
223
 
226
- end
224
+ size.last
227
225
  end
228
226
  alias_method :xn, :width
229
227
  alias_method :txn, :width
@@ -235,13 +233,9 @@ module Vedeu
235
233
  #
236
234
  # @return [Fixnum]
237
235
  def height
238
- if Vedeu::Configuration.drb?
239
- Vedeu::Configuration.drb_height
236
+ return Vedeu::Configuration.drb_height if Vedeu::Configuration.drb?
240
237
 
241
- else
242
- size.first
243
-
244
- end
238
+ size.first
245
239
  end
246
240
  alias_method :yn, :height
247
241
  alias_method :tyn, :height
@@ -42,8 +42,8 @@ module Vedeu
42
42
  describe '#hide_cursor' do
43
43
  subject { instance.hide_cursor }
44
44
 
45
- it { subject.must_be_instance_of(String) }
46
- it { subject.must_equal("\e[?25l") }
45
+ it { subject.must_be_instance_of(Vedeu::EscapeChar) }
46
+ it { subject.to_s.must_equal("\e[?25l") }
47
47
  end
48
48
 
49
49
  describe '#inspect' do
@@ -58,8 +58,8 @@ module Vedeu
58
58
  describe '#show_cursor' do
59
59
  subject { instance.show_cursor }
60
60
 
61
- it { subject.must_be_instance_of(String) }
62
- it { subject.must_equal("\e[?25h") }
61
+ it { subject.must_be_instance_of(Vedeu::EscapeChar) }
62
+ it { subject.to_s.must_equal("\e[?25h") }
63
63
  end
64
64
 
65
65
  describe '#to_s' do
@@ -96,15 +96,6 @@ module Vedeu
96
96
  it { subject.maximised.must_equal(false) }
97
97
  end
98
98
 
99
- describe '#move' do
100
- let(:dy) {}
101
- let(:dx) {}
102
-
103
- subject { instance.move(dy, dx) }
104
-
105
-
106
- end
107
-
108
99
  describe '#top, #right, #bottom, #left' do
109
100
  context 'maximised is true' do
110
101
  let(:attributes) { { maximised: true } }
@@ -0,0 +1,56 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ describe EscapeChar do
6
+
7
+ let(:described) { Vedeu::EscapeChar }
8
+ let(:instance) { described.new(_value) }
9
+ let(:_value) { "\e[?25h" }
10
+
11
+ describe '#initialize' do
12
+ it { instance.must_be_instance_of(described) }
13
+ it { instance.instance_variable_get('@value').must_equal(_value) }
14
+ end
15
+
16
+ describe '#colour' do
17
+ it { instance.colour.must_equal('') }
18
+ end
19
+
20
+ describe '#eql?' do
21
+ let(:other) { instance }
22
+
23
+ subject { instance.eql?(other) }
24
+
25
+ it { subject.must_equal(true) }
26
+
27
+ context 'when different to other' do
28
+ let(:other) { described.new(value: 'b') }
29
+
30
+ it { subject.must_equal(false) }
31
+ end
32
+ end
33
+
34
+ describe '#inspect' do
35
+ it { instance.inspect.must_equal(
36
+ "<Vedeu::EscapeChar '" \
37
+ "\\e[?25h" \
38
+ "'>"
39
+ ) }
40
+ end
41
+
42
+ describe '#position' do
43
+ it { instance.position.must_equal('') }
44
+ end
45
+
46
+ describe '#style' do
47
+ it { instance.style.must_equal('') }
48
+ end
49
+
50
+ describe '#to_s' do
51
+ it { instance.to_s.must_be_instance_of(String) }
52
+ end
53
+
54
+ end # EscapeChar
55
+
56
+ end # Vedeu