vedeu 0.0.39 → 0.0.40

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -30
  3. data/Rakefile +8 -9
  4. data/bin/log +13 -0
  5. data/deps.md +11 -95
  6. data/lib/vedeu.rb +14 -46
  7. data/lib/vedeu/application.rb +4 -8
  8. data/lib/vedeu/instrumentation.rb +111 -0
  9. data/lib/vedeu/launcher.rb +2 -2
  10. data/lib/vedeu/models/attributes/interface_collection.rb +2 -2
  11. data/lib/vedeu/models/attributes/line_collection.rb +2 -2
  12. data/lib/vedeu/models/attributes/stream_collection.rb +2 -2
  13. data/lib/vedeu/models/colour.rb +1 -1
  14. data/lib/vedeu/models/composition.rb +1 -1
  15. data/lib/vedeu/models/interface.rb +18 -10
  16. data/lib/vedeu/models/line.rb +3 -3
  17. data/lib/vedeu/models/presentation.rb +1 -1
  18. data/lib/vedeu/models/stream.rb +2 -2
  19. data/lib/vedeu/models/style.rb +1 -1
  20. data/lib/vedeu/output/render_interface.rb +1 -1
  21. data/lib/vedeu/{support → parsing}/compositor.rb +1 -1
  22. data/lib/vedeu/parsing/hash_parser.rb +1 -1
  23. data/lib/vedeu/parsing/parser.rb +6 -10
  24. data/lib/vedeu/{models/builders → support}/builder.rb +19 -9
  25. data/lib/vedeu/support/esc.rb +1 -1
  26. data/lib/vedeu/support/events.rb +15 -19
  27. data/lib/vedeu/support/geometry.rb +3 -3
  28. data/lib/vedeu/{input → support}/input.rb +6 -9
  29. data/lib/vedeu/support/menu.rb +3 -3
  30. data/lib/vedeu/support/persistence.rb +41 -0
  31. data/lib/vedeu/support/terminal.rb +1 -1
  32. data/test/example_app/lib/app.rb +85 -5
  33. data/test/lib/vedeu/application_test.rb +2 -2
  34. data/test/lib/vedeu/configuration_test.rb +2 -2
  35. data/test/lib/vedeu/launcher_test.rb +2 -2
  36. data/test/lib/vedeu/models/attributes/collection_test.rb +2 -2
  37. data/test/lib/vedeu/models/attributes/interface_collection_test.rb +4 -4
  38. data/test/lib/vedeu/models/attributes/line_collection_test.rb +3 -3
  39. data/test/lib/vedeu/models/attributes/stream_collection_test.rb +3 -3
  40. data/test/lib/vedeu/models/colour_test.rb +2 -2
  41. data/test/lib/vedeu/models/composition_test.rb +19 -19
  42. data/test/lib/vedeu/models/interface_test.rb +46 -34
  43. data/test/lib/vedeu/models/line_test.rb +2 -2
  44. data/test/lib/vedeu/models/presentation_test.rb +2 -2
  45. data/test/lib/vedeu/models/stream_test.rb +2 -2
  46. data/test/lib/vedeu/models/style_test.rb +31 -31
  47. data/test/lib/vedeu/output/clear_interface_test.rb +5 -5
  48. data/test/lib/vedeu/output/render_interface_test.rb +5 -6
  49. data/test/lib/vedeu/output/template.rb +2 -1
  50. data/test/lib/vedeu/{support → parsing}/compositor_test.rb +6 -4
  51. data/test/lib/vedeu/parsing/hash_parser_test.rb +2 -2
  52. data/test/lib/vedeu/parsing/json_parser_test.rb +2 -2
  53. data/test/lib/vedeu/parsing/parser_test.rb +6 -5
  54. data/test/lib/vedeu/parsing/text_adaptor_test.rb +2 -2
  55. data/test/lib/vedeu/{models/builders/interface_builder_test.rb → support/builder_test.rb} +10 -10
  56. data/test/lib/vedeu/support/esc_test.rb +2 -2
  57. data/test/lib/vedeu/support/events_test.rb +2 -2
  58. data/test/lib/vedeu/support/geometry_test.rb +2 -2
  59. data/test/lib/vedeu/{input → support}/input_test.rb +6 -7
  60. data/test/lib/vedeu/support/menu_test.rb +2 -2
  61. data/test/lib/vedeu/support/persistence_test.rb +55 -0
  62. data/test/lib/vedeu/support/queue_test.rb +2 -2
  63. data/test/lib/vedeu/support/terminal_test.rb +2 -2
  64. data/test/lib/vedeu/support/translator_test.rb +2 -2
  65. data/test/lib/vedeu/support/wordwrap_test.rb +2 -2
  66. data/test/lib/vedeu_test.rb +17 -2
  67. data/test/support/bench.rb +34 -0
  68. data/test/test_helper.rb +3 -11
  69. data/vedeu.gemspec +2 -2
  70. metadata +20 -44
  71. data/lib/vedeu/models/builders/command_builder.rb +0 -10
  72. data/lib/vedeu/models/builders/interface_builder.rb +0 -32
  73. data/lib/vedeu/models/command.rb +0 -23
  74. data/lib/vedeu/output/output.rb +0 -14
  75. data/lib/vedeu/process/process.rb +0 -51
  76. data/lib/vedeu/repository/command_repository.rb +0 -31
  77. data/lib/vedeu/repository/interface_repository.rb +0 -31
  78. data/lib/vedeu/repository/repository.rb +0 -41
  79. data/lib/vedeu/repository/storage.rb +0 -40
  80. data/lib/vedeu/support/exit.rb +0 -9
  81. data/test/lib/vedeu/models/builders/builder_test.rb +0 -11
  82. data/test/lib/vedeu/models/builders/command_builder_test.rb +0 -16
  83. data/test/lib/vedeu/models/command_test.rb +0 -40
  84. data/test/lib/vedeu/output/output_test.rb +0 -19
  85. data/test/lib/vedeu/process/process_test.rb +0 -71
  86. data/test/lib/vedeu/repository/command_repository_test.rb +0 -55
  87. data/test/lib/vedeu/repository/interface_repository_test.rb +0 -67
  88. data/test/lib/vedeu/repository/repository_test.rb +0 -81
  89. data/test/lib/vedeu/repository/storage_test.rb +0 -70
  90. data/test/lib/vedeu/support/exit_test.rb +0 -12
  91. data/test/support/dummy_command.rb +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3f1858b317f4c614c4171d5d1032e7f512f093a6
