vedeu 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/docs/api.md +2 -0
- data/docs/events.md +0 -4
- data/examples/cursor_app/cursor_app.rb +56 -44
- data/lib/vedeu/api/api.rb +4 -6
- data/lib/vedeu/api/composition.rb +3 -7
- data/lib/vedeu/api/interface.rb +2 -3
- data/lib/vedeu/api/menu.rb +5 -3
- data/lib/vedeu/api/stream.rb +34 -0
- data/lib/vedeu/application.rb +4 -7
- data/lib/vedeu/configuration/api.rb +0 -5
- data/lib/vedeu/configuration/cli.rb +0 -1
- data/lib/vedeu/configuration/configuration.rb +0 -12
- data/lib/vedeu/input/input.rb +0 -3
- data/lib/vedeu/launcher.rb +0 -1
- data/lib/vedeu/models/{attributes/background.rb → background.rb} +0 -4
- data/lib/vedeu/models/char.rb +43 -0
- data/lib/vedeu/models/colour.rb +0 -1
- data/lib/vedeu/models/composition.rb +4 -3
- data/lib/vedeu/models/cursor.rb +70 -146
- data/lib/vedeu/models/{attributes/foreground.rb → foreground.rb} +0 -4
- data/lib/vedeu/models/geometry.rb +19 -20
- data/lib/vedeu/models/interface.rb +36 -5
- data/lib/vedeu/models/keymap.rb +7 -4
- data/lib/vedeu/models/line.rb +31 -11
- data/lib/vedeu/models/offset.rb +84 -0
- data/lib/vedeu/models/stream.rb +37 -13
- data/lib/vedeu/models/style.rb +0 -1
- data/lib/vedeu/output/area.rb +284 -0
- data/lib/vedeu/output/clear.rb +2 -4
- data/lib/vedeu/output/compositor.rb +0 -4
- data/lib/vedeu/output/refresh.rb +1 -2
- data/lib/vedeu/output/render.rb +12 -163
- data/lib/vedeu/output/view.rb +0 -2
- data/lib/vedeu/output/viewport.rb +132 -0
- data/lib/vedeu/repositories/buffers.rb +11 -22
- data/lib/vedeu/repositories/cursors.rb +20 -47
- data/lib/vedeu/repositories/events.rb +2 -1
- data/lib/vedeu/repositories/focus.rb +16 -16
- data/lib/vedeu/repositories/groups.rb +1 -4
- data/lib/vedeu/repositories/interfaces.rb +10 -3
- data/lib/vedeu/repositories/keymaps.rb +0 -3
- data/lib/vedeu/repositories/menus.rb +0 -2
- data/lib/vedeu/repositories/offsets.rb +47 -0
- data/lib/vedeu/{models/attributes → support}/coercions.rb +0 -0
- data/lib/vedeu/{models/attributes → support}/colour_translator.rb +0 -16
- data/lib/vedeu/support/esc.rb +0 -22
- data/lib/vedeu/support/event.rb +1 -17
- data/lib/vedeu/support/exceptions.rb +0 -3
- data/lib/vedeu/support/grid.rb +0 -3
- data/lib/vedeu/support/log.rb +13 -14
- data/lib/vedeu/support/move.rb +50 -0
- data/lib/vedeu/support/position.rb +17 -9
- data/lib/vedeu/{models/attributes → support}/presentation.rb +1 -4
- data/lib/vedeu/support/registrar.rb +2 -2
- data/lib/vedeu/support/repository.rb +23 -2
- data/lib/vedeu/support/terminal.rb +0 -2
- data/lib/vedeu/support/trace.rb +0 -11
- data/lib/vedeu.rb +11 -5
- data/test/lib/vedeu/api/api_test.rb +14 -5
- data/test/lib/vedeu/api/composition_test.rb +9 -26
- data/test/lib/vedeu/api/keymap_test.rb +1 -1
- data/test/lib/vedeu/api/menu_test.rb +6 -0
- data/test/lib/vedeu/api/stream_test.rb +32 -0
- data/test/lib/vedeu/models/{attributes/background_test.rb → background_test.rb} +0 -0
- data/test/lib/vedeu/models/char_test.rb +46 -0
- data/test/lib/vedeu/models/composition_test.rb +7 -0
- data/test/lib/vedeu/models/cursor_test.rb +63 -80
- data/test/lib/vedeu/models/{attributes/foreground_test.rb → foreground_test.rb} +0 -0
- data/test/lib/vedeu/models/geometry_test.rb +8 -10
- data/test/lib/vedeu/models/interface_test.rb +26 -21
- data/test/lib/vedeu/models/keymap_test.rb +6 -0
- data/test/lib/vedeu/models/line_test.rb +82 -3
- data/test/lib/vedeu/models/offset_test.rb +121 -0
- data/test/lib/vedeu/models/stream_test.rb +107 -8
- data/test/lib/vedeu/output/area_test.rb +242 -0
- data/test/lib/vedeu/output/compositor_test.rb +12 -3
- data/test/lib/vedeu/output/render_test.rb +34 -39
- data/test/lib/vedeu/output/viewport_test.rb +36 -0
- data/test/lib/vedeu/repositories/cursors_test.rb +32 -9
- data/test/lib/vedeu/repositories/focus_test.rb +8 -0
- data/test/lib/vedeu/repositories/offsets_test.rb +32 -0
- data/test/lib/vedeu/{models/attributes → support}/coercions_test.rb +0 -0
- data/test/lib/vedeu/{models/attributes → support}/colour_translator_test.rb +0 -0
- data/test/lib/vedeu/support/move_test.rb +35 -0
- data/test/lib/vedeu/{models/attributes → support}/presentation_test.rb +0 -0
- data/test/lib/vedeu/support/registrar_test.rb +6 -0
- data/test/lib/vedeu_test.rb +5 -0
- data/vedeu.gemspec +1 -1
- metadata +37 -17
@@ -37,15 +37,24 @@ module Vedeu
|
|
37
37
|
# This will delete the interfaces themselves, and the client application
|
38
38
|
# will need to either redefine interfaces before using them, or restart.
|
39
39
|
#
|
40
|
+
# Note: It also resets repositories which depend on interfaces being
|
41
|
+
# registered.
|
42
|
+
#
|
40
43
|
# @return [Hash]
|
41
44
|
def reset
|
42
45
|
@_storage = in_memory
|
46
|
+
|
47
|
+
Vedeu::Buffers.reset
|
48
|
+
Vedeu::Cursors.reset
|
49
|
+
Vedeu::Focus.reset
|
50
|
+
Vedeu::Groups.reset
|
51
|
+
|
52
|
+
@_storage
|
43
53
|
end
|
44
54
|
|
45
55
|
private
|
46
56
|
|
47
57
|
# @see Vedeu::Refresh.register_event
|
48
|
-
# @api private
|
49
58
|
# @param attributes [Hash]
|
50
59
|
# @return [Boolean]
|
51
60
|
def register_event(attributes)
|
@@ -55,13 +64,11 @@ module Vedeu
|
|
55
64
|
Vedeu::Refresh.register_event(:by_name, name, delay)
|
56
65
|
end
|
57
66
|
|
58
|
-
# @api private
|
59
67
|
# @return [Hash]
|
60
68
|
def in_memory
|
61
69
|
{}
|
62
70
|
end
|
63
71
|
|
64
|
-
# @api private
|
65
72
|
# @param name [String]
|
66
73
|
# @raise [InterfaceNotFound] When the entity cannot be found with this name.
|
67
74
|
# @return [InterfaceNotFound]
|
@@ -150,7 +150,6 @@ module Vedeu
|
|
150
150
|
|
151
151
|
# Registers the key.
|
152
152
|
#
|
153
|
-
# @api private
|
154
153
|
# @param attributes [Hash]
|
155
154
|
# @param interface [String]
|
156
155
|
# @return []
|
@@ -166,7 +165,6 @@ module Vedeu
|
|
166
165
|
|
167
166
|
# Determine which interface to store the key with.
|
168
167
|
#
|
169
|
-
# @api private
|
170
168
|
# @param interface [String]
|
171
169
|
# @return [String]
|
172
170
|
def namespace(interface = '')
|
@@ -180,7 +178,6 @@ module Vedeu
|
|
180
178
|
proc { :noop }
|
181
179
|
end
|
182
180
|
|
183
|
-
# @api private
|
184
181
|
# @return [Array]
|
185
182
|
def in_memory
|
186
183
|
{ '_global_keymap_' => {} }
|
@@ -61,13 +61,11 @@ module Vedeu
|
|
61
61
|
# Returns an empty collection ready for the storing of menus by name with
|
62
62
|
# associated menu instance.
|
63
63
|
#
|
64
|
-
# @api private
|
65
64
|
# @return [Hash]
|
66
65
|
def in_memory
|
67
66
|
{}
|
68
67
|
end
|
69
68
|
|
70
|
-
# @api private
|
71
69
|
# @param name [String]
|
72
70
|
# @raise [MenuNotFound] When the entity cannot be found with this name.
|
73
71
|
# @return [MenuNotFound]
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Vedeu
|
2
|
+
|
3
|
+
# Repository for storing and retrieving content offsets; i.e. scroll
|
4
|
+
# position for a named interface.
|
5
|
+
#
|
6
|
+
# @api private
|
7
|
+
module Offsets
|
8
|
+
|
9
|
+
include Common
|
10
|
+
include Repository
|
11
|
+
extend self
|
12
|
+
|
13
|
+
# Add or update the offset coordinates for interface content.
|
14
|
+
#
|
15
|
+
# @param attributes [Hash]
|
16
|
+
# @return [Offset]
|
17
|
+
def add(attributes)
|
18
|
+
validate_attributes!(attributes)
|
19
|
+
|
20
|
+
Vedeu.log("#{action(__callee__)} offset: '#{attributes[:name]}'")
|
21
|
+
|
22
|
+
storage.store(attributes[:name], Offset.new(attributes))
|
23
|
+
end
|
24
|
+
alias_method :update, :add
|
25
|
+
|
26
|
+
# @param y [Fixnum]
|
27
|
+
# @param x [Fixnum]
|
28
|
+
# @return [Offset]
|
29
|
+
def move(y, x)
|
30
|
+
find_or_create(Focus.current).move(y, x)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
# @return [Class]
|
36
|
+
def entity
|
37
|
+
Offset
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [Hash]
|
41
|
+
def in_memory
|
42
|
+
{}
|
43
|
+
end
|
44
|
+
|
45
|
+
end # Offsets
|
46
|
+
|
47
|
+
end # Vedeu
|
File without changes
|
@@ -63,19 +63,16 @@ module Vedeu
|
|
63
63
|
|
64
64
|
attr_reader :colour
|
65
65
|
|
66
|
-
# @api private
|
67
66
|
# @return [Boolean]
|
68
67
|
def no_colour?
|
69
68
|
colour.nil? || colour.to_s.empty?
|
70
69
|
end
|
71
70
|
|
72
|
-
# @api private
|
73
71
|
# @return [Boolean]
|
74
72
|
def named?
|
75
73
|
colour.is_a?(Symbol) && valid_name?
|
76
74
|
end
|
77
75
|
|
78
|
-
# @api private
|
79
76
|
# @raise [NotImplemented] Subclasses of this class must implement this
|
80
77
|
# method.
|
81
78
|
# @return [Exception]
|
@@ -83,19 +80,16 @@ module Vedeu
|
|
83
80
|
fail NotImplemented, 'Subclasses implement this.'
|
84
81
|
end
|
85
82
|
|
86
|
-
# @api private
|
87
83
|
# @return [Boolean]
|
88
84
|
def valid_name?
|
89
85
|
codes.keys.include?(colour)
|
90
86
|
end
|
91
87
|
|
92
|
-
# @api private
|
93
88
|
# @return [Boolean]
|
94
89
|
def numbered?
|
95
90
|
colour.is_a?(Fixnum) && valid_range?
|
96
91
|
end
|
97
92
|
|
98
|
-
# @api private
|
99
93
|
# @raise [NotImplemented] Subclasses of this class must implement this
|
100
94
|
# method.
|
101
95
|
# @return [NotImplemented]
|
@@ -103,19 +97,16 @@ module Vedeu
|
|
103
97
|
fail NotImplemented, 'Subclasses implement this.'
|
104
98
|
end
|
105
99
|
|
106
|
-
# @api private
|
107
100
|
# @return [Boolean]
|
108
101
|
def valid_range?
|
109
102
|
colour >= 0 && colour <= 255
|
110
103
|
end
|
111
104
|
|
112
|
-
# @api private
|
113
105
|
# @return [Boolean]
|
114
106
|
def rgb?
|
115
107
|
colour.is_a?(String) && valid_rgb?
|
116
108
|
end
|
117
109
|
|
118
|
-
# @api private
|
119
110
|
# @raise [NotImplemented] Subclasses of this class must implement this
|
120
111
|
# method.
|
121
112
|
# @return [NotImplemented]
|
@@ -123,13 +114,11 @@ module Vedeu
|
|
123
114
|
fail NotImplemented, 'Subclasses implement this.'
|
124
115
|
end
|
125
116
|
|
126
|
-
# @api private
|
127
117
|
# @return [Boolean]
|
128
118
|
def valid_rgb?
|
129
119
|
!!(colour =~ /^#([A-Fa-f0-9]{6})$/)
|
130
120
|
end
|
131
121
|
|
132
|
-
# @api private
|
133
122
|
# @return [Array]
|
134
123
|
def css_to_rgb
|
135
124
|
[
|
@@ -139,7 +128,6 @@ module Vedeu
|
|
139
128
|
]
|
140
129
|
end
|
141
130
|
|
142
|
-
# @api private
|
143
131
|
# @return [Fixnum]
|
144
132
|
def css_to_numbered
|
145
133
|
if rgb?
|
@@ -151,25 +139,21 @@ module Vedeu
|
|
151
139
|
end
|
152
140
|
end
|
153
141
|
|
154
|
-
# @api private
|
155
142
|
# @return [Fixnum]
|
156
143
|
def red
|
157
144
|
(css_to_rgb[0] / 51) * 36
|
158
145
|
end
|
159
146
|
|
160
|
-
# @api private
|
161
147
|
# @return [Fixnum]
|
162
148
|
def green
|
163
149
|
(css_to_rgb[1] / 51) * 6
|
164
150
|
end
|
165
151
|
|
166
|
-
# @api private
|
167
152
|
# @return [Fixnum]
|
168
153
|
def blue
|
169
154
|
(css_to_rgb[2] / 51) * 1
|
170
155
|
end
|
171
156
|
|
172
|
-
# @api private
|
173
157
|
# @return [Hash]
|
174
158
|
def codes
|
175
159
|
{
|
data/lib/vedeu/support/esc.rb
CHANGED
@@ -65,7 +65,6 @@ module Vedeu
|
|
65
65
|
|
66
66
|
private
|
67
67
|
|
68
|
-
# @api private
|
69
68
|
# @return [Hash]
|
70
69
|
def sequences
|
71
70
|
{
|
@@ -93,37 +92,31 @@ module Vedeu
|
|
93
92
|
}
|
94
93
|
end
|
95
94
|
|
96
|
-
# @api private
|
97
95
|
# @return [String]
|
98
96
|
def bg_reset
|
99
97
|
"\e[48;2;49m"
|
100
98
|
end
|
101
99
|
|
102
|
-
# @api private
|
103
100
|
# @return [String]
|
104
101
|
def blink
|
105
102
|
"\e[5m"
|
106
103
|
end
|
107
104
|
|
108
|
-
# @api private
|
109
105
|
# @return [String]
|
110
106
|
def blink_off
|
111
107
|
"\e[25m"
|
112
108
|
end
|
113
109
|
|
114
|
-
# @api private
|
115
110
|
# @return [String]
|
116
111
|
def bold
|
117
112
|
"\e[1m"
|
118
113
|
end
|
119
114
|
|
120
|
-
# @api private
|
121
115
|
# @return [String]
|
122
116
|
def bold_off
|
123
117
|
"\e[22m"
|
124
118
|
end
|
125
119
|
|
126
|
-
# @api private
|
127
120
|
# @return [String]
|
128
121
|
def clear
|
129
122
|
[ string('fg_reset'),
|
@@ -131,7 +124,6 @@ module Vedeu
|
|
131
124
|
"\e[2J" ].join
|
132
125
|
end
|
133
126
|
|
134
|
-
# @api private
|
135
127
|
# @return [String]
|
136
128
|
def clear_line
|
137
129
|
[ string('fg_reset'),
|
@@ -139,45 +131,38 @@ module Vedeu
|
|
139
131
|
"\e[2K" ].join
|
140
132
|
end
|
141
133
|
|
142
|
-
# @api private
|
143
134
|
# @return [String]
|
144
135
|
def clear_last_line
|
145
136
|
[ set_position((Terminal.height - 1), 1),
|
146
137
|
string('clear_line') ].join
|
147
138
|
end
|
148
139
|
|
149
|
-
# @api private
|
150
140
|
# @return [String]
|
151
141
|
def colour_reset
|
152
142
|
[ string('fg_reset'),
|
153
143
|
string('bg_reset') ].join
|
154
144
|
end
|
155
145
|
|
156
|
-
# @api private
|
157
146
|
# @return [String]
|
158
147
|
def dim
|
159
148
|
"\e[2m"
|
160
149
|
end
|
161
150
|
|
162
|
-
# @api private
|
163
151
|
# @return [String]
|
164
152
|
def fg_reset
|
165
153
|
"\e[38;2;39m"
|
166
154
|
end
|
167
155
|
|
168
|
-
# @api private
|
169
156
|
# @return [String]
|
170
157
|
def hide_cursor
|
171
158
|
"\e[?25l"
|
172
159
|
end
|
173
160
|
|
174
|
-
# @api private
|
175
161
|
# @return [String]
|
176
162
|
def negative
|
177
163
|
"\e[7m"
|
178
164
|
end
|
179
165
|
|
180
|
-
# @api private
|
181
166
|
# @return [String]
|
182
167
|
def normal
|
183
168
|
[ string('underline_off'),
|
@@ -185,19 +170,16 @@ module Vedeu
|
|
185
170
|
string('positive') ].join
|
186
171
|
end
|
187
172
|
|
188
|
-
# @api private
|
189
173
|
# @return [String]
|
190
174
|
def positive
|
191
175
|
"\e[27m"
|
192
176
|
end
|
193
177
|
|
194
|
-
# @api private
|
195
178
|
# @return [String]
|
196
179
|
def reset
|
197
180
|
"\e[0m"
|
198
181
|
end
|
199
182
|
|
200
|
-
# @api private
|
201
183
|
# @return [String]
|
202
184
|
def screen_init
|
203
185
|
[ string('reset'),
|
@@ -205,7 +187,6 @@ module Vedeu
|
|
205
187
|
string('hide_cursor') ].join
|
206
188
|
end
|
207
189
|
|
208
|
-
# @api private
|
209
190
|
# @return [String]
|
210
191
|
def screen_exit
|
211
192
|
[ string('show_cursor'),
|
@@ -213,19 +194,16 @@ module Vedeu
|
|
213
194
|
string('reset') ].join
|
214
195
|
end
|
215
196
|
|
216
|
-
# @api private
|
217
197
|
# @return [String]
|
218
198
|
def show_cursor
|
219
199
|
"\e[?25h"
|
220
200
|
end
|
221
201
|
|
222
|
-
# @api private
|
223
202
|
# @return [String]
|
224
203
|
def underline
|
225
204
|
"\e[4m"
|
226
205
|
end
|
227
206
|
|
228
|
-
# @api private
|
229
207
|
# @return [String]
|
230
208
|
def underline_off
|
231
209
|
"\e[24m"
|
data/lib/vedeu/support/event.rb
CHANGED
@@ -37,7 +37,7 @@ module Vedeu
|
|
37
37
|
|
38
38
|
# Execute the code stored in the event closure.
|
39
39
|
#
|
40
|
-
# @
|
40
|
+
# @param args []
|
41
41
|
# @return []
|
42
42
|
def execute(*args)
|
43
43
|
reset_deadline
|
@@ -53,7 +53,6 @@ module Vedeu
|
|
53
53
|
# event. Setting the delay option to any value greater than 0 will enable
|
54
54
|
# throttling.
|
55
55
|
#
|
56
|
-
# @api private
|
57
56
|
# @return [Boolean]
|
58
57
|
def throttling?
|
59
58
|
set_time
|
@@ -63,7 +62,6 @@ module Vedeu
|
|
63
62
|
|
64
63
|
# Returns a boolean indicating whether the throttle has expired.
|
65
64
|
#
|
66
|
-
# @api private
|
67
65
|
# @return [Boolean]
|
68
66
|
def throttle_expired?
|
69
67
|
if elapsed_time > delay
|
@@ -81,7 +79,6 @@ module Vedeu
|
|
81
79
|
# event. Setting the debounce option to any value greater than 0 will
|
82
80
|
# enable debouncing.
|
83
81
|
#
|
84
|
-
# @api private
|
85
82
|
# @return [Boolean]
|
86
83
|
def debouncing?
|
87
84
|
set_time
|
@@ -93,7 +90,6 @@ module Vedeu
|
|
93
90
|
|
94
91
|
# Returns a boolean indicating whether the debounce has expired.
|
95
92
|
#
|
96
|
-
# @api private
|
97
93
|
# @return [Boolean]
|
98
94
|
def debounce_expired?
|
99
95
|
if set_executed > deadline
|
@@ -107,43 +103,36 @@ module Vedeu
|
|
107
103
|
end
|
108
104
|
end
|
109
105
|
|
110
|
-
# @api private
|
111
106
|
# @return [Float]
|
112
107
|
def elapsed_time
|
113
108
|
now - @executed_at
|
114
109
|
end
|
115
110
|
|
116
|
-
# @api private
|
117
111
|
# @return [Float]
|
118
112
|
def set_executed
|
119
113
|
@executed_at = now
|
120
114
|
end
|
121
115
|
|
122
|
-
# @api private
|
123
116
|
# @return [Float]
|
124
117
|
def set_time
|
125
118
|
@now = Time.now.to_f
|
126
119
|
end
|
127
120
|
|
128
|
-
# @api private
|
129
121
|
# @return [Fixnum]
|
130
122
|
def reset_time
|
131
123
|
@now = 0
|
132
124
|
end
|
133
125
|
|
134
|
-
# @api private
|
135
126
|
# @return [Boolean]
|
136
127
|
def has_deadline?
|
137
128
|
@deadline > 0
|
138
129
|
end
|
139
130
|
|
140
|
-
# @api private
|
141
131
|
# @return [Fixnum]
|
142
132
|
def reset_deadline
|
143
133
|
@deadline = 0
|
144
134
|
end
|
145
135
|
|
146
|
-
# @api private
|
147
136
|
# @return [NilClass]
|
148
137
|
def set_deadline
|
149
138
|
@deadline = now + debounce
|
@@ -151,31 +140,26 @@ module Vedeu
|
|
151
140
|
nil
|
152
141
|
end
|
153
142
|
|
154
|
-
# @api private
|
155
143
|
# @return [String]
|
156
144
|
def event_name
|
157
145
|
options[:event_name].to_s
|
158
146
|
end
|
159
147
|
|
160
|
-
# @api private
|
161
148
|
# @return [Fixnum|Float]
|
162
149
|
def debounce
|
163
150
|
options[:debounce] || defaults[:debounce]
|
164
151
|
end
|
165
152
|
|
166
|
-
# @api private
|
167
153
|
# @return [Fixnum|Float]
|
168
154
|
def delay
|
169
155
|
options[:delay] || defaults[:delay]
|
170
156
|
end
|
171
157
|
|
172
|
-
# @api private
|
173
158
|
# @return [Hash]
|
174
159
|
def options
|
175
160
|
defaults.merge!(@options)
|
176
161
|
end
|
177
162
|
|
178
|
-
# @api private
|
179
163
|
# @return [Hash]
|
180
164
|
def defaults
|
181
165
|
{
|
@@ -3,9 +3,6 @@ module Vedeu
|
|
3
3
|
# Raised when Vedeu attempts to access a named buffer that does not exist.
|
4
4
|
BufferNotFound = Class.new(StandardError)
|
5
5
|
|
6
|
-
# Raised when a cursor cannot be found by name.
|
7
|
-
CursorNotFound = Class.new(StandardError)
|
8
|
-
|
9
6
|
# Raised when trying to access a group of interfaces which do not exist by
|
10
7
|
# this name.
|
11
8
|
GroupNotFound = Class.new(StandardError)
|
data/lib/vedeu/support/grid.rb
CHANGED
@@ -55,19 +55,16 @@ module Vedeu
|
|
55
55
|
|
56
56
|
# Returns the width of a single column in characters.
|
57
57
|
#
|
58
|
-
# @api private
|
59
58
|
# @return [Fixnum]
|
60
59
|
def column
|
61
60
|
actual / 12
|
62
61
|
end
|
63
62
|
|
64
|
-
# @api private
|
65
63
|
# @return [Fixnum]
|
66
64
|
def actual
|
67
65
|
Terminal.width
|
68
66
|
end
|
69
67
|
|
70
|
-
# @api private
|
71
68
|
# @return [Boolean]
|
72
69
|
def out_of_range?
|
73
70
|
value < 1 || value > 12
|
data/lib/vedeu/support/log.rb
CHANGED
@@ -2,9 +2,10 @@ require 'fileutils'
|
|
2
2
|
require 'time'
|
3
3
|
|
4
4
|
module Vedeu
|
5
|
-
|
5
|
+
|
6
6
|
# @api private
|
7
7
|
class MonoLogger < Logger
|
8
|
+
|
8
9
|
# Create a trappable Logger instance.
|
9
10
|
#
|
10
11
|
# @param logdev [String|IO] The filename (String) or IO object (typically
|
@@ -83,6 +84,7 @@ module Vedeu
|
|
83
84
|
)
|
84
85
|
end
|
85
86
|
end
|
87
|
+
|
86
88
|
end
|
87
89
|
|
88
90
|
# Provides the ability to Log anything to the Vedeu log file which is
|
@@ -97,28 +99,26 @@ module Vedeu
|
|
97
99
|
log.formatter = proc do |_, time, _, message|
|
98
100
|
utc_time = time.utc.iso8601
|
99
101
|
|
100
|
-
|
101
|
-
message + "\n"
|
102
|
-
|
103
|
-
else
|
104
|
-
@last_seen = utc_time
|
105
|
-
|
106
|
-
"\n\e[4m\e[31m" + utc_time + "\e[39m\e[24m\n" + message + "\n"
|
107
|
-
|
108
|
-
end
|
102
|
+
[timestamp(utc_time), message, "\n"].join
|
109
103
|
end
|
110
104
|
end
|
111
105
|
end
|
112
106
|
|
113
107
|
private
|
114
108
|
|
115
|
-
|
109
|
+
def self.timestamp(utc_time)
|
110
|
+
return "" if @last_seen == utc_time
|
111
|
+
|
112
|
+
@last_seen = utc_time
|
113
|
+
|
114
|
+
"\n\e[4m\e[31m" + utc_time + "\e[39m\e[24m\n"
|
115
|
+
end
|
116
|
+
|
116
117
|
# @return [String]
|
117
118
|
def self.filename
|
118
119
|
@_filename ||= directory + '/vedeu.log'
|
119
120
|
end
|
120
121
|
|
121
|
-
# @api private
|
122
122
|
# @return [String]
|
123
123
|
def self.directory
|
124
124
|
FileUtils.mkdir_p(path) unless File.directory?(path)
|
@@ -126,12 +126,11 @@ module Vedeu
|
|
126
126
|
path
|
127
127
|
end
|
128
128
|
|
129
|
-
# @api private
|
130
129
|
# @return [String]
|
131
130
|
def self.path
|
132
131
|
Dir.home + '/.vedeu'
|
133
132
|
end
|
134
133
|
|
135
134
|
end # Log
|
136
|
-
|
135
|
+
|
137
136
|
end # Vedeu
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Vedeu
|
2
|
+
|
3
|
+
# Facade to access Offsets when a movement action occurs.
|
4
|
+
#
|
5
|
+
module Move
|
6
|
+
|
7
|
+
extend self
|
8
|
+
|
9
|
+
# @return [Array]
|
10
|
+
def down
|
11
|
+
move(1, 0)
|
12
|
+
end
|
13
|
+
|
14
|
+
# @return [Array]
|
15
|
+
def up
|
16
|
+
move(-1, 0)
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [Array]
|
20
|
+
def right
|
21
|
+
move(0, 1)
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [Array]
|
25
|
+
def left
|
26
|
+
move(0, -1)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
# @param y [Fixnum]
|
32
|
+
# @param x [Fixnum]
|
33
|
+
# @return [Array]
|
34
|
+
def move(y, x)
|
35
|
+
Offsets.move(y, x)
|
36
|
+
|
37
|
+
Focus.refresh
|
38
|
+
end
|
39
|
+
|
40
|
+
# System events which when called will move in the direction specified;
|
41
|
+
# these will update the cursor position or content offset (scrolling)
|
42
|
+
# according to the interface in focus.
|
43
|
+
Vedeu.event(:_cursor_up_) { up }
|
44
|
+
Vedeu.event(:_cursor_right_) { right }
|
45
|
+
Vedeu.event(:_cursor_down_) { down }
|
46
|
+
Vedeu.event(:_cursor_left_) { left }
|
47
|
+
|
48
|
+
end # Move
|
49
|
+
|
50
|
+
end # Vedeu
|
@@ -1,17 +1,18 @@
|
|
1
1
|
module Vedeu
|
2
2
|
|
3
3
|
# Change coordinates into an escape sequence to set the cursor position.
|
4
|
+
# Also used as the basis of an Offset.
|
4
5
|
#
|
5
6
|
# @api private
|
6
|
-
class Position
|
7
|
+
class Position < Array
|
7
8
|
|
8
9
|
# Initializes a new instance of Position.
|
9
10
|
#
|
10
11
|
# @param y [Fixnum]
|
11
12
|
# @param x [Fixnum]
|
12
13
|
# @return [Position]
|
13
|
-
def initialize(y =
|
14
|
-
|
14
|
+
def initialize(y = 0, x = 0)
|
15
|
+
super([y, x])
|
15
16
|
end
|
16
17
|
|
17
18
|
# Returns an escape sequence to position the cursor. When passed a block,
|
@@ -31,22 +32,29 @@ module Vedeu
|
|
31
32
|
|
32
33
|
private
|
33
34
|
|
34
|
-
#
|
35
|
+
# Returns the escape sequence to reposition the cursors at the coordinates
|
36
|
+
# specified by x and y. If either of these values are 0, then we use 1,
|
37
|
+
# as ANSI terminals do not have a 0, 0 coordinate.
|
38
|
+
#
|
35
39
|
# @return [String]
|
36
40
|
def sequence
|
37
|
-
["\e[", y, ';', x, 'H'].join
|
41
|
+
["\e[", (y == 0 ? 1 : y), ';', (x == 0 ? 1 : x), 'H'].join
|
38
42
|
end
|
39
43
|
|
40
|
-
#
|
44
|
+
# Returns the y coordinate. Can be 0 as this class may also be used as an
|
45
|
+
# Offset.
|
46
|
+
#
|
41
47
|
# @return [Fixnum]
|
42
48
|
def y
|
43
|
-
(
|
49
|
+
(first == nil) ? 0 : first
|
44
50
|
end
|
45
51
|
|
46
|
-
#
|
52
|
+
# Returns the x coordinate. Can be 0 as this class may also be used as an
|
53
|
+
# Offset.
|
54
|
+
#
|
47
55
|
# @return [Fixnum]
|
48
56
|
def x
|
49
|
-
(
|
57
|
+
(last == nil) ? 0 : last
|
50
58
|
end
|
51
59
|
|
52
60
|
end # Position
|