vedeu 0.6.7 → 0.6.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/docs/dsl.md +4 -4
  4. data/lib/vedeu/all.rb +6 -18
  5. data/lib/vedeu/api.rb +14 -13
  6. data/lib/vedeu/bindings/system.rb +5 -4
  7. data/lib/vedeu/buffers/virtual_buffer.rb +13 -11
  8. data/lib/vedeu/configuration/api.rb +4 -3
  9. data/lib/vedeu/cursors/cursor.rb +23 -18
  10. data/lib/vedeu/distributed/client.rb +11 -6
  11. data/lib/vedeu/distributed/server.rb +4 -3
  12. data/lib/vedeu/dsl/keymap.rb +6 -6
  13. data/lib/vedeu/editor/all.rb +19 -0
  14. data/lib/vedeu/{input/editor → editor}/capture.rb +1 -1
  15. data/lib/vedeu/{input/editor → editor}/cropper.rb +0 -0
  16. data/lib/vedeu/{input/editor → editor}/cursor.rb +0 -0
  17. data/lib/vedeu/{input/editor → editor}/document.rb +0 -0
  18. data/lib/vedeu/{input/editor → editor}/documents.rb +0 -0
  19. data/lib/vedeu/{input/editor → editor}/editor.rb +0 -0
  20. data/lib/vedeu/{input/editor → editor}/insert.rb +0 -0
  21. data/lib/vedeu/{input/editor → editor}/line.rb +0 -0
  22. data/lib/vedeu/{input/editor → editor}/lines.rb +0 -0
  23. data/lib/vedeu/error.rb +21 -18
  24. data/lib/vedeu/esc/borders.rb +6 -4
  25. data/lib/vedeu/esc/colours.rb +13 -12
  26. data/lib/vedeu/esc/esc.rb +11 -10
  27. data/lib/vedeu/input/all.rb +15 -0
  28. data/lib/vedeu/input/input.rb +55 -52
  29. data/lib/vedeu/input/key.rb +36 -30
  30. data/lib/vedeu/input/keymap.rb +101 -92
  31. data/lib/vedeu/input/keymaps.rb +10 -6
  32. data/lib/vedeu/input/keys.rb +8 -4
  33. data/lib/vedeu/input/mapper.rb +125 -121
  34. data/lib/vedeu/input/translator.rb +159 -0
  35. data/lib/vedeu/internal_api.rb +16 -15
  36. data/lib/vedeu/logging/all.rb +13 -0
  37. data/lib/vedeu/logging/debug.rb +84 -0
  38. data/lib/vedeu/logging/lockless_log_device.rb +65 -0
  39. data/lib/vedeu/logging/log.rb +179 -0
  40. data/lib/vedeu/logging/mono_logger.rb +26 -0
  41. data/lib/vedeu/logging/timer.rb +68 -0
  42. data/lib/vedeu/menus/all.rb +12 -0
  43. data/lib/vedeu/{dsl/menu.rb → menus/dsl.rb} +19 -18
  44. data/lib/vedeu/menus/menu.rb +234 -0
  45. data/lib/vedeu/{null/menu.rb → menus/null.rb} +6 -6
  46. data/lib/vedeu/menus/repository.rb +18 -0
  47. data/lib/vedeu/models/cell.rb +62 -55
  48. data/lib/vedeu/models/escape.rb +55 -50
  49. data/lib/vedeu/models/page.rb +74 -69
  50. data/lib/vedeu/models/row.rb +55 -51
  51. data/lib/vedeu/models/views/all.rb +1 -0
  52. data/lib/vedeu/models/views/char.rb +1 -1
  53. data/lib/vedeu/models/views/html_char.rb +165 -0
  54. data/lib/vedeu/output/renderers/html.rb +5 -4
  55. data/lib/vedeu/repositories/model.rb +2 -0
  56. data/lib/vedeu/runtime/application.rb +110 -103
  57. data/lib/vedeu/runtime/bootstrap.rb +109 -103
  58. data/lib/vedeu/runtime/flags.rb +45 -41
  59. data/lib/vedeu/runtime/launcher.rb +1 -1
  60. data/lib/vedeu/runtime/main_loop.rb +51 -46
  61. data/lib/vedeu/runtime/traps.rb +20 -16
  62. data/lib/vedeu/version.rb +1 -1
  63. data/lib/vedeu.rb +2 -2
  64. data/test/lib/vedeu/buffers/virtual_buffer_test.rb +1 -1
  65. data/test/lib/vedeu/cursors/cursor_test.rb +11 -5
  66. data/test/lib/vedeu/dsl/interface_test.rb +1 -1
  67. data/test/lib/vedeu/dsl/keymap_test.rb +2 -2
  68. data/test/lib/vedeu/{input/editor → editor}/capture_test.rb +0 -0
  69. data/test/lib/vedeu/{input/editor → editor}/cropper_test.rb +0 -0
  70. data/test/lib/vedeu/{input/editor → editor}/cursor_test.rb +0 -0
  71. data/test/lib/vedeu/{input/editor → editor}/document_test.rb +0 -0
  72. data/test/lib/vedeu/{input/editor → editor}/documents_test.rb +0 -0
  73. data/test/lib/vedeu/{input/editor → editor}/editor_test.rb +0 -0
  74. data/test/lib/vedeu/{input/editor → editor}/insert_test.rb +0 -0
  75. data/test/lib/vedeu/{input/editor → editor}/line_test.rb +0 -0
  76. data/test/lib/vedeu/{input/editor → editor}/lines_test.rb +0 -0
  77. data/test/lib/vedeu/input/input_test.rb +58 -54
  78. data/test/lib/vedeu/input/key_test.rb +29 -25
  79. data/test/lib/vedeu/input/keymap_test.rb +74 -70
  80. data/test/lib/vedeu/input/keymaps_test.rb +8 -4
  81. data/test/lib/vedeu/input/keys_test.rb +12 -8
  82. data/test/lib/vedeu/input/mapper_test.rb +64 -56
  83. data/test/lib/vedeu/input/translator_test.rb +36 -0
  84. data/test/lib/vedeu/logging/debug_test.rb +39 -0
  85. data/test/lib/vedeu/logging/lockless_log_device_test.rb +42 -0
  86. data/test/lib/vedeu/logging/log_test.rb +52 -0
  87. data/test/lib/vedeu/logging/mono_logger_test.rb +43 -0
  88. data/test/lib/vedeu/logging/timer_test.rb +44 -0
  89. data/test/lib/vedeu/{dsl/menu_test.rb → menus/dsl_test.rb} +6 -6
  90. data/test/lib/vedeu/menus/menu_test.rb +305 -0
  91. data/test/lib/vedeu/{null/menu_test.rb → menus/null_test.rb} +5 -5
  92. data/test/lib/vedeu/menus/repository_test.rb +17 -0
  93. data/test/lib/vedeu/models/cell_test.rb +54 -50
  94. data/test/lib/vedeu/models/escape_test.rb +49 -45
  95. data/test/lib/vedeu/models/page_test.rb +167 -160
  96. data/test/lib/vedeu/models/row_test.rb +71 -67
  97. data/test/lib/vedeu/models/views/html_char_test.rb +110 -0
  98. data/test/lib/vedeu/output/compressor_test.rb +44 -22
  99. data/test/lib/vedeu/output/renderers_test.rb +4 -2
  100. data/test/lib/vedeu/runtime/application_test.rb +36 -32
  101. data/test/lib/vedeu/runtime/bootstrap_test.rb +31 -26
  102. data/test/lib/vedeu/runtime/flags_test.rb +33 -29
  103. data/test/lib/vedeu/runtime/launcher_test.rb +4 -2
  104. data/test/lib/vedeu/runtime/main_loop_test.rb +28 -24
  105. data/test/lib/vedeu/runtime/traps_test.rb +8 -4
  106. data/test/test_helper.rb +4 -2
  107. metadata +66 -63
  108. data/lib/vedeu/input/editor/all.rb +0 -19
  109. data/lib/vedeu/input/input_translator.rb +0 -155
  110. data/lib/vedeu/log/debug.rb +0 -79
  111. data/lib/vedeu/log/lockless_log_device.rb +0 -61
  112. data/lib/vedeu/log/log.rb +0 -172
  113. data/lib/vedeu/log/mono_logger.rb +0 -21
  114. data/lib/vedeu/log/timer.rb +0 -63
  115. data/lib/vedeu/models/menu.rb +0 -217
  116. data/lib/vedeu/models/menus.rb +0 -14
  117. data/lib/vedeu/output/html_char.rb +0 -161
  118. data/test/lib/vedeu/input/input_translator_test.rb +0 -32
  119. data/test/lib/vedeu/log/debug_test.rb +0 -35
  120. data/test/lib/vedeu/log/lockless_log_device_test.rb +0 -29
  121. data/test/lib/vedeu/log/log_test.rb +0 -48
  122. data/test/lib/vedeu/log/mono_logger_test.rb +0 -31
  123. data/test/lib/vedeu/log/timer_test.rb +0 -40
  124. data/test/lib/vedeu/models/menu_test.rb +0 -301
  125. data/test/lib/vedeu/models/menus_test.rb +0 -13
  126. data/test/lib/vedeu/output/html_char_test.rb +0 -106