4
- data.tar.gz: b33301029f63c79baeef259eac052cd109634415
3
+ metadata.gz: 5d50ccc8e12767562af12af4793529e7349194a4
4
+ data.tar.gz: 3f0eede2555296556c6be6f229f8393d9597a2f4
5
5
  SHA512:
6
- metadata.gz: cd006607dbf4753ca9a488298d6054e68db1425a4807ad058cbbc4c3d779b45ae030f9e4ca7d4b1db611c12ac70abfb44cc6b81d2f523ba09a916649a64181e5
7
- data.tar.gz: be1a3ab07377b3385f7d0b2611989edc59c6cb84b6ecfeecf40e2b843c2dd4a344a67e3ab153bfc9b6e9dd2a3de75dae407ecdd3b11cf52dde47240660f82e59
6
+ metadata.gz: db682960148fc784f0b8dd745a1afd820e1698b0d0ab71d6f29c30a77ad42f159300ebaec49c235228354a1788ab30929c981eaa4d5c6aee843d7467c20c64ff
7
+ data.tar.gz: c75a838470727f59dba50085130228ff295a7a1fa8f2af34caad8d0f25bfdcfc5dfd5c7939b41e3a0fa37726c4a1440c4f0bd410334d7d4e698b798aeaae49d8
data/README.md CHANGED
@@ -31,12 +31,6 @@ Expect proper documentation soon!
31
31
  ...
