vedeu 0.6.51 → 0.6.52

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vedeu/borders/refresh.rb +1 -0
  3. data/lib/vedeu/buffers/all.rb +2 -0
  4. data/lib/vedeu/buffers/empty.rb +78 -0
  5. data/lib/vedeu/buffers/view.rb +51 -0
  6. data/lib/vedeu/colours/colour.rb +24 -12
  7. data/lib/vedeu/editor/cropper.rb +1 -1
  8. data/lib/vedeu/editor/cursor.rb +6 -2
  9. data/lib/vedeu/editor/document.rb +50 -32
  10. data/lib/vedeu/esc/actions.rb +0 -7
  11. data/lib/vedeu/esc/borders.rb +0 -7
  12. data/lib/vedeu/esc/colours.rb +0 -2
  13. data/lib/vedeu/esc/mouse.rb +0 -7
  14. data/lib/vedeu/events/event.rb +2 -2
  15. data/lib/vedeu/interfaces/clear.rb +1 -0
  16. data/lib/vedeu/logging/all.rb +1 -0
  17. data/lib/vedeu/logging/clock_time.rb +34 -0
  18. data/lib/vedeu/logging/log.rb +20 -18
  19. data/lib/vedeu/logging/timer.rb +2 -2
  20. data/lib/vedeu/models/cell.rb +10 -0
  21. data/lib/vedeu/models/views/char.rb +12 -0
  22. data/lib/vedeu/models/views/line.rb +5 -0
  23. data/lib/vedeu/models/views/stream.rb +6 -0
  24. data/lib/vedeu/output/compressor.rb +31 -2
  25. data/lib/vedeu/output/output.rb +25 -2
  26. data/lib/vedeu/output/presentation/colour.rb +9 -0
  27. data/lib/vedeu/output/presentation/styles.rb +3 -0
  28. data/lib/vedeu/output/renderers/file.rb +1 -1
  29. data/lib/vedeu/version.rb +1 -1
  30. data/test/lib/vedeu/buffers/empty_test.rb +87 -0
  31. data/test/lib/vedeu/buffers/view_test.rb +36 -0
  32. data/test/lib/vedeu/colours/colour_test.rb +10 -13
  33. data/test/lib/vedeu/editor/cursor_test.rb +23 -5
  34. data/test/lib/vedeu/interfaces/clear_test.rb +4 -6
  35. data/test/lib/vedeu/logging/clock_time_test.rb +13 -0
  36. data/test/lib/vedeu/logging/timer_test.rb +3 -5
  37. data/test/lib/vedeu/models/cell_test.rb +16 -0
  38. data/test/lib/vedeu/models/views/char_test.rb +18 -0
  39. data/test/lib/vedeu/models/views/html_char_test.rb +30 -17
  40. data/test/lib/vedeu/models/views/line_test.rb +14 -0
  41. data/test/lib/vedeu/models/views/stream_test.rb +14 -0
  42. data/test/lib/vedeu/output/compressor_test.rb +43 -21
  43. data/test/lib/vedeu/output/renderers/json_test.rb +4 -1
  44. data/test/lib/vedeu/output/renderers/terminal_test.rb +4 -3
  45. data/test/lib/vedeu/templating/encoder_test.rb +1 -1
  46. data/test/lib/vedeu/templating/helpers_test.rb +6 -6
  47. data/vedeu.gemspec +1 -1
  48. metadata +13 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 08eb61b65bd7020344202d3002defb0dc0d50c13
4
- data.tar.gz: 560d43d002cf41c62bcb74b9964534071f33e941
3
+ metadata.gz: 134542edb6745534c69b060678db4f11bd0e5b47
4
+ data.tar.gz: c679c95b4f54b95a03ec19d6ed011d2590954905
5
5
  SHA512:
6
- metadata.gz: ad2ece537d1197ef06bce653d9a063dae0a43abd7fd42989fe090451b346be4a4a36685c56d4794366b64b474d1dc5fed2be4bb44e15f4cce02b7bbb51051b6c
7
- data.tar.gz: 2e660fa55283d844fbe6e5fa9f2a74ae8ba26489059a57ca8975fc1073c3a9afb91aefa6ea3bf8d0b52e7fc168bf23e9897895e876e0a58fe00b0ec976815f7b
6
+ metadata.gz: e63c021516235bf2d2567ed1416127b5ef882167d8811c5a7fa107591c87f596431bfb48a47aed11b394efc1dab68f29eeb671c2820a10a410741741ef536f6f
7
+ data.tar.gz: 1c0d40b4476b35b6cf4cd33161fd9b878da4efe5e8b8c02dc1d169d18adb877dc628c12276fde234cbbca3235eaebc1757c471d2c219c72994a6544455262da6
@@ -104,6 +104,7 @@ module Vedeu
104
104
  Vedeu::Views::Char.new(value: value,
105
105
  parent: interface,
106
106
  colour: colour,
107
+ name: name,
107
108
  style: style,
108
109
  position: [iy, ix],
109
110
  border: type)
