vedeu 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/LICENSE.txt +5 -0
  4. data/bin/vedeu +3 -1
  5. data/docs/api.md +2 -0
  6. data/examples/cursor_app/cursor_app.rb +22 -7
  7. data/examples/hello_world.rb +42 -0
  8. data/lib/vedeu.rb +5 -5
  9. data/lib/vedeu/api/api.rb +16 -33
  10. data/lib/vedeu/api/helpers.rb +86 -0
  11. data/lib/vedeu/api/interface.rb +60 -17
  12. data/lib/vedeu/api/keymap.rb +5 -0
  13. data/lib/vedeu/api/line.rb +52 -34
  14. data/lib/vedeu/api/menu.rb +1 -1
  15. data/lib/vedeu/api/stream.rb +0 -34
  16. data/lib/vedeu/configuration/api.rb +10 -10
  17. data/lib/vedeu/configuration/cli.rb +1 -1
  18. data/lib/vedeu/launcher.rb +21 -6
  19. data/lib/vedeu/models/background.rb +1 -1
  20. data/lib/vedeu/models/composition.rb +1 -1
  21. data/lib/vedeu/models/cursor.rb +25 -35
  22. data/lib/vedeu/models/foreground.rb +1 -1
  23. data/lib/vedeu/models/geometry.rb +216 -6
  24. data/lib/vedeu/models/interface.rb +14 -16
  25. data/lib/vedeu/models/keymap.rb +38 -6
  26. data/lib/vedeu/models/line.rb +1 -1
  27. data/lib/vedeu/models/stream.rb +1 -1
  28. data/lib/vedeu/output/compositor.rb +1 -1
  29. data/lib/vedeu/output/render.rb +1 -5
  30. data/lib/vedeu/output/viewport.rb +37 -2
  31. data/lib/vedeu/repositories/buffers.rb +21 -27
  32. data/lib/vedeu/repositories/cursors.rb +3 -15
  33. data/lib/vedeu/repositories/focus.rb +2 -6
  34. data/lib/vedeu/repositories/groups.rb +1 -1
  35. data/lib/vedeu/repositories/interfaces.rb +1 -1
  36. data/lib/vedeu/repositories/keymaps.rb +26 -22
  37. data/lib/vedeu/repositories/menus.rb +1 -1
  38. data/lib/vedeu/repositories/offsets.rb +30 -12
  39. data/lib/vedeu/repositories/positional.rb +23 -0
  40. data/lib/vedeu/support/colour_translator.rb +1 -16
  41. data/lib/vedeu/support/esc.rb +23 -28
  42. data/lib/vedeu/support/event.rb +6 -14
  43. data/lib/vedeu/{output → support}/refresh.rb +0 -0
  44. data/lib/vedeu/support/registrar.rb +6 -14
  45. data/lib/vedeu/support/repository.rb +3 -2
  46. data/lib/vedeu/support/terminal.rb +9 -13
  47. data/lib/vedeu/support/trace.rb +2 -3
  48. data/test/integration/cursors_test.rb +9 -0
  49. data/test/integration/views/basic_view_test.rb +19 -0
  50. data/test/lib/vedeu/api/api_test.rb +28 -5
  51. data/test/lib/vedeu/api/composition_test.rb +7 -3
  52. data/test/lib/vedeu/api/defined_test.rb +9 -3
  53. data/test/lib/vedeu/api/helpers_test.rb +39 -5
  54. data/test/lib/vedeu/api/interface_test.rb +88 -8
  55. data/test/lib/vedeu/api/keymap_test.rb +5 -3
  56. data/test/lib/vedeu/api/line_test.rb +9 -3
  57. data/test/lib/vedeu/api/menu_test.rb +11 -7
  58. data/test/lib/vedeu/api/stream_test.rb +9 -31
  59. data/test/lib/vedeu/application_test.rb +25 -2
  60. data/test/lib/vedeu/configuration/api_test.rb +5 -3
  61. data/test/lib/vedeu/configuration/cli_test.rb +5 -3
  62. data/test/lib/vedeu/configuration/configuration_test.rb +5 -2
  63. data/test/lib/vedeu/input/input_test.rb +5 -2
  64. data/test/lib/vedeu/launcher_test.rb +37 -2
  65. data/test/lib/vedeu/models/background_test.rb +6 -2
  66. data/test/lib/vedeu/models/char_test.rb +9 -6
  67. data/test/lib/vedeu/models/colour_test.rb +6 -2
  68. data/test/lib/vedeu/models/composition_test.rb +4 -2
  69. data/test/lib/vedeu/models/cursor_test.rb +27 -16
  70. data/test/lib/vedeu/models/foreground_test.rb +6 -2
  71. data/test/lib/vedeu/models/geometry_test.rb +6 -2
  72. data/test/lib/vedeu/models/interface_test.rb +5 -2
  73. data/test/lib/vedeu/models/keymap_test.rb +6 -4
  74. data/test/lib/vedeu/models/line_test.rb +5 -2
  75. data/test/lib/vedeu/models/offset_test.rb +7 -3
  76. data/test/lib/vedeu/models/stream_test.rb +4 -2
  77. data/test/lib/vedeu/models/style_test.rb +5 -2
  78. data/test/lib/vedeu/output/clear_test.rb +6 -2
  79. data/test/lib/vedeu/output/compositor_test.rb +8 -4
  80. data/test/lib/vedeu/output/render_test.rb +9 -6
  81. data/test/lib/vedeu/output/view_test.rb +7 -3
  82. data/test/lib/vedeu/output/viewport_test.rb +42 -9
  83. data/test/lib/vedeu/repositories/buffers_test.rb +52 -12
  84. data/test/lib/vedeu/repositories/cursors_test.rb +4 -26
  85. data/test/lib/vedeu/repositories/events_test.rb +6 -2
  86. data/test/lib/vedeu/repositories/focus_test.rb +5 -2
  87. data/test/lib/vedeu/repositories/groups_test.rb +5 -2
  88. data/test/lib/vedeu/repositories/interfaces_test.rb +4 -2
  89. data/test/lib/vedeu/repositories/keymaps_test.rb +8 -2
  90. data/test/lib/vedeu/repositories/menus_test.rb +3 -2
  91. data/test/lib/vedeu/repositories/offsets_test.rb +26 -19
  92. data/test/lib/vedeu/repositories/positional_test.rb +50 -0
  93. data/test/lib/vedeu/support/coercions_test.rb +7 -3
  94. data/test/lib/vedeu/support/colour_translator_test.rb +6 -2
  95. data/test/lib/vedeu/support/common_test.rb +5 -3
  96. data/test/lib/vedeu/support/esc_test.rb +6 -2
  97. data/test/lib/vedeu/support/event_test.rb +6 -2
  98. data/test/lib/vedeu/support/grid_test.rb +9 -3
  99. data/test/lib/vedeu/support/keymap_validator_test.rb +5 -2
  100. data/test/lib/vedeu/support/log_test.rb +4 -2
  101. data/test/lib/vedeu/support/menu_test.rb +10 -2
  102. data/test/lib/vedeu/support/position_test.rb +10 -2
  103. data/test/lib/vedeu/support/presentation_test.rb +6 -3
  104. data/test/lib/vedeu/{output → support}/refresh_test.rb +6 -2
  105. data/test/lib/vedeu/support/registrar_test.rb +2 -2
  106. data/test/lib/vedeu/support/repository_test.rb +4 -3
  107. data/test/lib/vedeu/support/terminal_test.rb +6 -2
  108. data/test/lib/vedeu/support/trace_test.rb +17 -2
  109. data/test/lib/vedeu_test.rb +1 -1
  110. data/vedeu.gemspec +2 -2
  111. metadata +13 -13
  112. data/lib/vedeu/output/area.rb +0 -284
  113. data/lib/vedeu/support/move.rb +0 -50
  114. data/test/lib/vedeu/output/area_test.rb +0 -242
  115. data/test/lib/vedeu/support/move_test.rb +0 -35
