vedeu 0.6.51 → 0.6.52

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vedeu/borders/refresh.rb +1 -0
  3. data/lib/vedeu/buffers/all.rb +2 -0
  4. data/lib/vedeu/buffers/empty.rb +78 -0
  5. data/lib/vedeu/buffers/view.rb +51 -0
  6. data/lib/vedeu/colours/colour.rb +24 -12
  7. data/lib/vedeu/editor/cropper.rb +1 -1
  8. data/lib/vedeu/editor/cursor.rb +6 -2
  9. data/lib/vedeu/editor/document.rb +50 -32
  10. data/lib/vedeu/esc/actions.rb +0 -7
  11. data/lib/vedeu/esc/borders.rb +0 -7
  12. data/lib/vedeu/esc/colours.rb +0 -2
  13. data/lib/vedeu/esc/mouse.rb +0 -7
  14. data/lib/vedeu/events/event.rb +2 -2
  15. data/lib/vedeu/interfaces/clear.rb +1 -0
  16. data/lib/vedeu/logging/all.rb +1 -0
  17. data/lib/vedeu/logging/clock_time.rb +34 -0
  18. data/lib/vedeu/logging/log.rb +20 -18
  19. data/lib/vedeu/logging/timer.rb +2 -2
  20. data/lib/vedeu/models/cell.rb +10 -0
  21. data/lib/vedeu/models/views/char.rb +12 -0
  22. data/lib/vedeu/models/views/line.rb +5 -0
  23. data/lib/vedeu/models/views/stream.rb +6 -0
  24. data/lib/vedeu/output/compressor.rb +31 -2
  25. data/lib/vedeu/output/output.rb +25 -2
  26. data/lib/vedeu/output/presentation/colour.rb +9 -0
  27. data/lib/vedeu/output/presentation/styles.rb +3 -0
  28. data/lib/vedeu/output/renderers/file.rb +1 -1
  29. data/lib/vedeu/version.rb +1 -1
  30. data/test/lib/vedeu/buffers/empty_test.rb +87 -0
  31. data/test/lib/vedeu/buffers/view_test.rb +36 -0
  32. data/test/lib/vedeu/colours/colour_test.rb +10 -13
  33. data/test/lib/vedeu/editor/cursor_test.rb +23 -5
  34. data/test/lib/vedeu/interfaces/clear_test.rb +4 -6
  35. data/test/lib/vedeu/logging/clock_time_test.rb +13 -0
  36. data/test/lib/vedeu/logging/timer_test.rb +3 -5
  37. data/test/lib/vedeu/models/cell_test.rb +16 -0
  38. data/test/lib/vedeu/models/views/char_test.rb +18 -0
  39. data/test/lib/vedeu/models/views/html_char_test.rb +30 -17
  40. data/test/lib/vedeu/models/views/line_test.rb +14 -0
  41. data/test/lib/vedeu/models/views/stream_test.rb +14 -0
  42. data/test/lib/vedeu/output/compressor_test.rb +43 -21
  43. data/test/lib/vedeu/output/renderers/json_test.rb +4 -1
  44. data/test/lib/vedeu/output/renderers/terminal_test.rb +4 -3
  45. data/test/lib/vedeu/templating/encoder_test.rb +1 -1
  46. data/test/lib/vedeu/templating/helpers_test.rb +6 -6
  47. data/vedeu.gemspec +1 -1
  48. metadata +13 -4
@@ -51,13 +51,6 @@ module Vedeu
51
51
 
52
52
  # @return [void]
53
53
  def setup!
54
- define_borders!
55
- end
56
-
57
- private
58
-
59
- # @return [void]
60
- def define_borders!
61
54
  characters.each { |key, code| define_method(key) { code } }
62
55
  end
63
56
 
@@ -74,8 +74,6 @@ module Vedeu
74
74
  define_foregrounds!
75
75
  end
76
76
 
77
- private
78
-
79
77
  # @return [void]
80
78
  def define_backgrounds!
81
79
  background_codes.each do |key, code|
@@ -42,13 +42,6 @@ module Vedeu
42
42
 
43
43
  # @return [void]
44
44
  def setup!
45
- define_actions!
46
- end
47
-
48
- private
49
-
50
- # @return [void]
51
- def define_actions!
52
45
  mouse_codes.each { |key, code| define_method(key) { code } }
53
46
  end
54
47
 
@@ -213,7 +213,7 @@ module Vedeu
213
213
  #
214
214
  # @return [Boolean]
215
215
  def throttling?
216
- @now = Time.now.to_f
216
+ @now = Vedeu.clock_time
217
217
 
218
218
  options[:delay] > 0