@@ -18,6 +18,8 @@ module Vedeu
18
18
 
19
19
  end # Vedeu
20
20
 
21
+ require 'vedeu/buffers/empty'
22
+ require 'vedeu/buffers/view'
21
23
  require 'vedeu/buffers/buffer'
22
24
  require 'vedeu/buffers/null'
23
25
  require 'vedeu/buffers/repository'
@@ -0,0 +1,78 @@
1
+ module Vedeu
2
+
3
+ module Buffers
4
+
5
+ # Provides a grid of Vedeu::Models::Cell objects at the given
6
+ # height and width.
7
+ #
8
+ # @api private
9
+ class Empty
10
+
11
+ # @!attribute [r] name
12
+ # @return [NilClass|String|Symbol]
13
+ attr_reader :name
14
+
15
+ # Returns a new instance of Vedeu::Buffers::Empty.
16
+ #
17
+ # @note
18
+ # If a particular key is missing from the attributes
19
+ # parameter, then it is added with the respective value from
20
+ # #defaults.
21
+ #
22
+ # @param attributes [Hash<Symbol => Fixnum, NilClass, String,
23
+ # Symbol]
24
+ # @option attributes name [NilClass|String|Symbol]
25
+ # @option attributes height [Fixnum]
26
+ # @option attributes width [Fixnum]
27
+ # @return [Vedeu::Buffers::Empty]
28
+ def initialize(attributes = {})
29
+ defaults.merge!(attributes).each do |key, value|
30
+ instance_variable_set("@#{key}", value || defaults.fetch(key))
31
+ end
32
+ end
33
+
34
+ # @return [Array<Array<Vedeu::Models::Cell>>]
35
+ def buffer
36
+ Array.new(width) do |y|
37
+ Array.new(height) do |x|
38
+ Vedeu::Models::Cell.new(name: name, position: [y, x])
39
+ end
40
+ end
41
+ end
42
+
43
+ # @note
44
+ # We add 1 to both the width and height as terminal screens
45
+ # are 1-indexed.
46
+ #
47
+ # @return [Fixnum]
48
+ def height
49
+ @height + 1
50
+ end
51
+
52
+ # @note
53
+ # We add 1 to both the width and height as terminal screens
54
+ # are 1-indexed.
55
+ #
56
+ # @return [Fixnum]
57
+ def width
58
+ @width + 1
59
+ end
60
+
61
+ private
62
+
63
+ # Returns the default options/attributes for this class.
64
+ #
65
+ # @return [Hash<Symbol => void>]
66
+ def defaults
67
+ {
68
+ height: Vedeu.height,
69
+ name: nil,
70
+ width: Vedeu.width,
71
+ }
72
+ end
73
+
74
+ end # Empty
75
+
76
+ end # Buffers
77
+
78
+ end # Vedeu
@@ -0,0 +1,51 @@
1
+ module Vedeu
2
+
3
+ module Buffers
4
+
5
+ class View
6
+
7
+ def initialize(attributes = {})
8
+ defaults.merge!(attributes).each do |key, value|
9
+ instance_variable_set("@#{key}", value || defaults.fetch(key))
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def border
16
+ Vedeu.borders.by_name(name)
17
+ end
18
+
19
+ def buffer
20
+ @_buffer ||= Vedeu::Buffers::Empty.new(height: border.height,
21
+ name: name,
22
+ width: border.width).buffer
23
+ end
24
+
25
+ def current
26
+ @current ||= buffer
27
+ end
28
+
29
+ def current_reset!
30
+ @current = buffer
31
+ end
32
+
33
+ def defaults
34
+ {
35
+ name: ''
36
+ }
37
+ end
38
+
39
+ def dirty
40
+ @dirty ||= buffer
41
+ end
42
+
43
+ def dirty_reset!
44
+ @dirty = buffer
45
+ end
46
+
47
+ end # View
48
+
49
+ end # Buffers
50
+
51
+ end # Vedeu
@@ -37,14 +37,6 @@ module Vedeu
37
37
  #
38
38
  class Colour
39
39
 
40
- # @!attribute [r] background
41
- # @return [Vedeu::Colours::Background]
42
- attr_reader :background
43
-
44
- # @!attribute [r] foreground
45
- # @return [Vedeu::Colours::Foreground]
46
- attr_reader :foreground
47
-
48
40
  # @param value [Vedeu::Colours::Colour|Hash<Symbol => void>]