@@ -82,7 +82,7 @@ module Vedeu
82
82
 
83
83
  # @return [Boolean]
84
84
  def valid_name?
85
- codes.keys.include?(colour)
85
+ Esc.codes.keys.include?(colour)
86
86
  end
87
87
 
88
88
  # @return [Boolean]
@@ -154,21 +154,6 @@ module Vedeu
154
154
  (css_to_rgb[2] / 51) * 1
155
155
  end
156
156
 
157
- # @return [Hash]
158
- def codes
159
- {
160
- black: 30,
161
- red: 31,
162
- green: 32,
163
- yellow: 33,
164
- blue: 34,
165
- magenta: 35,
166
- cyan: 36,
167
- white: 37,
168
- default: 39,
169
- }
170
- end
171
-
172
157
  end # ColourTranslator
173
158
 
174
159
  end # Vedeu
@@ -8,6 +8,21 @@ module Vedeu
8
8
 
9
9
  extend self
10
10
 
11
+ # @return [Hash]
12
+ def codes
13
+ {
14
+ black: 30,
15
+ red: 31,
16
+ green: 32,
17
+ yellow: 33,
18
+ blue: 34,
19
+ magenta: 35,
20
+ cyan: 36,
21
+ white: 37,
22
+ default: 39,
23
+ }
24
+ end
25
+
11
26
  # Dynamically creates methods for each terminal named colour. When a block