219
219
  end
@@ -238,7 +238,7 @@ module Vedeu
238
238
  #
239
239
  # @return [Boolean]
240
240
  def debouncing?
241
- @now = Time.now.to_f
241
+ @now = Vedeu.clock_time
242
242
 
243
243
  @deadline = @now + debounce unless deadline?
244
244
 
@@ -167,6 +167,7 @@ module Vedeu
167
167
  Array.new(width) do |ix|
168
168
  Vedeu::Views::Char.new(value: ' '.freeze,
169
169
  colour: colour,
170
+ name: name,
170
171
  position: [y + iy, x + ix])
171
172
  end
172
173
  end
@@ -9,6 +9,7 @@ module Vedeu
9
9
 
10
10
  end # Vedeu
11
11
 
12
+ require 'vedeu/logging/clock_time'
12
13
  require 'vedeu/logging/lockless_log_device'
13
14
  require 'vedeu/logging/mono_logger'
14
15
  require 'vedeu/logging/log'
@@ -0,0 +1,34 @@
1
+ module Vedeu
2
+
3
+ module Logging
4
+
5
+ # If the system supports Process::CLOCK_MONOTONIC use that for
6
+ # timestamps.
7
+ #
8
+ # Vedeu.clock_time # => 15217.232113 (Process::CLOCK_MONOTONIC)
9
+ # # => 1447196800.3098037 (Time.now)
10
+ #
11
+ module ClockTime
12
+
13
+ if defined?(Process::CLOCK_MONOTONIC)
14
+ def self.clock_time
15
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
16
+ end
17
+
18
+ else
19
+ def self.clock_time
20
+ Time.now
21
+ end
22
+
23
+ end
24
+
25
+ end # ClockTime
26
+
27
+ end # Logging
28
+
29
+ # @!method clock_time
30
+ # @see Vedeu::Logging::ClockTime
31
+ def_delegators Vedeu::Logging::ClockTime,
32
+ :clock_time
33
+
34
+ end # Vedeu
@@ -54,6 +54,24 @@ module Vedeu
54
54
  $stderr.puts log_entry(type, message)
55
55
  end
56
56
 
57
+ # Returns a formatted timestamp.
58
+ # eg. [137.7824]
59
+ #
60
+ # @return [String]
61
+ def timestamp
62
+ @now = Vedeu.clock_time
63
+ @time ||= 0.0
64
+ @last ||= @now
65
+
66
+ unless @last == @time
67
+ @time += (@now - @last).round(4)
68
+ @last = @now
69
+ end
70
+
71
+ "[#{format('%7.4f', @time.to_s)}] ".rjust(7)
72
+ end
73
+ alias_method :log_timestamp, :timestamp
74
+
57
75
  private
58
76
 
59
77
  # @return [TrueClass]
@@ -163,23 +181,6 @@ module Vedeu
163
181
  }
164
182
  end
165
183
 
166
- # Returns a formatted timestamp.
167
- # eg. [137.7824]
168
- #
169
- # @return [String]
170
- def timestamp
171
- @now = Time.now.to_f
172
- @time ||= 0.0
173
- @last ||= @now
174
-
175
- unless @last == @time
176
- @time += (@now - @last).round(4)
177
- @last = @now
178
- end
179
-
180
- "[#{format('%7.4f', @time.to_s)}] ".rjust(7)
181
- end
182
-
183
184
  end # Eigenclass
184
185
 
185
186
  end # Log
@@ -195,7 +196,8 @@ module Vedeu
195
196
  def_delegators Vedeu::Logging::Log,
196
197
  :log,
197
198
  :log_stdout,
198
- :log_stderr
199
+ :log_stderr,
200
+ :log_timestamp
199
201
 
200
202
  # :nocov:
201
203
 
@@ -35,7 +35,7 @@ module Vedeu
35
35
  # @return [Vedeu::Logging::Timer]
36
36
  def initialize(message = '')
37
37
  @message = message
38
- @started = Time.now.to_f
38
+ @started = Vedeu.clock_time
39
39
  end
40
40
 
41
41
  # Write an entry to the log file stating how long a section of
@@ -75,7 +75,7 @@ module Vedeu
75
75
  #
76
76
  # @return [Float]
77
77
  def elapsed
78
- ((Time.now.to_f - started) * 1000).round(3)
78
+ ((Vedeu.clock_time - started) * 1000).round(3)
79
79
  end
80
80
 
81
81
  end # Timer
@@ -12,6 +12,10 @@ module Vedeu
12
12
  # @return [NilClass|String]
13
13
  attr_reader :colour
14
14
 