32
32
  end
33
33
 
34
- command 'thing' do
35
- entity SomeClass
36
- keypress 't'
37
- keyword 'thing'
38
- end
39
-
40
34
  event :some_event do
41
35
  # ...
42
36
  end
@@ -76,7 +70,6 @@ To understand how Vedeu works, you need to familiarise yourself with some terms.
76
70
  interface 'main' do
77
71
  y 1
78
72
  x 1
79
- z 1
80
73
  width 10 # see notes below
81
74
  height 10
82
75
  colour foreground: '#ffffff', background: '#000000'
@@ -87,8 +80,6 @@ Referring to the above example, interfaces have a name, and various default attr
87
80
 
88
81
  `y` sets the starting row point. (See Geometry)
89
82
  `x` sets the starting column point.
90
- `z` an integer specifying the z-index of the interface.
91
- (See Layers)
92
83
 
93
84
  `width` sets character width of the interface
94
85
  `height` sets character height of the interface
@@ -100,18 +91,6 @@ Referring to the above example, interfaces have a name, and various default attr
100
91
  `cursor` a boolean specifying whether the cursor should show.
101
92
 
102
93
 
103
- ### On Defining Commands
104
-
105
- command 'do_something' do
106
- entity SomeClass
107
- keypress 's'
108
- keyword 'start'
109
- arguments [:some, { :values => :here }, "etc"]
110
- end
111
-
112
- As above, commands have a name, a class which performs the action
113
- (you define this), and they can be invoked with a keypress or a keyword. At this time, Vedeu will call the `.dispatch` method on your class, passing any arguments you originally defined in the command. In the future, both the method called and the arguments could be dynamic.
114
-
115
94
  ### On Defining Events
116
95
 
117
96
  event :event_name do |arg1, arg2|
@@ -149,15 +128,6 @@ Vedeu has a range of symbol styles which are compatible with most terminals whic
149
128
  Like colours, they can be defined in either interfaces, for specific lines or within streams. Styles are applied as encountered.
150
129
 
151
130
 
152
- ### Layers
153
-
154
- Vedeu allows the overlaying of interfaces. To render these correctly,
155
- Vedeu uses two rules.
156
-
157
- 1) The :z value. 1 would be default, or bottom. 2 would be placed on top of 1. 3 on top of 2, and so on.
158
- 2) If two interfaces occupy the same 'space', the interface which was defined last, wins.
159
-
160
-
161
131
  ## Contributing
162
132
 