12
27
  # is given, then the colour is reset to 'default' once the block is called.
13
28
  #
@@ -21,17 +36,7 @@ module Vedeu
21
36
  # Esc.on_blue { 'some text' } # => "\e[44msome text\e[49m"
22
37
  #
23
38
  # @return [String]
24
- {
25
- black: 30,
26
- red: 31,
27
- green: 32,
28
- yellow: 33,
29
- blue: 34,
30
- magenta: 35,
31
- cyan: 36,
32
- white: 37,
33
- default: 39,
34
- }.each do |key, code|
39
+ codes.each do |key, code|
35
40
  define_method(key) do |&blk|
36
41
  "\e[#{code}m" + (blk ? blk.call + "\e[39m" : '')
37
42
  end
@@ -119,28 +124,24 @@ module Vedeu
119
124
 
120
125
  # @return [String]
121
126
  def clear
122
- [ string('fg_reset'),
123
- string('bg_reset'),
127
+ [ colour_reset,
124
128
  "\e[2J" ].join
125
129
  end
126
130
 
127
131
  # @return [String]
128
132
  def clear_line
129
- [ string('fg_reset'),
130
- string('bg_reset'),
133
+ [ colour_reset,
131
134
  "\e[2K" ].join
132
135
  end
133
136
 
134
137
  # @return [String]
135
138
  def clear_last_line
136
- [ set_position((Terminal.height - 1), 1),
137
- string('clear_line') ].join
139
+ [set_position((Terminal.height - 1), 1), clear_line].join
138
140
  end
139
141
 
140
142
  # @return [String]
141
143
  def colour_reset
142
- [ string('fg_reset'),
143
- string('bg_reset') ].join
144
+ [fg_reset, bg_reset].join
144
145
  end
145
146
 
146
147
  # @return [String]
@@ -165,9 +166,7 @@ module Vedeu
165
166
 
166
167
  # @return [String]
167
168
  def normal
168
- [ string('underline_off'),
169
- string('bold_off'),
170
- string('positive') ].join
169
+ [underline_off, bold_off, positive].join
171
170
  end
172
171
 
173
172
  # @return [String]
@@ -182,16 +181,12 @@ module Vedeu
182
181
 
183
182
  # @return [String]
184
183
  def screen_init
185
- [ string('reset'),
186
- string('clear'),
187
- string('hide_cursor') ].join
184
+ [reset, clear, hide_cursor].join
188
185
  end
189
186
 
190
187
  # @return [String]
191
188
  def screen_exit
192
- [ string('show_cursor'),
193
- string('colour_reset'),
194
- string('reset') ].join
189
+ [show_cursor, colour_reset, reset].join
195
190
  end
196
191
 
197
192
  # @return [String]
@@ -64,15 +64,11 @@ module Vedeu
64
64
  #
65
65
  # @return [Boolean]
66
66
  def throttle_expired?
67
- if elapsed_time > delay
68
- true
67
+ return true if elapsed_time > delay
69
68
 
70
- else
71
- Vedeu.log("Throttling event '#{event_name}'")
69
+ Vedeu.log("Throttling event '#{event_name}'")
72
70
 
73
- false
74
-
75
- end
71
+ false
76
72
  end
77
73
 
78
74
  # Returns a boolean indicating whether debouncing is required for this
@@ -92,15 +88,11 @@ module Vedeu
92
88
  #
93
89
  # @return [Boolean]
94
90
  def debounce_expired?
95
- if set_executed > deadline
96
- true
97
-
98
- else
99
- Vedeu.log("Debouncing event '#{event_name}'")
91
+ return true if set_executed > deadline
100
92
 
101
- false
93
+ Vedeu.log("Debouncing event '#{event_name}'")
102
94
 
103
- end
95
+ false
104
96
  end
105
97
 
106
98
  # @return [Float]
File without changes
@@ -1,13 +1,13 @@
1
1
  module Vedeu
2
2
 
3
- # When the client application has defined interfaces to be used, the Registrar
4
- # stores these interfaces into various repositories for later use.
3
+ # When the client application has defined an interface to be used, the
4
+ # Registrar stores the attributes into various repositories for later use.
5
5
  #
6
6
  # @api private
7
7
  class Registrar
8
8
 
9
9
  # @param attributes [Hash]
10
- # @return [TrueClass|]
10
+ # @return [TrueClass|MissingRequired]
11
11
  def self.record(attributes = {})
12
12
  new(attributes).record
13
13
  end
@@ -22,17 +22,9 @@ module Vedeu
22
22
  #
23
23
  # @return [TrueClass|MissingRequired]
24
24
  def record
25
- Vedeu::Buffers.add(attributes)
26
-
27
- Vedeu::Offsets.add(attributes)
28
-
29
- Vedeu::Interfaces.add(attributes)
30
-
31
- Vedeu::Cursors.add(attributes)
32
-
33
- Vedeu::Groups.add(attributes)
34
-
35
- Vedeu::Focus.add(attributes)
25
+ [Buffers, Offsets, Interfaces, Cursors, Groups, Focus].map do |repository|
26
+ repository.add(attributes)
27
+ end
36
28
 
37
29
  true
38
30
  end
@@ -1,5 +1,7 @@
1
1
  module Vedeu
2
2
 
3
+ # Provides common methods for accessing the various repositories Vedeu uses.
4
+ #
3
5
  # @api private
4
6
  module Repository
5
7
 
@@ -25,8 +27,7 @@ module Vedeu
25
27
  # @return [Cursor|Offset]
26
28
  def find_or_create(name)
27
29
  storage.fetch(name) do
28
- Vedeu.log("Entity (#{entity.to_s}) not found, " \
29
- "registering new for: '#{name}'")
30
+ Vedeu.log("Entity (#{entity}) not found, registering: '#{name}'")
30
31
 
31
32
  storage.store(name, entity.new({ name: name }))
32
33
  end
@@ -65,7 +65,7 @@ module Vedeu
65
65
  # @param block [Proc]
66
66
  # @return []
67
67
  def initialize_screen(&block)
68
- output Esc.string 'screen_init'
68
+ output(Esc.string('screen_init'))
69
69
 
70
70
  yield
71
71
  end
@@ -74,7 +74,7 @@ module Vedeu
74
74
  #
75
75
  # @return [String]
76
76
  def clear_screen
77
- output Esc.string 'clear'
77
+ output(Esc.string('clear'))
78
78
  end
79
79
 
80
80
  # Attempts to tidy up the screen just before the application terminates.
@@ -92,7 +92,7 @@ module Vedeu
92
92
  #
93
93
  # @return [String]
94
94
  def set_cursor_mode
95
- output Esc.string 'show_cursor' unless raw_mode?
95
+ output(Esc.string('show_cursor')) unless raw_mode?
96
96
  end
97
97
 
98
98
  # Returns a boolean indicating whether the terminal is currently in `cooked`
@@ -107,6 +107,8 @@ module Vedeu
107
107
  #
108
108
  # @return [Symbol]
109
109
  def cooked_mode!
110
+ Vedeu.log("Terminal switching to 'cooked' mode")
111
+
110
112
  @_mode = :cooked
111
113
  end
112
114
 
@@ -122,6 +124,8 @@ module Vedeu
122
124
  #
123
125
  # @return [Symbol]
124
126
  def raw_mode!
127
+ Vedeu.log("Terminal switching to 'raw' mode")
128
+
125
129
  @_mode = :raw
126
130
  end
127
131
 
@@ -130,17 +134,9 @@ module Vedeu
130
134
  #
131
135
  # @return [Symbol]
132
136
  def switch_mode!
133
- if raw_mode?
134
- Vedeu.log("Terminal switching to 'cooked' mode")
135
-
136
- cooked_mode!
137
+ return cooked_mode! if raw_mode?
137
138
 
138
- else
139
- Vedeu.log("Terminal switching to 'raw' mode")
140
-
141
- raw_mode!
142
-
143
- end
139
+ raw_mode!
144
140
  end
145
141
 
146
142
  # Returns the mode of the terminal, either `:raw` or `:cooked`
@@ -30,7 +30,7 @@ module Vedeu
30
30
  #
31
31
  # @return []
32
32
  def trace
33
- set_trace_func proc { |event, file, line, id, binding, classname|
33
+ set_trace_func proc { |event, _file, _line, id, binding, classname|
34
34
  if event == watched && id != :log && classes.include?(classname.to_s)
35
35
  vars = variables(binding)
36
36
 
@@ -120,7 +120,7 @@ module Vedeu
120
120
  #
121
121
  # @return [String]
122
122
  def class_count
123
- @_count ||= "(#{classes.size.to_s}/#{vedeu_classes.size.to_s})"
123
+ @_count ||= "(#{classes.size}/#{vedeu_classes.size})"
124
124
  end
125
125
 
126
126
  # Returns the classes to be traced, without exceptions or ignored classes.
@@ -169,7 +169,6 @@ module Vedeu
169
169
  Set.new [
170
170
  # 'Vedeu::API',
171
171
  # 'Vedeu::Application',
172
- # 'Vedeu::Area',
173
172
  # 'Vedeu::Background',
174
173
  # 'Vedeu::Buffers',
175
174
  # 'Vedeu::Clear',
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ describe 'Integrations: Testing cursors, offsets and viewports' do
6
+
7
+ end
8
+
9
+ end # Vedeu
@@ -22,6 +22,7 @@ module Vedeu
22
22
  end.must_equal(
23
23
  { interfaces: [{
24
24
  name: 'testing_view',
25
+ cursor: :hide,
25
26
  group: '',
26
27
  colour: {},
27
28
  style: '',
@@ -54,6 +55,7 @@ module Vedeu
54
55
  end.must_equal(
55
56
  { interfaces: [{
56
57
  name: 'testing_view',
58
+ cursor: :hide,
57
59
  group: '',
58
60
  colour: {},
59
61
  style: '',
@@ -81,6 +83,7 @@ module Vedeu
81
83
  end.must_equal(
82
84
  { interfaces: [{
83
85
  name: 'testing_view',
86
+ cursor: :hide,
84
87
  group: '',
85
88
  colour: {},
86
89
  style: '',
@@ -108,6 +111,7 @@ module Vedeu
108
111
  end.must_equal(
109
112
  { interfaces: [{
110
113
  name: 'testing_view',
114
+ cursor: :hide,
111
115
  group: '',
112
116
  colour: {},
113
117
  style: '',
@@ -136,6 +140,7 @@ module Vedeu
136
140
  end.must_equal(
137
141
  { interfaces: [{
138
142
  name: 'testing_view',
143
+ cursor: :hide,
139
144
  group: '',
140
145
  colour: {},
141
146
  style: '',
@@ -171,6 +176,7 @@ module Vedeu
171
176
  end.must_equal(
172
177
  { interfaces: [{
173
178
  name: 'testing_view',
179
+ cursor: :hide,
174
180
  group: '',
175
181
  colour: {},
176
182
  style: '',
@@ -205,6 +211,7 @@ module Vedeu
205
211
  end.must_equal(
206
212
  { interfaces: [{
207
213
  name: 'testing_view',
214
+ cursor: :hide,
208
215
  group: '',
209
216
  colour: {},
210
217
  style: '',
@@ -234,6 +241,7 @@ module Vedeu
234
241
  end.must_equal(
235
242
  { interfaces: [{
236
243
  name: 'testing_view',
244
+ cursor: :hide,
237
245
  group: '',
238
246
  colour: {},
239
247
  style: '',
@@ -264,6 +272,7 @@ module Vedeu
264
272
  end.must_equal(
265
273
  { interfaces: [{
266
274
  name: 'testing_view',
275
+ cursor: :hide,
267
276
  group: '',
268
277
  colour: {},
269
278
  style: '',
@@ -299,6 +308,7 @@ module Vedeu
299
308
  end.must_equal(
300
309
  { interfaces: [{
301
310
  name: 'testing_view',
311
+ cursor: :hide,
302
312
  group: '',
303
313
  colour: {},
304
314
  style: '',
@@ -334,6 +344,7 @@ module Vedeu
334
344
  end.must_equal(
335
345
  { interfaces: [{
336
346
  name: 'testing_view',
347
+ cursor: :hide,
337
348
  group: '',
338
349
  colour: {},
339
350
  style: '',
@@ -377,6 +388,7 @@ module Vedeu
377
388
  end.must_equal(
378
389
  { interfaces: [{
379
390
  name: 'testing_view',
391
+ cursor: :hide,
380
392
  group: '',
381
393
  colour: {},
382
394
  style: '',
@@ -426,6 +438,7 @@ module Vedeu
426
438
  end.must_equal(
427
439
  { interfaces: [{
428
440
  name: 'testing_view',
441
+ cursor: :hide,
429
442
  group: '',
430
443
  colour: {},
431
444
  style: '',
@@ -478,6 +491,7 @@ module Vedeu
478
491
  end.must_equal(
479
492
  { interfaces: [{
480
493
  name: 'testing_view',
494
+ cursor: :hide,
481
495
  group: '',
482
496
  colour: {},
483
497
  style: '',
@@ -523,6 +537,7 @@ module Vedeu
523
537
  end.must_equal(
524
538
  { interfaces: [{
525
539
  name: 'testing_view',
540
+ cursor: :hide,
526
541
  group: '',
527
542
  colour: {},
528
543
  style: '',
@@ -558,6 +573,7 @@ module Vedeu
558
573
  end.must_equal(
559
574
  { interfaces: [{
560
575
  name: 'testing_view',
576
+ cursor: :hide,
561
577
  group: '',
562
578
  colour: {},
563
579
  style: '',
@@ -593,6 +609,7 @@ module Vedeu
593
609
  end.must_equal(
594
610
  { interfaces: [{
595
611
  name: 'testing_view',
612
+ cursor: :hide,
596
613
  group: '',
597
614
  colour: {},
598
615
  style: '',
@@ -628,6 +645,7 @@ module Vedeu
628
645
  end.must_equal(
629
646
  { interfaces: [{
630
647
  name: 'testing_view',
648
+ cursor: :hide,
631
649
  group: '',
632
650
  colour: {},
633
651
  style: '',
@@ -672,6 +690,7 @@ module Vedeu
672
690
  end.must_equal(
673
691
  { interfaces: [{
674
692
  name: 'testing_view',
693
+ cursor: :hide,
675
694
  group: '',
676
695
  colour: {},
677
696
  style: '',