vedeu 0.6.51 → 0.6.52
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vedeu/borders/refresh.rb +1 -0
- data/lib/vedeu/buffers/all.rb +2 -0
- data/lib/vedeu/buffers/empty.rb +78 -0
- data/lib/vedeu/buffers/view.rb +51 -0
- data/lib/vedeu/colours/colour.rb +24 -12
- data/lib/vedeu/editor/cropper.rb +1 -1
- data/lib/vedeu/editor/cursor.rb +6 -2
- data/lib/vedeu/editor/document.rb +50 -32
- data/lib/vedeu/esc/actions.rb +0 -7
- data/lib/vedeu/esc/borders.rb +0 -7
- data/lib/vedeu/esc/colours.rb +0 -2
- data/lib/vedeu/esc/mouse.rb +0 -7
- data/lib/vedeu/events/event.rb +2 -2
- data/lib/vedeu/interfaces/clear.rb +1 -0
- data/lib/vedeu/logging/all.rb +1 -0
- data/lib/vedeu/logging/clock_time.rb +34 -0
- data/lib/vedeu/logging/log.rb +20 -18
- data/lib/vedeu/logging/timer.rb +2 -2
- data/lib/vedeu/models/cell.rb +10 -0
- data/lib/vedeu/models/views/char.rb +12 -0
- data/lib/vedeu/models/views/line.rb +5 -0
- data/lib/vedeu/models/views/stream.rb +6 -0
- data/lib/vedeu/output/compressor.rb +31 -2
- data/lib/vedeu/output/output.rb +25 -2
- data/lib/vedeu/output/presentation/colour.rb +9 -0
- data/lib/vedeu/output/presentation/styles.rb +3 -0
- data/lib/vedeu/output/renderers/file.rb +1 -1
- data/lib/vedeu/version.rb +1 -1
- data/test/lib/vedeu/buffers/empty_test.rb +87 -0
- data/test/lib/vedeu/buffers/view_test.rb +36 -0
- data/test/lib/vedeu/colours/colour_test.rb +10 -13
- data/test/lib/vedeu/editor/cursor_test.rb +23 -5
- data/test/lib/vedeu/interfaces/clear_test.rb +4 -6
- data/test/lib/vedeu/logging/clock_time_test.rb +13 -0
- data/test/lib/vedeu/logging/timer_test.rb +3 -5
- data/test/lib/vedeu/models/cell_test.rb +16 -0
- data/test/lib/vedeu/models/views/char_test.rb +18 -0
- data/test/lib/vedeu/models/views/html_char_test.rb +30 -17
- data/test/lib/vedeu/models/views/line_test.rb +14 -0
- data/test/lib/vedeu/models/views/stream_test.rb +14 -0
- data/test/lib/vedeu/output/compressor_test.rb +43 -21
- data/test/lib/vedeu/output/renderers/json_test.rb +4 -1
- data/test/lib/vedeu/output/renderers/terminal_test.rb +4 -3
- data/test/lib/vedeu/templating/encoder_test.rb +1 -1
- data/test/lib/vedeu/templating/helpers_test.rb +6 -6
- data/vedeu.gemspec +1 -1
- metadata +13 -4
data/lib/vedeu/esc/borders.rb
CHANGED
data/lib/vedeu/esc/colours.rb
CHANGED
data/lib/vedeu/esc/mouse.rb
CHANGED
data/lib/vedeu/events/event.rb
CHANGED
@@ -213,7 +213,7 @@ module Vedeu
|
|
213
213
|
#
|
214
214
|
# @return [Boolean]
|
215
215
|
def throttling?
|
216
|
-
@now =
|
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 =
|
241
|
+
@now = Vedeu.clock_time
|
242
242
|
|
243
243
|
@deadline = @now + debounce unless deadline?
|
244
244
|
|
data/lib/vedeu/logging/all.rb
CHANGED
@@ -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
|
data/lib/vedeu/logging/log.rb
CHANGED
@@ -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
|
|
data/lib/vedeu/logging/timer.rb
CHANGED
@@ -35,7 +35,7 @@ module Vedeu
|
|
35
35
|
# @return [Vedeu::Logging::Timer]
|
36
36
|
def initialize(message = '')
|
37
37
|
@message = message
|
38
|
-
@started =
|
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
|
-
((
|
78
|
+
((Vedeu.clock_time - started) * 1000).round(3)
|
79
79
|
end
|
80
80
|
|
81
81
|
end # Timer
|
data/lib/vedeu/models/cell.rb
CHANGED
@@ -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,
|
@@ -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}
|
61
|
+
Vedeu.timer("Compression for #{content.size} objects".freeze) do
|
62
62
|
out = ''
|
63
63
|
|
64
64
|
content.each do |cell|
|
65
|
-
out << cell
|
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)
|
data/lib/vedeu/output/output.rb
CHANGED
@@ -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
|
-
:
|
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
|
|