163
133
  1. Fork it ( http://github.com/gavinlaking/vedeu/fork )
data/Rakefile CHANGED
@@ -1,11 +1,10 @@
1
- require 'bundler/gem_tasks'
2
- require 'rake/testtask'
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
3
 
4
- Rake::TestTask.new(:minitest) do |t|
5
- t.libs << 'lib/vedeu'
6
- t.test_files = FileList['test/lib/vedeu/*_test.rb',
7
- 'test/lib/vedeu/**/*_test.rb']
8
- # t.options = '-v' # verbose mode
9
- end
4
+ task :default => :test
10
5
 
11
- task default: :minitest
6
+ Rake::TestTask.new do |t|
7
+ t.libs.push "lib"
8
+ t.libs.push "test"
9
+ t.pattern = "test/**/*_test.rb"
10
+ end
data/bin/log ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')
3
+
4
+ -> { its -> { a } }
5
+ trap('INT') { exit! }
6
+
7
+ require 'vedeu'
8
+
9
+ loop do
10
+ Vedeu.log('-B<-------------------------------------------------------------------')
11
+
12
+ sleep 10
13
+ end
data/deps.md CHANGED
@@ -4,11 +4,13 @@ By class
4
4
 
5
5
  Application
6
6
  Input
7
- Output
8
7
  Process
9
8
  Terminal
10
9
 
11
10
  Builder
11
+ Geometry
12
+ Interface
13
+ Persistence
12
14
 
13
15
  ClearInterface
14
16
 
@@ -17,16 +19,6 @@ Collection
17
19
  Colour
18
20
  Esc
19
21
 
20
- Command
21
-
22
- CommandBuilder
23
- Builder
24
- CommandRepository
25
-
26
- CommandRepository
27
- Command
28
- Repository
29
-
30
22
  Composition
31
23
  InterfaceCollection
32
24
 
@@ -44,8 +36,6 @@ Esc
44
36
 
45
37
  Events
46
38
 
47
- Exit
48
-
49
39
  HashParser
50
40
  TextAdaptor
51
41
 
@@ -63,17 +53,8 @@ Interface
63
53
  Style
64
54
  Terminal
65
55
 
66
- InterfaceBuilder
67
- Builder
68
- Geometry
69
- InterfaceRepository
70
-
71
56
  InterfaceCollection
72
- InterfaceRepository
73
-
74
- InterfaceRepository
75
- Interface
76
- Repository
57
+ Persistence
77
58
 
78
59
  JSONParser
79
60
 
@@ -92,20 +73,18 @@ LineCollection
92
73
 
93
74
  Menu
94
75
 
95
- Output
96
- InterfaceRepository
97
- Terminal
98
-
99
76
  Parser
100
77
  Compositor
101
78
  HashParser
102
79
  JSONParser
103
80
 
81
+ Persistence
82
+ Interface
83
+
104
84
  Presentation
105
85
  Colour
106
86
 
107
87
  Process
108
- CommandRepository
109
88
  Parser
110
89
  Queue
111
90
 
@@ -114,11 +93,6 @@ Queue
114
93
  RenderInterface
115
94
  ClearInterface
116
95
 
117
- Repository
118
- Storage
119
-
120
- Storage
121
-
122
96
  Stream
123
97
  Presentation
124
98
  Style
@@ -150,19 +124,15 @@ Orphans
150
124
  Template - orphaned
151
125
  Wordwrap - orphaned
152
126
  Menu - orphaned
153
- Exit - orphaned
154
127
 
155
128
  ----------------------------------------------------------------------
156
129
  Grouped
157
130
  ----------------------------------------------------------------------
158
131
 
159
- CommandBuilder
160
- Builder
161
-
162
- InterfaceBuilder
163
- Builder
132
+ Builder
133
+ Interface
164
134
  Geometry
165
- InterfaceRepository
135
+ Persistence
166
136
 
167
137
  Launcher
168
138
  Application
@@ -171,64 +141,12 @@ Launcher
171
141
  Terminal
172
142
  Esc
173
143
  Translator
174
- Output
175
- InterfaceRepository
176
- Interface
177
- ClearInterface
178
- Geometry
179
- Esc
180
- Translator
181
- Terminal
182
- Esc
183
- Translator
184
- LineCollection
185
- Collection
186
- Line
187
- Presentation
188
- Colour
189
- Esc
190
- Translator
191
- StreamCollection
192
- Collection
193
- Stream
194
- Presentation
195
- Colour
196
- Esc
197
- Translator
198
- Style
199
- Esc
200
- Translator
201
- Style
202
- Esc
203
- Translator
204
- Presentation
205
- Colour
206
- Esc
207
- Translator
208
- Queue
209
- RenderInterface
210
- ClearInterface
211
- Style
212
- Esc
213
- Translator
214
- Terminal
215
- Esc
216
- Translator
217
- Repository
218
- Storage
219
- Terminal
220
- Esc
221
- Translator
222
144
  Process
223
- CommandRepository
224
- Command
225
- Repository
226
- Storage
227
145
  Parser
228
146
  Compositor
229
147
  Composition
230
148
  InterfaceCollection
231
- InterfaceRepository
149
+ Persistence
232
150
  Interface
233
151
  ClearInterface
234
152
  Geometry
@@ -270,8 +188,6 @@ Launcher
270
188
  Terminal
271
189
  Esc
272
190
  Translator
273
- Repository
274
- Storage
275
191
  HashParser
276
192
  TextAdaptor
277
193
  JSONParser
data/lib/vedeu.rb CHANGED
@@ -1,23 +1,17 @@
1
- require 'date'
2
- require 'logger'
3
-
4
- require_relative 'vedeu/models/builders/command_builder'
5
- require_relative 'vedeu/models/builders/interface_builder'
6
- require_relative 'vedeu/support/events'
7
- require_relative 'vedeu/support/geometry'
8
- require_relative 'vedeu/support/menu'
9
- require_relative 'vedeu/support/exit'
10
- require_relative 'vedeu/launcher'
1
+ require 'vedeu/instrumentation'
2
+ require 'vedeu/support/builder'
3
+ require 'vedeu/support/events'
4
+ require 'vedeu/support/geometry'
5
+ require 'vedeu/support/menu'
6
+ require 'vedeu/launcher'
11
7
 
12
8
  module Vedeu
9
+ # Vedeu::Instrumentation::Trace.call
10
+
13
11
  # :nocov:
14
12
  module ClassMethods
15
- def command(name, &block)
16
- CommandBuilder.build(name, &block)
17
- end
18
-
19
13
  def interface(name, &block)
20
- InterfaceBuilder.build(name, &block)
14
+ Builder.build(name, &block)
21
15
  end
22
16
 
23
17
  def event(name, &block)
@@ -34,49 +28,23 @@ module Vedeu
34
28
  def self.events
35
29
  @events ||= Events.new do
36
30
  on(:_exit_) { fail StopIteration }
37
- on(:_log_) { |message| Vedeu.logger.debug(message) }
31
+ on(:_log_) { |message| Vedeu.log(message) }
38
32
  on(:_mode_switch_) { fail ModeSwitch }
39
33
 
40
34
  on(:_keypress_) do |key|
41
35
  trigger(:key, key)
42
- trigger(:_log_, "key: #{key}")
36
+ trigger(:_log_, (' ' * 42) + "key: #{key}")
43
37
  trigger(:_mode_switch_) if key == :escape
44
38
  end
45
39
  end
46
40
  end
47
41
 
48
- def self.logger
49
- @logger ||= Logger.new(root_path + '/logs/vedeu.log').tap do |log|
50
- log.formatter = proc do |_, time, _, msg|
51
- "\n#{time.iso8601}: #{msg}\n"
52
- end
53
- end
54
- end
55
-
56
- def self.error(exception)
57
- logger.debug "\e[38;5;196mError:\e[38;2;39m\e[48;2;49m " +
58
- "#{exception.message}\n\n" +
59
- exception.backtrace.join("\n")
60
- end
61
-
62
- def self.debug(filename = 'profile.html', &block)
63
- require 'ruby-prof'
64
-
65
- RubyProf.start
66
-
67
- yield
68
-
69
- result = RubyProf.stop
70
- result.eliminate_methods!([/^Array/, /^Hash/])
71
-
72
- File.open(Vedeu.root_path + '/tmp/' + filename, 'w') do |file|
73
- RubyProf::CallStackPrinter.new(result).print(file)
74
- # RubyProf::GraphPrinter.new(result).print(file)
75
- end
42
+ def self.log(message)
43
+ Vedeu::Instrumentation::Log.logger.debug(message)
76
44
  end
77
45
 
78
46
  def self.included(receiver)
79
- receiver.send :include, ClassMethods
47
+ receiver.send(:include, ClassMethods)
80
48
  receiver.extend(ClassMethods)
81
49
  end
82
50
 
@@ -1,7 +1,5 @@
1
- require_relative 'input/input'
2
- require_relative 'output/output'
3
- require_relative 'process/process'
4
- require_relative 'support/terminal'
1
+ require 'vedeu/support/input'
2
+ require 'vedeu/support/terminal'
5
3
 
6
4
  module Vedeu
7
5
  ModeSwitch = Class.new(StandardError)
@@ -20,7 +18,7 @@ module Vedeu
20
18
  Terminal.open(mode) do
21
19
  Terminal.set_cursor_mode
22
20
 
23
- Output.render
21
+ Vedeu.events.trigger(:refresh)
24
22
 
25
23
  runner { main_sequence }
26
24
  end
@@ -43,9 +41,7 @@ module Vedeu
43
41
  def main_sequence
44
42
  Input.capture
45
43
 
46
- Process.evaluate
47
-
48
- Output.render
44
+ Vedeu.events.trigger(:refresh)
49
45
  end
50
46
 
51
47
  def interactive?
@@ -0,0 +1,111 @@
1
+ require 'date'
2
+ require 'logger'
3
+ require 'ruby-prof'
4
+
5
+ require 'vedeu'
6
+
7
+ module Vedeu
8
+ module Instrumentation
9
+ # :nocov:
10
+ class Log
11
+ def self.logger
12
+ @logger ||= Logger.new(filename).tap do |log|
13
+ log.formatter = proc do |_, time, _, message|
14
+ time.utc.iso8601 + ": " + message + "\n"
15
+ end
16
+ end
17
+ end
18
+
19
+ def self.error(exception)
20
+ logger.debug(exception.message + "\n" +
21
+ exception.backtrace.join("\n"))
22
+ end
23
+
24
+ private
25
+
26
+ def self.filename
27
+ Vedeu.root_path + '/logs/vedeu.log'
28
+ end
29
+ end
30
+
31
+ class Profile
32
+ def self.call(filename = 'profile.html', &block)
33
+ new(filename).profile(&block)
34
+ end
35
+
36
+ def initialize(filename)
37
+ @filename = filename
38
+ end
39
+
40
+ def profile(&block)
41
+ RubyProf.start
42
+
43
+ yield
44
+
45
+ result = RubyProf.stop.eliminate_methods!([/^Array/, /^Hash/])
46
+
47
+ File.open(filename, 'w') do |file|
48
+ RubyProf::CallStackPrinter.new(result).print(file)
49
+ RubyProf::GraphPrinter.new(result).print(file)
50
+ end
51
+ end
52
+
53
+ private
54
+
55
+ def filename
56
+ Vedeu.root_path + '/tmp/' + @filename
57
+ end
58
+ end
59
+
60
+ class Trace
61
+ def self.call(options = {})
62
+ new(options).trace
63
+ end
64
+
65
+ def initialize(options = {})
66
+ @options = options
67
+ end
68
+
69
+ def trace
70
+ set_trace_func proc { |event, file, line, id, binding, classname|
71
+ if event == watched && classname.to_s.match(klass)
72
+ Vedeu.log(sprintf(" %s %-35s #%s", event, classname, id))
73
+ # binding.eval('local_variables').each do |var|
74
+ # print("#{var.to_s} = #{binding.local_variable_get(var).inspect}\n")
75
+ # end
76
+ end
77
+ }
78
+ end
79
+
80
+ private
81
+
82
+ def pretty!(&block)
83
+ ["\e[38;5;#{rand(22..231)}m", yield, "\e[38;2;39m"].join
84
+
85
+ end
86
+
87
+ def watched
88
+ options[:event]
89
+ end
90
+
91
+ def klass
92
+ options[:klass]
93
+ end
94
+
95
+ def options
96
+ defaults.merge!(@options)
97
+ end
98
+
99
+ def defaults
100
+ {
101
+ event: 'call',
102
+ klass: /^Vedeu::(?!.*Instrumentation|Line|Stream|Style|Colour|Geometry|Terminal|Esc|Translator).*/
103
+ }
104
+ end
105
+
106
+ # everything except Interface, Geometry and Terminal
107
+ # klass: /^Vedeu::(?!.*Interface|Geometry|Terminal).*/
108
+ end
109
+ # :nocov:
110
+ end
111
+ end