15
+ # @!attribute [r] name
16
+ # @return [String|Symbol]
17
+ attr_reader :name
18
+
15
19
  # @!attribute [r] style
16
20
  # @return [NilClass|Array<Symbol|String>|Symbol|String]
17
21
  attr_reader :style
@@ -56,6 +60,11 @@ module Vedeu
56
60
  end
57
61
  alias_method :==, :eql?
58
62
 
63
+ # @return [Vedeu::Interfaces::Interface]
64
+ def interface
65
+ @interface ||= Vedeu.interfaces.by_name(name)
66
+ end
67
+
59
68
  # @return [Vedeu::Geometry::Position]
60
69
  def position
61
70
  Vedeu::Geometry::Position.coerce(@position)
@@ -90,6 +99,7 @@ module Vedeu
90
99
  def defaults
91
100
  {
92
101
  colour: nil,
102
+ name: nil,
93
103
  style: nil,
94
104
  value: '',
95
105
  position: [1, 1],
@@ -30,6 +30,10 @@ module Vedeu
30
30
  # @return [NilClass|Symbol]
31
31
  attr_accessor :border
32
32
 
33
+ # @!attribute [rw] name
34
+ # @return [String|Symbol]
35
+ attr_accessor :name
36
+
33
37
  # @!attribute [rw] parent
34
38
  # @return [Vedeu::Views::Line]
35
39
  attr_accessor :parent
@@ -45,6 +49,7 @@ module Vedeu
45
49
  # A symbol representing the border 'piece' this
46
50
  # {Vedeu::Views::Char} represents.
47
51
  # @option attributes colour [Vedeu::Colours::Colour]
52
+ # @option attributes name [String|Symbol]
48
53
  # @option attributes parent [Vedeu::Views::Line]
49
54
  # @option attributes position [Vedeu::Geometry::Position]
50
55
  # @option attributes style [Vedeu::Presentation::Style]
@@ -53,6 +58,7 @@ module Vedeu
53
58
  def initialize(attributes = {})
54
59
  @attributes = attributes
55
60
  @border = @attributes[:border]
61
+ @name = @attributes[:name]
56
62
  @parent = @attributes[:parent]
57
63
  @value = @attributes[:value]
58
64
  end
@@ -83,6 +89,11 @@ module Vedeu
83
89
  end
84
90
  alias_method :==, :eql?
85
91
 
92
+ # @return [Vedeu::Interfaces::Interface]
93
+ def interface
94
+ @interface ||= Vedeu.interfaces.by_name(name)
95
+ end
96
+
86
97
  # @return [Vedeu::Geometry::Position]
87
98
  def position
88
99
  @position = Vedeu::Geometry::Position.coerce(@attributes[:position])
@@ -130,6 +141,7 @@ module Vedeu
130
141
  {
131
142
  border: border.to_s,
132
143
  colour: colour_to_hash,
144
+ name: name.to_s,
133
145
  parent: parent_to_hash,
134
146
  position: position_to_hash,
135
147
  style: style.to_s,
@@ -86,6 +86,11 @@ module Vedeu
86
86
  end
87
87
  alias_method :==, :eql?
88
88
 
89
+ # @return [NilClass|String|Symbol]
90
+ def name
91
+ parent.name if parent
92
+ end
93
+
89
94
  # Returns the size of the content in characters without
90
95
  # formatting.
91
96
  #
@@ -71,6 +71,7 @@ module Vedeu
71
71
 
72
72
  @chars ||= value.chars.map do |char|
73
73
  member.new(value: char,
74
+ name: name,
74
75
  parent: parent,
75
76
  colour: colour,
76
77
  style: style,
@@ -101,6 +102,11 @@ module Vedeu
101
102
  end
102
103
  alias_method :==, :eql?
103
104
 
105
+ # @return [NilClass|String|Symbol]
106
+ def name
107
+ parent.name if parent
108
+ end
109
+
104
110
  # Returns the size of the content in characters without
105
111
  # formatting.
106
112
  #
@@ -58,16 +58,20 @@ module Vedeu
58
58
 
59
59
  # @return [String]
60
60
  def compress
61
- Vedeu.timer("Compression for #{content.size} characters".freeze) do
61
+ Vedeu.timer("Compression for #{content.size} objects".freeze) do
62
62
  out = ''
63
63
 
64
64
  content.each do |cell|
65
- out << cell.position.to_s
65
+ out << position_for(cell)
66
66
  out << colour_for(cell)
67
67
  out << style_for(cell)
68
68
  out << cell.value
69
69
  end
70
70
 
71
+ Vedeu.log(type: :output,
72
+ message: "Compression: #{content.size} objects -> " \
73
+ "#{out.size} characters".freeze)
74
+
71
75
  out
72
76
  end
73
77
  end
@@ -80,9 +84,30 @@ module Vedeu
80
84
  out << cell.to_s
81
85
  end
82
86
 
87
+ Vedeu.log(type: :output,
88
+ message: "No compression: #{content.size} objects -> " \
89
+ "#{out.size} characters".freeze)
90
+
83
91
  out
84
92
  end
85
93
 
94
+ # Compress by not repeatedly sending a position when only the x
95
+ # coordinate has changed; i.e. we are on the same line, just
96
+ # advancing a character.
97
+ #
98
+ # @param char [Vedeu::Views::Char]
99
+ # @return [String]
100
+ def position_for(char)
101
+ return ''.freeze if char.position.y == @y
102
+
103
+ @y = char.position.y
104
+ char.position.to_s
105
+ end
106
+
107
+ # Compress by not repeatedly sending the same colours for each
108
+ # character which has the same colours as the last character
109
+ # output.
110
+ #
86
111
  # @param char [Vedeu::Views::Char]
87
112
  # @return [String]
88
113
  def colour_for(char)
@@ -92,6 +117,10 @@ module Vedeu
92
117
  @colour.to_s
93
118
  end
94
119
 
120
+ # Compress by not repeatedly sending the same style(s) for each
121
+ # character which has the same style(s) as the last character
122
+ # output.
123
+ #
95
124
  # @param char [Vedeu::Views::Char]
96
125
  # @return [String]
97
126
  def style_for(char)
@@ -9,6 +9,15 @@ module Vedeu
9
9
  #
10
10
  class Output
11
11
 
12
+ # @param output [Array<Array<Vedeu::Views::Char>>|
13
+ # NilClass|Vedeu::Models::Escape]
14
+ # @return [Array]
15
+ def self.buffer_update(output)
16
+ return nil if output.nil?
17
+
18
+ new(output).buffer_update
19
+ end
20
+
12
21
  # @param output [Array<Array<Vedeu::Views::Char>>|
13
22
  # NilClass|Vedeu::Models::Escape]
14
23
  # @return [Array]
@@ -47,6 +56,11 @@ module Vedeu
47
56
  @output = output
48
57
  end
49
58
 
59
+ # @return [Array]
60
+ def buffer_update
61
+ buffer_update!
62
+ end
63
+
50
64
  # @return [Array]
51
65
  def buffer_write
52
66
  buffer_write!
@@ -84,6 +98,11 @@ module Vedeu
84
98
 
85
99
  private
86
100
 
101
+ # @return [Array]
102
+ def buffer_update!
103
+ Vedeu::Terminal::Buffer.update(output)
104
+ end
105
+
87
106
  # @return [Array]
88
107
  def buffer_write!
89
108
  Vedeu::Terminal::Buffer.write(output)
@@ -106,13 +125,17 @@ module Vedeu
106
125
  # Write the given output to the configured or default renderers.
107
126
  #
108
127
  # @example
128
+ # Vedeu.buffer_update(output)
129
+ # Vedeu.buffer_write(output)
130
+ # Vedeu.direct_write(output)
109
131
  # Vedeu.render_output(output)
110
132
  #
111
133
  # @!method render_output
112
134
  # @return [Array|NilClass]
113
135
  def_delegators Vedeu::Output::Output,
114
- :render_output,
136
+ :buffer_update,
115
137
  :buffer_write,
116
- :direct_write
138
+ :direct_write,
139
+ :render_output
117
140
 
118
141
  end # Vedeu
@@ -15,6 +15,9 @@ module Vedeu
15
15
  @background ||= if colour
16
16
  colour.background
17
17
 
18
+ elsif self.is_a?(Vedeu::Views::Char) && name
19
+ interface.colour.background
20
+
18
21
  elsif parent
19
22
  parent.background
20
23
 
@@ -39,6 +42,9 @@ module Vedeu
39
42
  @colour ||= if attributes[:colour]
40
43
  Vedeu::Colours::Colour.coerce(attributes[:colour])
41
44
 
45
+ elsif self.is_a?(Vedeu::Views::Char) && name
46
+ Vedeu::Colours::Colour.coerce(interface.colour)
47
+
42
48
  elsif parent
43
49
  Vedeu::Colours::Colour.coerce(parent.colour)
44
50
 
@@ -65,6 +71,9 @@ module Vedeu
65
71
  @foreground ||= if colour
66
72
  colour.foreground
67
73
 
74
+ elsif self.is_a?(Vedeu::Views::Char) && name
75
+ interface.colour.background
76
+
68
77
  elsif parent
69
78
  parent.foreground
70
79