49
41
  # @return [Vedeu::Colours::Colour]
50
42
  def self.coerce(value)
@@ -78,19 +70,25 @@ module Vedeu
78
70
  # @option attributes foreground [String]
79
71
  # @return [Vedeu::Colours::Colour]
80
72
  def initialize(attributes = {})
81
- @background = Vedeu::Colours::Background.coerce(attributes[:background])
82
- @foreground = Vedeu::Colours::Foreground.coerce(attributes[:foreground])
73
+ defaults.merge!(attributes).each do |key, value|
74
+ instance_variable_set("@#{key}", value)
75
+ end
83
76
  end
84
77
 
85
78
  # @return [Hash<Symbol => Vedeu::Colours::Background,
86
79
  # Vedeu::Colours::Foreground>]
87
80
  def attributes
88
81
  {
89
- background: Vedeu::Colours::Background.coerce(@background),
90
- foreground: Vedeu::Colours::Foreground.coerce(@foreground),
82
+ background: background,
83
+ foreground: foreground,
91
84
  }
92
85
  end
93
86
 
87
+ # @return [Vedeu::Colours::Background]
88
+ def background
89
+ @background = Vedeu::Colours::Background.coerce(@background)
90
+ end
91
+
94
92
  # Converts the value into a Vedeu::Colours::Background.
95
93
  #
96
94
  # @param value [String]
@@ -109,6 +107,11 @@ module Vedeu
109
107
  end
110
108
  alias_method :==, :eql?
111
109
 
110
+ # @return [Vedeu::Colours::Foreground]
111
+ def foreground
112
+ @foreground = Vedeu::Colours::Foreground.coerce(@foreground)
113
+ end
114
+
112
115
  # Converts the value into a Vedeu::Colours::Foreground.
113
116
  #
114
117
  # @param value [String]
@@ -126,6 +129,15 @@ module Vedeu
126
129
  end
127
130
  alias_method :to_str, :to_s
128
131
 
132
+ private
133
+
134
+ def defaults
135
+ {
136
+ background: Vedeu::Colours::Background.new,
137
+ foreground: Vedeu::Colours::Foreground.new
138
+ }
139
+ end
140
+
129
141
  end # Colour
130
142
 
131
143
  end # Colours
@@ -43,7 +43,7 @@ module Vedeu
43
43
 
44
44
  visible.each_with_index do |line, iy|
45
45
  line.chars.each_with_index do |char, ix|
