vedeu 0.6.7 → 0.6.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/docs/dsl.md +4 -4
- data/lib/vedeu/all.rb +6 -18
- data/lib/vedeu/api.rb +14 -13
- data/lib/vedeu/bindings/system.rb +5 -4
- data/lib/vedeu/buffers/virtual_buffer.rb +13 -11
- data/lib/vedeu/configuration/api.rb +4 -3
- data/lib/vedeu/cursors/cursor.rb +23 -18
- data/lib/vedeu/distributed/client.rb +11 -6
- data/lib/vedeu/distributed/server.rb +4 -3
- data/lib/vedeu/dsl/keymap.rb +6 -6
- data/lib/vedeu/editor/all.rb +19 -0
- data/lib/vedeu/{input/editor → editor}/capture.rb +1 -1
- data/lib/vedeu/{input/editor → editor}/cropper.rb +0 -0
- data/lib/vedeu/{input/editor → editor}/cursor.rb +0 -0
- data/lib/vedeu/{input/editor → editor}/document.rb +0 -0
- data/lib/vedeu/{input/editor → editor}/documents.rb +0 -0
- data/lib/vedeu/{input/editor → editor}/editor.rb +0 -0
- data/lib/vedeu/{input/editor → editor}/insert.rb +0 -0
- data/lib/vedeu/{input/editor → editor}/line.rb +0 -0
- data/lib/vedeu/{input/editor → editor}/lines.rb +0 -0
- data/lib/vedeu/error.rb +21 -18
- data/lib/vedeu/esc/borders.rb +6 -4
- data/lib/vedeu/esc/colours.rb +13 -12
- data/lib/vedeu/esc/esc.rb +11 -10
- data/lib/vedeu/input/all.rb +15 -0
- data/lib/vedeu/input/input.rb +55 -52
- data/lib/vedeu/input/key.rb +36 -30
- data/lib/vedeu/input/keymap.rb +101 -92
- data/lib/vedeu/input/keymaps.rb +10 -6
- data/lib/vedeu/input/keys.rb +8 -4
- data/lib/vedeu/input/mapper.rb +125 -121
- data/lib/vedeu/input/translator.rb +159 -0
- data/lib/vedeu/internal_api.rb +16 -15
- data/lib/vedeu/logging/all.rb +13 -0
- data/lib/vedeu/logging/debug.rb +84 -0
- data/lib/vedeu/logging/lockless_log_device.rb +65 -0
- data/lib/vedeu/logging/log.rb +179 -0
- data/lib/vedeu/logging/mono_logger.rb +26 -0
- data/lib/vedeu/logging/timer.rb +68 -0
- data/lib/vedeu/menus/all.rb +12 -0
- data/lib/vedeu/{dsl/menu.rb → menus/dsl.rb} +19 -18
- data/lib/vedeu/menus/menu.rb +234 -0
- data/lib/vedeu/{null/menu.rb → menus/null.rb} +6 -6
- data/lib/vedeu/menus/repository.rb +18 -0
- data/lib/vedeu/models/cell.rb +62 -55
- data/lib/vedeu/models/escape.rb +55 -50
- data/lib/vedeu/models/page.rb +74 -69
- data/lib/vedeu/models/row.rb +55 -51
- data/lib/vedeu/models/views/all.rb +1 -0
- data/lib/vedeu/models/views/char.rb +1 -1
- data/lib/vedeu/models/views/html_char.rb +165 -0
- data/lib/vedeu/output/renderers/html.rb +5 -4
- data/lib/vedeu/repositories/model.rb +2 -0
- data/lib/vedeu/runtime/application.rb +110 -103
- data/lib/vedeu/runtime/bootstrap.rb +109 -103
- data/lib/vedeu/runtime/flags.rb +45 -41
- data/lib/vedeu/runtime/launcher.rb +1 -1
- data/lib/vedeu/runtime/main_loop.rb +51 -46
- data/lib/vedeu/runtime/traps.rb +20 -16
- data/lib/vedeu/version.rb +1 -1
- data/lib/vedeu.rb +2 -2
- data/test/lib/vedeu/buffers/virtual_buffer_test.rb +1 -1
- data/test/lib/vedeu/cursors/cursor_test.rb +11 -5
- data/test/lib/vedeu/dsl/interface_test.rb +1 -1
- data/test/lib/vedeu/dsl/keymap_test.rb +2 -2
- data/test/lib/vedeu/{input/editor → editor}/capture_test.rb +0 -0
- data/test/lib/vedeu/{input/editor → editor}/cropper_test.rb +0 -0
- data/test/lib/vedeu/{input/editor → editor}/cursor_test.rb +0 -0
- data/test/lib/vedeu/{input/editor → editor}/document_test.rb +0 -0
- data/test/lib/vedeu/{input/editor → editor}/documents_test.rb +0 -0
- data/test/lib/vedeu/{input/editor → editor}/editor_test.rb +0 -0
- data/test/lib/vedeu/{input/editor → editor}/insert_test.rb +0 -0
- data/test/lib/vedeu/{input/editor → editor}/line_test.rb +0 -0
- data/test/lib/vedeu/{input/editor → editor}/lines_test.rb +0 -0
- data/test/lib/vedeu/input/input_test.rb +58 -54
- data/test/lib/vedeu/input/key_test.rb +29 -25
- data/test/lib/vedeu/input/keymap_test.rb +74 -70
- data/test/lib/vedeu/input/keymaps_test.rb +8 -4
- data/test/lib/vedeu/input/keys_test.rb +12 -8
- data/test/lib/vedeu/input/mapper_test.rb +64 -56
- data/test/lib/vedeu/input/translator_test.rb +36 -0
- data/test/lib/vedeu/logging/debug_test.rb +39 -0
- data/test/lib/vedeu/logging/lockless_log_device_test.rb +42 -0
- data/test/lib/vedeu/logging/log_test.rb +52 -0
- data/test/lib/vedeu/logging/mono_logger_test.rb +43 -0
- data/test/lib/vedeu/logging/timer_test.rb +44 -0
- data/test/lib/vedeu/{dsl/menu_test.rb → menus/dsl_test.rb} +6 -6
- data/test/lib/vedeu/menus/menu_test.rb +305 -0
- data/test/lib/vedeu/{null/menu_test.rb → menus/null_test.rb} +5 -5
- data/test/lib/vedeu/menus/repository_test.rb +17 -0
- data/test/lib/vedeu/models/cell_test.rb +54 -50
- data/test/lib/vedeu/models/escape_test.rb +49 -45
- data/test/lib/vedeu/models/page_test.rb +167 -160
- data/test/lib/vedeu/models/row_test.rb +71 -67
- data/test/lib/vedeu/models/views/html_char_test.rb +110 -0
- data/test/lib/vedeu/output/compressor_test.rb +44 -22
- data/test/lib/vedeu/output/renderers_test.rb +4 -2
- data/test/lib/vedeu/runtime/application_test.rb +36 -32
- data/test/lib/vedeu/runtime/bootstrap_test.rb +31 -26
- data/test/lib/vedeu/runtime/flags_test.rb +33 -29
- data/test/lib/vedeu/runtime/launcher_test.rb +4 -2
- data/test/lib/vedeu/runtime/main_loop_test.rb +28 -24
- data/test/lib/vedeu/runtime/traps_test.rb +8 -4
- data/test/test_helper.rb +4 -2
- metadata +66 -63
- data/lib/vedeu/input/editor/all.rb +0 -19
- data/lib/vedeu/input/input_translator.rb +0 -155
- data/lib/vedeu/log/debug.rb +0 -79
- data/lib/vedeu/log/lockless_log_device.rb +0 -61
- data/lib/vedeu/log/log.rb +0 -172
- data/lib/vedeu/log/mono_logger.rb +0 -21
- data/lib/vedeu/log/timer.rb +0 -63
- data/lib/vedeu/models/menu.rb +0 -217
- data/lib/vedeu/models/menus.rb +0 -14
- data/lib/vedeu/output/html_char.rb +0 -161
- data/test/lib/vedeu/input/input_translator_test.rb +0 -32
- data/test/lib/vedeu/log/debug_test.rb +0 -35
- data/test/lib/vedeu/log/lockless_log_device_test.rb +0 -29
- data/test/lib/vedeu/log/log_test.rb +0 -48
- data/test/lib/vedeu/log/mono_logger_test.rb +0 -31
- data/test/lib/vedeu/log/timer_test.rb +0 -40
- data/test/lib/vedeu/models/menu_test.rb +0 -301
- data/test/lib/vedeu/models/menus_test.rb +0 -13
- data/test/lib/vedeu/output/html_char_test.rb +0 -106
data/lib/vedeu/input/mapper.rb
CHANGED
@@ -1,127 +1,131 @@
|
|
1
1
|
module Vedeu
|
2
2
|
|
3
|
-
|
4
|
-
#
|
5
|
-
class Mapper
|
3
|
+
module Input
|
6
4
|
|
7
|
-
#
|
8
|
-
# the associated action is fired, otherwise, we move to the next keymap or
|
9
|
-
# return false.
|
5
|
+
# Maps keys to keymaps.
|
10
6
|
#
|
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
|
-
return
|
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
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
7
|
+
class Mapper
|
8
|
+
|
9
|
+
# Takes a key as a keypress and sends it to registered keymaps. If found,
|
10
|
+
# the associated action is fired, otherwise, we move to the next keymap or
|
11
|
+
# return false.
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# Vedeu.keypress(key_name, keymap_name)
|
15
|
+
#
|
16
|
+
# @param (see #initialize)
|
17
|
+
# @return [Boolean]
|
18
|
+
def self.keypress(key = nil, name = nil)
|
19
|
+
Vedeu.trigger(:key, key)
|
20
|
+
|
21
|
+
return false unless key
|
22
|
+
|
23
|
+
new(key, name).keypress
|
24
|
+
end
|
25
|
+
|
26
|
+
# Checks a key is valid; i.e. not already registered to a keymap. When the
|
27
|
+
# key is registered, then the key is invalid and cannot be used again.
|
28
|
+
#
|
29
|
+
# @param (see #initialize)
|
30
|
+
# @return [Boolean]
|
31
|
+
def self.valid?(key = nil, name = nil)
|
32
|
+
return false unless key
|
33
|
+
|
34
|
+
new(key, name).valid?
|
35
|
+
end
|
36
|
+
|
37
|
+
# Returns a new instance of Vedeu::Input::Mapper.
|
38
|
+
#
|
39
|
+
# @param key [NilClass|String|Symbol]
|
40
|
+
# @param name [NilClass|String]
|
41
|
+
# @param repository [NilClass|Vedeu::Repository]
|
42
|
+
# @return [Vedeu::Input::Mapper]
|
43
|
+
def initialize(key = nil, name = nil, repository = nil)
|
44
|
+
@key = key
|
45
|
+
@name = name
|
46
|
+
@repository = repository || Vedeu.keymaps
|
47
|
+
end
|
48
|
+
|
49
|
+
# Returns a boolean indicating that the key is registered to the current
|
50
|
+
# keymap, or the global keymap.
|
51
|
+
#
|
52
|
+
# @return [Boolean]
|
53
|
+
def keypress
|
54
|
+
return false unless key
|
55
|
+
|
56
|
+
Vedeu.log(type: :input, message: "Key detected: #{key.inspect}")
|
57
|
+
|
58
|
+
return true if key_defined? && keymap.use(key)
|
59
|
+
|
60
|
+
return true if global_key? && keymap('_global_').use(key)
|
61
|
+
|
62
|
+
false
|
63
|
+
end
|
64
|
+
|
65
|
+
# Returns a boolean indicating that the key is not registered to
|
66
|
+
# the current keymap, or the global keymap.
|
67
|
+
#
|
68
|
+
# @return [Boolean]
|
69
|
+
def valid?
|
70
|
+
return false if !key || key_defined? || global_key?
|
71
|
+
|
72
|
+
true
|
73
|
+
end
|
74
|
+
|
75
|
+
protected
|
76
|
+
|
77
|
+
# @!attribute [r] key
|
78
|
+
# @return [String|Symbol]
|
79
|
+
attr_reader :key
|
80
|
+
|
81
|
+
# @!attribute [r] repository
|
82
|
+
# @return [Vedeu::Repository]
|
83
|
+
attr_reader :repository
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
# Is the key a global key?
|
88
|
+
#
|
89
|
+
# @return [Boolean]
|
90
|
+
def global_key?
|
91
|
+
key_defined?('_global_')
|
92
|
+
end
|
93
|
+
|
94
|
+
# Is the key defined in the named keymap?
|
95
|
+
#
|
96
|
+
# @param named [NilClass|String]
|
97
|
+
# @return [Boolean]
|
98
|
+
def key_defined?(named = name)
|
99
|
+
keymap?(named) && keymap(named).key_defined?(key)
|
100
|
+
end
|
101
|
+
|
102
|
+
# Fetch the named keymap from the repository.
|
103
|
+
#
|
104
|
+
# @param named [NilClass|String]
|
105
|
+
# @return [Vedeu::Input::Keymap]
|
106
|
+
def keymap(named = name)
|
107
|
+
repository.find(named)
|
108
|
+
end
|
109
|
+
|
110
|
+
# Does the keymaps repository have the named keymap already registered?
|
111
|
+
#
|
112
|
+
# @param named [NilClass|String]
|
113
|
+
# @return [Boolean]
|
114
|
+
def keymap?(named = name)
|
115
|
+
repository.registered?(named)
|
116
|
+
end
|
117
|
+
|
118
|
+
# With a name, we check the keymap with that name, otherwise we use the
|
119
|
+
# name of the interface currently in focus.
|
120
|
+
#
|
121
|
+
# @return [String|NilClass]
|
122
|
+
def name
|
123
|
+
@name || Vedeu.focus
|
124
|
+
end
|
125
|
+
alias_method :interface, :name
|
126
|
+
|
127
|
+
end # Mapper
|
128
|
+
|
129
|
+
end # Input
|
126
130
|
|
127
131
|
end # Vedeu
|
@@ -0,0 +1,159 @@
|
|
1
|
+
module Vedeu
|
2
|
+
|
3
|
+
module Input
|
4
|
+
|
5
|
+
# Translates escape sequences provided by the terminal into
|
6
|
+
# symbols which Vedeu can use for various behaviours.
|
7
|
+
#
|
8
|
+
class Translator
|
9
|
+
|
10
|
+
# @param code [String]
|
11
|
+
# @return [Symbol]
|
12
|
+
def self.translate(code)
|
13
|
+
new(code).translate
|
14
|
+
end
|
15
|
+
|
16
|
+
# Returns a new instance of Vedeu::Input::Translator.
|
17
|
+
#
|
18
|
+
# @param code [String]
|
19
|
+
# @return [Vedeu::Input::Translator]
|
20
|
+
def initialize(code)
|
21
|
+
@code = code
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [Symbol]
|
25
|
+
def translate
|
26
|
+
symbols.fetch(code, code)
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
# @!attribute [r] code
|
32
|
+
# @return [String]
|
33
|
+
attr_reader :code
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
# @return [Hash<String => Symbol>]
|
38
|
+
def symbols
|
39
|
+
@symbols ||= f_keys.merge!(ctrl_letters).merge!(specials)
|
40
|
+
end
|
41
|
+
|
42
|
+
# @return [Hash<String => Symbol>]
|
43
|
+
def ctrl_letters
|
44
|
+
{
|
45
|
+
"\u0001" => :ctrl_a,
|
46
|
+
"\u0002" => :ctrl_b,
|
47
|
+
"\u0003" => :ctrl_c,
|
48
|
+
"\u2404" => :ctrl_c,
|
49
|
+
"\u0004" => :ctrl_d,
|
50
|
+
"\u2403" => :ctrl_d,
|
51
|
+
"\u0005" => :ctrl_e,
|
52
|
+
"\u0006" => :ctrl_f,
|
53
|
+
"\u0007" => :ctrl_g,
|
54
|
+
"\u0008" => :ctrl_h,
|
55
|
+
# "\u0009" => :ctrl_i, # duplicates tab
|
56
|
+
"\u0010" => :ctrl_j, # produces "\n"
|
57
|
+
"\u0011" => :ctrl_k,
|
58
|
+
"\u0012" => :ctrl_l,
|
59
|
+
"\u0013" => :ctrl_m,
|
60
|
+
"\u0014" => :ctrl_n,
|
61
|
+
"\u0015" => :ctrl_o,
|
62
|
+
"\u0016" => :ctrl_p,
|
63
|
+
"\u0017" => :ctrl_q,
|
64
|
+
"\u0018" => :ctrl_r,
|
65
|
+
"\u2412" => :ctrl_r,
|
66
|
+
"\u0019" => :ctrl_s,
|
67
|
+
# "\u0020" => :ctrl_t, # duplicates spacebar
|
68
|
+
"\u0021" => :ctrl_u,
|
69
|
+
"\u0022" => :ctrl_v,
|
70
|
+
"\u0023" => :ctrl_w,
|
71
|
+
"\u0024" => :ctrl_x,
|
72
|
+
"\u0025" => :ctrl_y,
|
73
|
+
"\u0026" => :ctrl_z,
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
77
|
+
# @return [Hash<String => Symbol>]
|
78
|
+
def f_keys
|
79
|
+
{
|
80
|
+
"\eOP" => :f1,
|
81
|
+
"\eOQ" => :f2,
|
82
|
+
"\eOR" => :f3,
|
83
|
+
"\eOS" => :f4,
|
84
|
+
|
85
|
+
"\e[15~" => :f5,
|
86
|
+
"\e[15;2~" => :shift_f5,
|
87
|
+
"\e[15;5~" => :ctrl_f5,
|
88
|
+
|
89
|
+
"\e[17~" => :f6,
|
90
|
+
"\e[17;2~" => :shift_f6,
|
91
|
+
"\e[17;5~" => :ctrl_f6,
|
92
|
+
|
93
|
+
"\e[18~" => :f7,
|
94
|
+
"\e[18;2~" => :shift_f7,
|
95
|
+
"\e[18;5~" => :ctrl_f7,
|
96
|
+
|
97
|
+
"\e[19~" => :f8,
|
98
|
+
"\e[19;2~" => :shift_f8,
|
99
|
+
"\e[19;5~" => :ctrl_f8,
|
100
|
+
|
101
|
+
"\e[20~" => :f9,
|
102
|
+
"\e[20;2~" => :shift_f9,
|
103
|
+
"\e[20;5~" => :ctrl_f9,
|
104
|
+
|
105
|
+
"\e[21~" => :f10,
|
106
|
+
"\e[21;2~" => :shift_f10,
|
107
|
+
"\e[21;5~" => :ctrl_f10,
|
108
|
+
|
109
|
+
"\e[23~" => :f11,
|
110
|
+
"\e[23;2~" => :shift_f11,
|
111
|
+
"\e[23;5~" => :ctrl_f11,
|
112
|
+
|
113
|
+
"\e[24~" => :f12,
|
114
|
+
"\e[24;2~" => :shift_f12,
|
115
|
+
"\e[24;5~" => :ctrl_f12,
|
116
|
+
}
|
117
|
+
end
|
118
|
+
|
119
|
+
# @return [Hash<String => Symbol>]
|
120
|
+
def specials
|
121
|
+
{
|
122
|
+
"\u007F" => :backspace,
|
123
|
+
"\u2408" => :backspace,
|
124
|
+
"\u23CE" => :carriage_return,
|
125
|
+
"\e[3~" => :delete,
|
126
|
+
"\u232B" => :delete,
|
127
|
+
"\e[B" => :down,
|
128
|
+
"\u2193" => :down,
|
129
|
+
"\e[F" => :end,
|
130
|
+
"\r" => :enter,
|
131
|
+
"\n" => :enter,
|
132
|
+
"\e" => :escape,
|
133
|
+
"\u238B" => :escape,
|
134
|
+
"\e[H" => :home,
|
135
|
+
"\eOH" => :home,
|
136
|
+
"\e[2~" => :insert,
|
137
|
+
"\e[D" => :left,
|
138
|
+
"\u2190" => :left,
|
139
|
+
"\u240A" => :line_feed,
|
140
|
+
"\e[5~" => :page_up,
|
141
|
+
"\e[6~" => :page_down,
|
142
|
+
"\e[1;2R" => :pause_break,
|
143
|
+
"\e[1;2P" => :print_screen,
|
144
|
+
"\e[C" => :right,
|
145
|
+
"\u2192" => :right,
|
146
|
+
"\e[1;2Q" => :scroll_lock,
|
147
|
+
"\e[Z" => :shift_tab,
|
148
|
+
"\t" => :tab,
|
149
|
+
"\u21B9" => :tab,
|
150
|
+
"\e[A" => :up,
|
151
|
+
"\u2191" => :up,
|
152
|
+
}
|
153
|
+
end
|
154
|
+
|
155
|
+
end # Translator
|
156
|
+
|
157
|
+
end # Input
|
158
|
+
|
159
|
+
end # Vedeu
|
data/lib/vedeu/internal_api.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Vedeu
|
2
2
|
|
3
|
-
# Vedeu's internal API methods provide convenient ways to access
|
4
|
-
# internals. They are not supposed to be used by client
|
5
|
-
# have limited value there.
|
3
|
+
# Vedeu's internal API methods provide convenient ways to access
|
4
|
+
# Vedeu's internals. They are not supposed to be used by client
|
5
|
+
# applications as they have limited value there.
|
6
6
|
#
|
7
7
|
module InternalAPI
|
8
8
|
|
@@ -46,14 +46,15 @@ module Vedeu
|
|
46
46
|
# @return [Vedeu::Cursors::Repository]
|
47
47
|
def_delegators Vedeu::Cursors::Repository, :cursors
|
48
48
|
|
49
|
-
# Allow debugging via the creation of stack traces courtesy of
|
49
|
+
# Allow debugging via the creation of stack traces courtesy of
|
50
|
+
# ruby-prof.
|
50
51
|
#
|
51
52
|
# @example
|
52
53
|
# Vedeu.debug
|
53
54
|
#
|
54
55
|
# @!method debug
|
55
|
-
# @return [Vedeu::Debug]
|
56
|
-
def_delegators Vedeu::Debug, :debug
|
56
|
+
# @return [Vedeu::Logging::Debug]
|
57
|
+
def_delegators Vedeu::Logging::Debug, :debug
|
57
58
|
|
58
59
|
# Manipulate the repository of documents.
|
59
60
|
#
|
@@ -115,8 +116,8 @@ module Vedeu
|
|
115
116
|
# Vedeu.keymaps
|
116
117
|
#
|
117
118
|
# @!method keymaps
|
118
|
-
# @return [Vedeu::Keymaps]
|
119
|
-
def_delegators Vedeu::Keymaps, :keymaps
|
119
|
+
# @return [Vedeu::Input::Keymaps]
|
120
|
+
def_delegators Vedeu::Input::Keymaps, :keymaps
|
120
121
|
|
121
122
|
# Manipulate the repository of menus.
|
122
123
|
#
|
@@ -124,15 +125,15 @@ module Vedeu
|
|
124
125
|
# Vedeu.menus
|
125
126
|
#
|
126
127
|
# @!method menus
|
127
|
-
# @return [Vedeu::Menus]
|
128
|
-
def_delegators Vedeu::Menus, :menus
|
128
|
+
# @return [Vedeu::Menus::Repository]
|
129
|
+
def_delegators Vedeu::Menus::Repository, :menus
|
129
130
|
|
130
131
|
# Manipulate the internal flags.
|
131
132
|
#
|
132
133
|
# @!method ready?
|
133
134
|
# @!method ready!
|
134
135
|
# @return [Boolean]
|
135
|
-
def_delegators Vedeu::Flags, :ready?, :ready!
|
136
|
+
def_delegators Vedeu::Runtime::Flags, :ready?, :ready!
|
136
137
|
|
137
138
|
# @example
|
138
139
|
# Vedeu.renderer
|
@@ -144,8 +145,8 @@ module Vedeu
|
|
144
145
|
# @see Vedeu::Renderers#renderers
|
145
146
|
def_delegators Vedeu::Renderers, :renderer, :renderers
|
146
147
|
|
147
|
-
# Instruct the terminal to resize. This will happen automatically
|
148
|
-
# terminal recieves SIGWINCH signals.
|
148
|
+
# Instruct the terminal to resize. This will happen automatically
|
149
|
+
# as the terminal recieves SIGWINCH signals.
|
149
150
|
#
|
150
151
|
# @example
|
151
152
|
# Vedeu.resize
|
@@ -162,8 +163,8 @@ module Vedeu
|
|
162
163
|
# end
|
163
164
|
#
|
164
165
|
# @!method timer
|
165
|
-
# @see Vedeu::Timer.timer
|
166
|
-
def_delegators Vedeu::Timer, :timer
|
166
|
+
# @see Vedeu::Logging::Timer.timer
|
167
|
+
def_delegators Vedeu::Logging::Timer, :timer
|
167
168
|
|
168
169
|
end # InternalAPI
|
169
170
|
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Vedeu
|
2
|
+
|
3
|
+
module Logging
|
4
|
+
|
5
|
+
# Provides a stack trace of a running client application upon exit
|
6
|
+
# in a file for further analysis.
|
7
|
+
#
|
8
|
+
module Debug
|
9
|
+
|
10
|
+
extend self
|
11
|
+
|
12
|
+
# :nocov:
|
13
|
+
# Helps to debug a running application by providing a stack
|
14
|
+
# trace of its execution upon exiting.
|
15
|
+
#
|
16
|
+
# @param filename [String]
|
17
|
+
# @return [void]
|
18
|
+
# @yieldreturn [void] The section of the application to debug.
|
19
|
+
def self.debug(filename = 'profile.html')
|
20
|
+
return nil unless block_given?
|
21
|
+
|
22
|
+
require 'ruby-prof'
|
23
|
+
|
24
|
+
# RubyProf.measure_mode = RubyProf::WALL_TIME
|
25
|
+
# RubyProf.measure_mode = RubyProf::PROCESS_TIME
|
26
|
+
RubyProf.measure_mode = RubyProf::CPU_TIME
|
27
|
+
# RubyProf.measure_mode = RubyProf::ALLOCATIONS
|
28
|
+
# RubyProf.measure_mode = RubyProf::MEMORY
|
29
|
+
# RubyProf.measure_mode = RubyProf::GC_TIME
|
30
|
+
# RubyProf.measure_mode = RubyProf::GC_RUNS
|
31
|
+
|
32
|
+
RubyProf.start
|
33
|
+
|
34
|
+
work = yield
|
35
|
+
|
36
|
+
result = RubyProf.stop
|
37
|
+
result.eliminate_methods!([
|
38
|
+
/^Array/,
|
39
|
+
/^Hash/,
|
40
|
+
/^String/,
|
41
|
+
/^Fixnum/,
|
42
|
+
])
|
43
|
+
|
44
|
+
File.open('/tmp/' + filename, 'w') do |file|
|
45
|
+
# - Creates a HTML visualization of the Ruby stack
|
46
|
+
RubyProf::CallStackPrinter.new(result).print(file)
|
47
|
+
|
48
|
+
# Used with QTCacheGrind to analyse performance.
|
49
|
+
# RubyProf::CallTreePrinter.new(result).print(file)
|
50
|
+
|
51
|
+
# Creates a flat report in text format
|
52
|
+
# RubyProf::FlatPrinter
|
53
|
+
|
54
|
+
# - same as above but more verbose
|
55
|
+
# RubyProf::FlatPrinterWithLineNumbers
|
56
|
+
|
57
|
+
# - Creates a call graph report in text format
|
58
|
+
# RubyProf::GraphPrinter
|
59
|
+
|
60
|
+
# - Creates a call graph report in HTML (separate files per
|
61
|
+
# thread)
|
62
|
+
# RubyProf::GraphHtmlPrinter
|
63
|
+
|
64
|
+
# - Creates a call graph report in GraphViz's DOT format
|
65
|
+
# which can be converted to an image
|
66
|
+
# RubyProf::DotPrinter
|
67
|
+
|
68
|
+
# - Creates a call tree report compatible with KCachegrind.
|
69
|
+
# RubyProf::CallTreePrinter
|
70
|
+
|
71
|
+
# - Uses the other printers to create several reports in one
|
72
|
+
# profiling run
|
73
|
+
# RubyProf::MultiPrinter
|
74
|
+
end
|
75
|
+
|
76
|
+
work
|
77
|
+
end
|
78
|
+
# :nocov:
|
79
|
+
|
80
|
+
end # Debug
|
81
|
+
|
82
|
+
end # Logging
|
83
|
+
|
84
|
+
end # Vedeu
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Vedeu
|
2
|
+
|
3
|
+
module Logging
|
4
|
+
|
5
|
+
# Ensures we can always write to the log file by creating a
|
6
|
+
# lock-less log device.
|
7
|
+
#
|
8
|
+
class LocklessLogDevice < ::Logger::LogDevice
|
9
|
+
|
10
|
+
# Returns a new instance of Vedeu::Logging::LocklessLogDevice.
|
11
|
+
#
|
12
|
+
# @param log [void]
|
13
|
+
# @return [Vedeu::Logging::LocklessLogDevice]
|
14
|
+
def initialize(log = nil)
|
15
|
+
@dev = nil
|
16
|
+
@filename = nil
|
17
|
+
|
18
|
+
if log.respond_to?(:write) && log.respond_to?(:close)
|
19
|
+
@dev = log
|
20
|
+
|
21
|
+
else
|
22
|
+
@dev = open_logfile(log)
|
23
|
+
@dev.sync = true
|
24
|
+
@filename = log
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# @param message [String]
|
30
|
+
# @return [void]
|
31
|
+
def write(message)
|
32
|
+
@dev.write(message)
|
33
|
+
|
34
|
+
rescue StandardError => exception
|
35
|
+
warn("log writing failed. #{exception}")
|
36
|
+
end
|
37
|
+
|
38
|
+
# @return [void]
|
39
|
+
def close
|
40
|
+
@dev.close
|
41
|
+
rescue
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
# @param log [String]
|
48
|
+
# @return [void]
|
49
|
+
def open_logfile(log)
|
50
|
+
if FileTest.exist?(log)
|
51
|
+
open(log, (File::WRONLY | File::APPEND))
|
52
|
+
|
53
|
+
else
|
54
|
+
logdev = open(log, (File::WRONLY | File::APPEND | File::CREAT))
|
55
|
+
logdev.sync = true
|
56
|
+
logdev
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end # LocklessLogDevice
|
62
|
+
|
63
|
+
end # Logging
|
64
|
+
|
65
|
+
end # Vedeu
|