vedeu 0.2.9 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +0 -3
- data/examples/configuration_app.rb +50 -0
- data/examples/cursor_app/cursor_app.rb +8 -3
- data/examples/focus_app.rb +5 -5
- data/examples/hello_world.rb +4 -4
- data/examples/lines_app/lines_app.rb +8 -3
- data/lib/vedeu.rb +2 -0
- data/lib/vedeu/api/api.rb +2 -2
- data/lib/vedeu/application.rb +1 -1
- data/lib/vedeu/configuration/api.rb +24 -9
- data/lib/vedeu/configuration/cli.rb +13 -12
- data/lib/vedeu/configuration/configuration.rb +135 -131
- data/lib/vedeu/input/input.rb +2 -0
- data/lib/vedeu/models/colour.rb +2 -0
- data/lib/vedeu/models/event.rb +8 -0
- data/lib/vedeu/support/log.rb +18 -119
- data/lib/vedeu/support/registrar.rb +12 -3
- data/test/lib/vedeu/api/interface_test.rb +10 -2
- data/test/lib/vedeu/configuration/api_test.rb +13 -5
- data/test/lib/vedeu/configuration/cli_test.rb +88 -78
- data/test/lib/vedeu/configuration/configuration_test.rb +14 -5
- data/test/lib/vedeu/models/menu_test.rb +3 -1
- data/test/lib/vedeu/output/compositor_test.rb +12 -11
- data/test/lib/vedeu/support/position_test.rb +3 -1
- data/test/lib/vedeu/support/refresh_test.rb +2 -2
- data/test/lib/vedeu/support/registrar_test.rb +8 -0
- data/test/lib/vedeu/support/repository_test.rb +8 -3
- data/test/lib/vedeu/support/trace_test.rb +3 -1
- data/test/test_helper.rb +12 -4
- data/vedeu.gemspec +1 -1
- metadata +3 -2
data/lib/vedeu/input/input.rb
CHANGED
data/lib/vedeu/models/colour.rb
CHANGED
data/lib/vedeu/models/event.rb
CHANGED
@@ -134,21 +134,29 @@ module Vedeu
|
|
134
134
|
nil
|
135
135
|
end
|
136
136
|
|
137
|
+
# Return the amount of time in seconds to debounce the event by.
|
138
|
+
#
|
137
139
|
# @return [Fixnum|Float]
|
138
140
|
def debounce
|
139
141
|
options[:debounce] || defaults[:debounce]
|
140
142
|
end
|
141
143
|
|
144
|
+
# Return the amount of time in seconds to throttle the event by.
|
145
|
+
#
|
142
146
|
# @return [Fixnum|Float]
|
143
147
|
def delay
|
144
148
|
options[:delay] || defaults[:delay]
|
145
149
|
end
|
146
150
|
|
151
|
+
# Combines the options provided at instantiation with the default values.
|
152
|
+
#
|
147
153
|
# @return [Hash]
|
148
154
|
def options
|
149
155
|
defaults.merge!(@options)
|
150
156
|
end
|
151
157
|
|
158
|
+
# The default values for a new instance of Event.
|
159
|
+
#
|
152
160
|
# @return [Hash]
|
153
161
|
def defaults
|
154
162
|
{
|
data/lib/vedeu/support/log.rb
CHANGED
@@ -1,137 +1,36 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'time'
|
3
|
-
|
4
1
|
module Vedeu
|
5
2
|
|
6
|
-
#
|
3
|
+
# Provides the ability to log anything to the Vedeu log file.
|
7
4
|
#
|
8
5
|
# @api private
|
9
|
-
class
|
10
|
-
|
11
|
-
# Create a trappable Logger instance.
|
12
|
-
#
|
13
|
-
# @param logdev [String|IO] The filename (String) or IO object (typically
|
14
|
-
# STDOUT, STDERR or an open file).
|
15
|
-
# @param shift_age [] Number of old log files to keep, or frequency of
|
16
|
-
# rotation (daily, weekly, monthly).
|
17
|
-
# @param shift_size [] Maximum log file size (only applies when shift_age
|
18
|
-
# is a number).
|
19
|
-
#
|
20
|
-
# @example
|
21
|
-
# Logger.new(name, shift_age = 7, shift_size = 1048576)
|
22
|
-
# Logger.new(name, shift_age = 'weekly')
|
23
|
-
#
|
24
|
-
def initialize(logdev, shift_age=nil, shift_size=nil)
|
25
|
-
@progname = nil
|
26
|
-
@level = DEBUG
|
27
|
-
@default_formatter = Formatter.new
|
28
|
-
@formatter = nil
|
29
|
-
@logdev = nil
|
30
|
-
if logdev
|
31
|
-
@logdev = LocklessLogDevice.new(logdev)
|
32
|
-
end
|
33
|
-
end
|
6
|
+
class Log
|
34
7
|
|
35
|
-
|
36
|
-
# log device.
|
37
|
-
class LocklessLogDevice < LogDevice
|
8
|
+
class << self
|
38
9
|
|
39
|
-
# @return []
|
40
|
-
def
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
@dev = open_logfile(log)
|
46
|
-
@dev.sync = true
|
47
|
-
@filename = log
|
10
|
+
# @return [TrueClass]
|
11
|
+
def logger
|
12
|
+
Logger.new(Configuration.log).tap do |log|
|
13
|
+
log.formatter = proc do |_, time, _, message|
|
14
|
+
[timestamp(time.utc.iso8601), message, "\n"].join
|
15
|
+
end
|
48
16
|
end
|
49
17
|
end
|
50
18
|
|
51
|
-
# @return []
|
52
|
-
def write(message)
|
53
|
-
@dev.write(message)
|
54
|
-
rescue Exception => ignored
|
55
|
-
warn("log writing failed. #{ignored}")
|
56
|
-
end
|
57
|
-
|
58
|
-
# @return []
|
59
|
-
def close
|
60
|
-
@dev.close rescue nil
|
61
|
-
end
|
62
|
-
|
63
19
|
private
|
64
20
|
|
65
|
-
#
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
72
|
-
end
|
21
|
+
# Returns a formatted (red, underlined) UTC timestamp,
|
22
|
+
# eg. 2014-10-24T12:34:56Z
|
23
|
+
#
|
24
|
+
# @return [String]
|
25
|
+
def timestamp(utc_time)
|
26
|
+
return '' if @last_seen == utc_time
|
73
27
|
|
74
|
-
|
75
|
-
def create_logfile(filename)
|
76
|
-
logdev = open(filename, (File::WRONLY | File::APPEND | File::CREAT))
|
77
|
-
logdev.sync = true
|
78
|
-
add_log_header(logdev)
|
79
|
-
logdev
|
80
|
-
end
|
28
|
+
@last_seen = utc_time
|
81
29
|
|
82
|
-
|
83
|
-
def add_log_header(file)
|
84
|
-
file.write(
|
85
|
-
"# Logfile created on %s by %s\n" % [Time.now.to_s, Logger::ProgName]
|
86
|
-
)
|
30
|
+
"\n\e[4m\e[31m" + utc_time + "\e[39m\e[24m\n"
|
87
31
|
end
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
# Provides the ability to Log anything to the Vedeu log file which is
|
93
|
-
# hard-coded to reside in `$HOME/.vedeu/vedeu.log`.
|
94
|
-
#
|
95
|
-
# @api private
|
96
|
-
class Log
|
97
|
-
|
98
|
-
# @return [TrueClass]
|
99
|
-
def self.logger
|
100
|
-
@logger ||= MonoLogger.new(filename).tap do |log|
|
101
|
-
log.formatter = proc do |_, time, _, message|
|
102
|
-
utc_time = time.utc.iso8601
|
103
|
-
|
104
|
-
[timestamp(utc_time), message, "\n"].join
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
private
|
110
|
-
|
111
|
-
def self.timestamp(utc_time)
|
112
|
-
return "" if @last_seen == utc_time
|
113
|
-
|
114
|
-
@last_seen = utc_time
|
115
|
-
|
116
|
-
"\n\e[4m\e[31m" + utc_time + "\e[39m\e[24m\n"
|
117
|
-
end
|
118
|
-
|
119
|
-
# @return [String]
|
120
|
-
def self.filename
|
121
|
-
@_filename ||= directory + '/vedeu.log'
|
122
|
-
end
|
123
|
-
|
124
|
-
# @return [String]
|
125
|
-
def self.directory
|
126
|
-
FileUtils.mkdir_p(path) unless File.directory?(path)
|
127
|
-
|
128
|
-
path
|
129
|
-
end
|
130
32
|
|
131
|
-
#
|
132
|
-
def self.path
|
133
|
-
Dir.home + '/.vedeu'
|
134
|
-
end
|
33
|
+
end # Log eigenclass
|
135
34
|
|
136
35
|
end # Log
|
137
36
|
|
@@ -6,12 +6,23 @@ module Vedeu
|
|
6
6
|
# @api private
|
7
7
|
class Registrar
|
8
8
|
|
9
|
+
REPOSITORIES = [Buffers, Cursors, Focus, Groups, Interfaces, Offsets]
|
10
|
+
|
9
11
|
# @param attributes [Hash]
|
10
12
|
# @return [TrueClass|MissingRequired]
|
11
13
|
def self.record(attributes = {})
|
12
14
|
new(attributes).record
|
13
15
|
end
|
14
16
|
|
17
|
+
# Removes all entities from all repositories. Use with caution.
|
18
|
+
#
|
19
|
+
# @return [TrueClass]
|
20
|
+
def self.reset!
|
21
|
+
REPOSITORIES.each { |repository| repository.reset }
|
22
|
+
|
23
|
+
true
|
24
|
+
end
|
25
|
+
|
15
26
|
# @param attributes [Hash]
|
16
27
|
# @return [Registrar]
|
17
28
|
def initialize(attributes = {})
|
@@ -22,9 +33,7 @@ module Vedeu
|
|
22
33
|
#
|
23
34
|
# @return [TrueClass|MissingRequired]
|
24
35
|
def record
|
25
|
-
|
26
|
-
repository.add(attributes)
|
27
|
-
end
|
36
|
+
REPOSITORIES.each { |repository| repository.add(attributes) }
|
28
37
|
|
29
38
|
true
|
30
39
|
end
|
@@ -361,7 +361,11 @@ module Vedeu
|
|
361
361
|
|
362
362
|
describe '#x' do
|
363
363
|
it 'sets the attribute to the block if a block is given' do
|
364
|
-
|
364
|
+
Vedeu.interface 'iron' do
|
365
|
+
x { 9 }
|
366
|
+
end
|
367
|
+
|
368
|
+
Vedeu.use('iron').geometry.x.must_equal(9)
|
365
369
|
end
|
366
370
|
|
367
371
|
it 'sets the attribute to the value if a block is not given' do
|
@@ -375,7 +379,11 @@ module Vedeu
|
|
375
379
|
|
376
380
|
describe '#y' do
|
377
381
|
it 'sets the attribute to the block if a block is given' do
|
378
|
-
|
382
|
+
Vedeu.interface 'iron' do
|
383
|
+
y { 6 }
|
384
|
+
end
|
385
|
+
|
386
|
+
Vedeu.use('iron').geometry.y.must_equal(6)
|
379
387
|
end
|
380
388
|
|
381
389
|
it 'sets the attribute to the value if a block is not given' do
|
@@ -2,12 +2,12 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module Vedeu
|
4
4
|
|
5
|
-
module
|
5
|
+
module Config
|
6
6
|
|
7
7
|
describe API do
|
8
8
|
|
9
|
-
before { Configuration.reset }
|
10
|
-
after {
|
9
|
+
before { Configuration.reset! }
|
10
|
+
after { test_configuration }
|
11
11
|
|
12
12
|
describe '.configure' do
|
13
13
|
it 'returns the default configuration' do
|
@@ -15,9 +15,10 @@ module Vedeu
|
|
15
15
|
# ...
|
16
16
|
end.must_equal(
|
17
17
|
{
|
18
|
-
colour_mode:
|
18
|
+
colour_mode: 256,
|
19
19
|
debug: false,
|
20
20
|
interactive: true,
|
21
|
+
log: '/tmp/vedeu.log',
|
21
22
|
once: false,
|
22
23
|
system_keys: {
|
23
24
|
exit: 'q',
|
@@ -208,6 +209,13 @@ module Vedeu
|
|
208
209
|
end
|
209
210
|
end
|
210
211
|
|
212
|
+
describe '#log' do
|
213
|
+
it 'sets the options to the desired value' do
|
214
|
+
configuration = Vedeu.configure { log('/tmp/vedeu_api_test.log') }
|
215
|
+
configuration[:log].must_equal('/tmp/vedeu_api_test.log')
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
211
219
|
describe 'redefining system keys' do
|
212
220
|
methods_and_keys = {
|
213
221
|
exit_key: :exit,
|
@@ -245,6 +253,6 @@ module Vedeu
|
|
245
253
|
|
246
254
|
end # API
|
247
255
|
|
248
|
-
end #
|
256
|
+
end # Config
|
249
257
|
|
250
258
|
end # Vedeu
|
@@ -2,89 +2,99 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module Vedeu
|
4
4
|
|
5
|
-
module
|
5
|
+
module Config
|
6
6
|
|
7
7
|
describe CLI do
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
#
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
#
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
#
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
#
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
#
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
#
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
9
|
+
before { Configuration.reset! }
|
10
|
+
after { test_configuration }
|
11
|
+
|
12
|
+
describe '#colour_mode' do
|
13
|
+
it '--colour-mode' do
|
14
|
+
Configuration.configure(['--colour-mode', '16777216'])
|
15
|
+
Configuration.colour_mode.must_equal(16777216)
|
16
|
+
end
|
17
|
+
|
18
|
+
it '--colour-mode' do
|
19
|
+
Configuration.configure(['--colour-mode', '256'])
|
20
|
+
Configuration.colour_mode.must_equal(256)
|
21
|
+
end
|
22
|
+
|
23
|
+
it '--colour-mode' do
|
24
|
+
Configuration.configure(['--colour-mode', '16'])
|
25
|
+
Configuration.colour_mode.must_equal(16)
|
26
|
+
end
|
27
|
+
|
28
|
+
it '--colour-mode' do
|
29
|
+
Configuration.configure(['--colour-mode', '348'])
|
30
|
+
Configuration.colour_mode.must_equal(8)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#debug?' do
|
35
|
+
it '--debug' do
|
36
|
+
Configuration.configure(['--debug'])
|
37
|
+
Configuration.debug?.must_equal(true)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#interactive?' do
|
42
|
+
it '--interactive' do
|
43
|
+
Configuration.configure(['--interactive'])
|
44
|
+
Configuration.interactive?.must_equal(true)
|
45
|
+
end
|
46
|
+
|
47
|
+
it '--noninteractive' do
|
48
|
+
Configuration.configure(['--noninteractive'])
|
49
|
+
Configuration.interactive?.must_equal(false)
|
50
|
+
end
|
51
|
+
|
52
|
+
it '--standalone' do
|
53
|
+
Configuration.configure(['--standalone'])
|
54
|
+
Configuration.interactive?.must_equal(false)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#log' do
|
59
|
+
it '--log' do
|
60
|
+
Configuration.configure(['--log', '/tmp/vedeu_cli_test.log'])
|
61
|
+
Configuration.log.must_equal('/tmp/vedeu_cli_test.log')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#once?' do
|
66
|
+
it '--run-once' do
|
67
|
+
Configuration.configure(['--run-once'])
|
68
|
+
Configuration.once?.must_equal(true)
|
69
|
+
end
|
70
|
+
|
71
|
+
it '--run-many' do
|
72
|
+
Configuration.configure(['--run-many'])
|
73
|
+
Configuration.once?.must_equal(false)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '#terminal_mode' do
|
78
|
+
it '--cooked' do
|
79
|
+
Configuration.configure(['--cooked'])
|
80
|
+
Configuration.terminal_mode.must_equal(:cooked)
|
81
|
+
end
|
82
|
+
|
83
|
+
it '--raw' do
|
84
|
+
Configuration.configure(['--raw'])
|
85
|
+
Configuration.terminal_mode.must_equal(:raw)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe '#trace?' do
|
90
|
+
it '--trace' do
|
91
|
+
Configuration.configure(['--trace'])
|
92
|
+
Configuration.trace?.must_equal(true)
|
93
|
+
end
|
94
|
+
end
|
85
95
|
|
86
96
|
end # CLI
|
87
97
|
|
88
|
-
end #
|
98
|
+
end # Config
|
89
99
|
|
90
100
|
end # Vedeu
|