@@ -1,127 +1,131 @@
1
1
  module Vedeu
2
2
 
3
- # Maps keys to keymaps.
4
- #
5
- class Mapper
3
+ module Input
6
4
 
7
- # Takes a key as a keypress and sends it to registered keymaps. If found,
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
- # @example
12
- # Vedeu.keypress(key_name, keymap_name)
13
- #
14
- # @param (see #initialize)
15
- # @return [Boolean]
16
- def self.keypress(key = nil, name = nil)
17
- Vedeu.trigger(:key, key)
18
-
19
- return false unless key
20
-
21
- new(key, name).keypress
22
- end
23
-
24
- # Checks a key is valid; i.e. not already registered to a keymap. When the
25
- # key is registered, then the key is invalid and cannot be used again.
26
- #
27
- # @param (see #initialize)
28
- # @return [Boolean]
29
- def self.valid?(key = nil, name = nil)
30
- return false unless key
31
-
32
- new(key, name).valid?
33
- end
34
-
35
- # Returns a new instance of Vedeu::Mapper.
36
- #
37
- # @param key [NilClass|String|Symbol]
38
- # @param name [NilClass|String]
39
- # @param repository [NilClass|Vedeu::Repository]
40
- # @return [Vedeu::Mapper]
41
- def initialize(key = nil, name = nil, repository = nil)
42
- @key = key
43
- @name = name
44
- @repository = repository || Vedeu.keymaps
45
- end
46
-
47
- # Returns a boolean indicating that the key is registered to the current
48
- # keymap, or the global keymap.
49
- #
50
- # @return [Boolean]
51
- def keypress
52
- return false unless key
53
-
54
- Vedeu.log(type: :input, message: "Key detected: #{key.inspect}")
55
-
56
- return true if key_defined? && keymap.use(key)
57
-
58
- return true if global_key? && keymap('_global_').use(key)
59
-
60
- false
61
- end
62
-
63
- # Returns a boolean indicating that the key is not registered to the current
64
- # keymap, or the global keymap.
65
- #
66
- # @return [Boolean]
67
- def valid?
68
- return false if !key || key_defined? || global_key?
69
-
70
- true
71
- end
72
-
73
- protected
74
-
75
- # @!attribute [r] key
76
- # @return [String|Symbol]
77
- attr_reader :key
78
-
79
- # @!attribute [r] repository
80
- # @return [Vedeu::Repository]
81
- attr_reader :repository
82
-
83
- private
84
-
85
- # Is the key a global key?
86
- #
87
- # @return [Boolean]
88
- def global_key?
89
- key_defined?('_global_')
90
- end
91
-
92
- # Is the key defined in the named keymap?
93
- #
94
- # @param named [NilClass|String]
95
- # @return [Boolean]
96
- def key_defined?(named = name)
97
- keymap?(named) && keymap(named).key_defined?(key)
98
- end
99
-
100
- # Fetch the named keymap from the repository.
101
- #
102
- # @param named [NilClass|String]
103
- # @return [Vedeu::Keymap]
104
- def keymap(named = name)
105
- repository.find(named)
106
- end
107
-
108
- # Does the keymaps repository have the named keymap already registered?
109
- #
110
- # @param named [NilClass|String]
111
- # @return [Boolean]
112
- def keymap?(named = name)
113
- repository.registered?(named)
114
- end
115
-
116
- # With a name, we check the keymap with that name, otherwise we use the
117
- # name of the interface currently in focus.
118
- #
119
- # @return [String|NilClass]
120
- def name
121
- @name || Vedeu.focus
122
- end
123
- alias_method :interface, :name
124
-
125
- end # Mapper
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
@@ -1,8 +1,8 @@
1
1
  module Vedeu
2
2
 
3
- # Vedeu's internal API methods provide convenient ways to access Vedeu's
4
- # internals. They are not supposed to be used by client applications as they
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 ruby-prof.
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 as the
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,13 @@
1
+ module Vedeu
2
+
3
+ module Logging
4
+
5
+ end # Logging
6
+
7
+ end # Vedeu
8
+
9
+ require 'vedeu/logging/lockless_log_device'
10
+ require 'vedeu/logging/mono_logger'
11
+ require 'vedeu/logging/log'
12
+ require 'vedeu/logging/debug'
13
+ require 'vedeu/logging/timer'
@@ -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