46
- out << Vedeu::Views::Char.new(parent: interface,
46
+ out << Vedeu::Views::Char.new(name: name,
47
47
  position: [(by + iy), (bx + ix)],
48
48
  value: char.freeze)
49
49
  end
@@ -65,9 +65,11 @@ module Vedeu
65
65
 
66
66
  # Move the virtual cursor down by one line.
67
67
  #
68
+ # @param size [Fixnum]
68
69
  # @return [Vedeu::Editor::Cursor]
69
- def down
70
+ def down(size = nil)
70
71
  @y += 1
72
+ @x = size if size && x > size
71
73
 
72
74
  self
73
75
  end
@@ -132,10 +134,12 @@ module Vedeu
132
134
 
133
135
  # Move the virtual cursor up by one line.
134
136
  #
137
+ # @param size [Fixnum]
135
138
  # @return [Vedeu::Editor::Cursor]
136
- def up
139
+ def up(size = nil)
137
140
  @oy -= 1 unless @oy == 0
138
141
  @y -= 1
142
+ @x = size if size && x > size
139
143
 
140
144
  self
141
145
  end
@@ -77,9 +77,9 @@ module Vedeu
77
77
  #
78
78
  # @return [Vedeu::Editor::Document]
79
79
  def delete_character
80
- return self if (x == 0 || x - 1 < 0) && y == 0
80
+ return self if document_start?
81
81
 
82
- if (x == 0 || x - 1 < 0) && y > 0
82
+ if first_char? && y > 0
83
83
  delete_line
84
84
 
85
85
  return
@@ -132,13 +132,12 @@ module Vedeu
132
132
 
133
133
  down
134
134
 
135
- cursor.bol.refresh
136
-
137
135
  refresh
138
136
  end
139
137
 
140
138
  # Returns the current line from the collection of lines.
141
139
  #
140
+ # @param index [Fixnum]
142
141
  # @return [Array<String|void>]
143
142
  def line(index = y)
144
143
  lines.line(index)
@@ -160,6 +159,8 @@ module Vedeu
160
159
 
161
160
  @lines = defaults[:data]
162
161
 
162
+ cursor.refresh
163
+
163
164
  refresh
164
165
  end
165
166
 
@@ -172,9 +173,9 @@ module Vedeu
172
173
 
173
174
  Vedeu.trigger(:_clear_view_content_, name)
174
175
 
175
- Vedeu.render_output(output)
176
+ Vedeu.buffer_update(output)
176
177
 
177
- cursor.refresh
178
+ Vedeu.direct_write(output.map(&:to_s).join)
178
179
 
179
180
  self
180
181
  end
@@ -183,7 +184,7 @@ module Vedeu
183
184
  #
184
185
  # @return [Vedeu::Editor::Document]
185
186
  def left
186
- return self if x - 1 < 0
187
+ return self if first_char?
187
188
 
188
189
  cursor.left.refresh
189
190
 
@@ -194,7 +195,7 @@ module Vedeu
194
195
  #
195
196
  # @return [Vedeu::Editor::Document]
196
197
  def right
197
- return self if x + 1 > line.size
198
+ return self if last_char?
198
199
 
199
200
  cursor.right.refresh
200
201
 
@@ -205,11 +206,9 @@ module Vedeu
205
206
  #
206
207
  # @return [Vedeu::Editor::Document]
207
208
  def up
208
- return self if y - 1 < 0
209
+ return self if first_line?
209
210
 
210
- cursor.up.refresh
211
-
212
- reposition_cursor_x!
211
+ cursor.up(prev_line_size).refresh
213
212
 
214
213
  self
215
214
  end
@@ -218,29 +217,26 @@ module Vedeu
218
217
  #
219
218
  # @return [Vedeu::Editor::Document]
220
219
  def down
221
- return self if y + 1 >= lines.size
222
-
223
- cursor.down.refresh
220
+ return self if last_line?
224
221
 
225
- reposition_cursor_x!
222
+ cursor.down(next_line_size).refresh
226
223
 
227
224
  self
228
225
  end
229
226
 
230
227
  private
231
228
 
232
- # Repositions the x coordinate of the virtual cursor to the end
233
- # of the line if the x coordinate is beyond the end of the line.
234
- #
235
- # This is used when the cursor moves up or down, moving from a
236
- # long line to a shorter line.
229
+ # @return [Boolean]
230
+ def document_start?
231
+ first_char? && first_line?
232
+ end
233
+
234
+ # Return a virtual cursor to track the cursor position within
235
+ # the document.
237
236
  #
238
237
  # @return [Vedeu::Editor::Cursor]
239
- def reposition_cursor_x!
240
- if x > line.size
241
- cursor.x = line.size
242
- cursor.refresh
243
- end
238
+ def cursor
239
+ @cursor ||= Vedeu::Editor::Cursor.new(name: name)
244
240
  end
245
241
 
246
242
  # Returns the default options/attributes for this class.
@@ -254,6 +250,31 @@ module Vedeu
254
250
  }
255
251
  end
256
252
 
253
+ # @return [Boolean]
254
+ def first_char?
255
+ x - 1 < 0
256
+ end
257
+
258
+ # @return [Boolean]
259
+ def first_line?
260
+ y - 1 < 0
261
+ end
262
+
263
+ # @return [Boolean]
264
+ def last_char?
265
+ x + 1 > line.size
266
+ end
267
+
268
+ # @return [Boolean]
269
+ def last_line?
270
+ y + 1 >= lines.size
271
+ end
272
+
273
+ # @return [Fixnum]
274
+ def next_line_size
275
+ line(y + 1).size
276
+ end
277
+
257
278
  # Return the data needed to render the document, based on the
258
279
  # current virtual cursor position. This output may be a cropped
259
280
  # representation of the full document depending on the size of
@@ -267,12 +288,9 @@ module Vedeu
267
288
  oy: oy).viewport
268
289
  end
269
290
 
270
- # Return a virtual cursor to track the cursor position within
271
- # the document.
272
- #
273
- # @return [Vedeu::Editor::Cursor]
274
- def cursor
275
- @cursor ||= Vedeu::Editor::Cursor.new(name: name)
291
+ # @return [Fixnum]
292
+ def prev_line_size
293
+ line(y - 1).size
276
294
  end
277
295
 
278
296
  end # Document
@@ -31,13 +31,6 @@ module Vedeu
31
31
 
32
32
  # @return [void]
33
33
  def setup!
34
- define_actions!
35
- end
36
-
37
- private
38
-
39
- # @return [void]
40
- def define_actions!
41
34
  characters.each { |key, code| define_method(key) { code } }
42
35
  end
43
36