vedeu 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c9a714b2238fa3c5bbdeeccef8713918b40f4f5
4
- data.tar.gz: 2f3dd1b000581dacd7f007347333fc5bc6028701
3
+ metadata.gz: 12ee9a34dc28d9a2230a6e1acb69e62e8da7cd20
4
+ data.tar.gz: 27b92a31c6f1585f4f84e6d1de7469569e5ddfa9
5
5
  SHA512:
6
- metadata.gz: e823c499c813c68bf11108eaf1c96de24ec984aff02afa56d240ca00fae273698b51d08b04c9fd85f730a78f9b7e713459b70cecd7316d6affa8e183fd669efb
7
- data.tar.gz: 2b92ab94bf23c05680545fdb6e3a2beccda9484809a82b416ef04354e74d6f13113e031c1077ba7c716407c5c1485717a7a0955192890e00152f508ce04134c8
6
+ metadata.gz: e24f06eb598a6776473d4f1a7364be6eca6e9c1660260093643a3a752ccd4765c66a1c9f429db439f5de99bafe2bdc64df3173bc38549e34d5df91029778f68b
7
+ data.tar.gz: abb7551af78cb1c8339cd678a33e0e590a74b057cf32c9f256bc77980a6b1f2b05da31fc563b86a3e79775ab6a267eb4c3ae7817669797ee072146dc18b8b890
@@ -66,6 +66,12 @@ reason, simply ask for it:
66
66
  ### log_only
67
67
  {include:Vedeu::Config::API#log_only}
68
68
 
69
+ ### log_except
70
+ {include:Vedeu::Config::API#log_except}
71
+
72
+ ### loggable?
73
+ {include:Vedeu::Configuration.loggable?}
74
+
69
75
  ### profile / profile!
70
76
  {include:Vedeu::Config::API#profile}
71
77
 
data/docs/debugging.md CHANGED
@@ -8,9 +8,7 @@ and hopefully be dropped into a Pry debuggging session:
8
8
 
9
9
  Vedeu::Terminal.cooked_mode!
10
10
  Vedeu::Terminal.open do
11
- mouse_off = Vedeu::EscapeSequences::Esc.mouse_x10_off
12
- show_cursor = Vedeu::EscapeSequences::Esc.show_cursor
13
- Vedeu::Terminal.output(mouse_off + show_cursor)
11
+ Vedeu::Terminal.debugging!
14
12
 
15
13
  require 'pry'
16
14
  binding.pry
@@ -13,6 +13,11 @@ module Vedeu
13
13
  @position = defaults[:position]
14
14
  end
15
15
 
16
+ # @return [String]
17
+ def text
18
+ '+'
19
+ end
20
+
16
21
  end # Corner
17
22
 
18
23
  end # Cells
@@ -9,6 +9,11 @@ module Vedeu
9
9
  #
10
10
  class Horizontal < Vedeu::Cells::Border
11
11
 
12
+ # @return [String]
13
+ def text
14
+ '-'
15
+ end
16
+
12
17
  # @return [Symbol]
13
18
  def type
14
19
  :horizontal
@@ -9,6 +9,11 @@ module Vedeu
9
9
  #
10
10
  class Vertical < Vedeu::Cells::Border
11
11
 
12
+ # @return [String]
13
+ def text
14
+ '|'
15
+ end
16
+
12
17
  # @return [Symbol]
13
18
  def type
14
19
  :vertical
@@ -17,6 +17,11 @@ module Vedeu
17
17
  false
18
18
  end
19
19
 
20
+ # @return [String]
21
+ def text
22
+ @value || ' '
23
+ end
24
+
20
25
  end # Char
21
26
 
22
27
  end # Cells
@@ -21,6 +21,7 @@ module Vedeu
21
21
  def value
22
22
  ' '.freeze
23
23
  end
24
+ alias_method :text, :value
24
25
 
25
26
  end # Clear
26
27
 
@@ -43,6 +43,11 @@ module Vedeu
43
43
  end
44
44
  alias_method :==, :eql?
45
45
 
46
+ # @return [String]
47
+ def text
48
+ ' '
49
+ end
50
+
46
51
  # @return [Hash]
47
52
  def to_hash
48
53
  {
@@ -303,6 +303,26 @@ module Vedeu
303
303
  options[:log] = filename
304
304
  end
305
305
 
306
+ # Log specific message types except those given. A complete list
307
+ # of message types can be found at
308
+ # {Vedeu::Logging::Log.message_types}.
309
+ #
310
+ # Vedeu.configure do
311
+ # log_except :debug, :event
312
+ #
313
+ # # or
314
+ # log_except [:debug, :info]
315
+ #
316
+ # # ...
317
+ # end
318
+ #
319
+ # @param types [Array<Symbol>] The message types which should
320
+ # not be logged.
321
+ # @return [Array<Symbol>]
322
+ def log_except(*types)
323
+ options[:log_except] = types.flatten
324
+ end
325
+
306
326
  # Only log specific message types. A complete list of message
307
327
  # types can be found at {Vedeu::Logging::Log.message_types}.
308
328
  #
@@ -170,11 +170,27 @@ module Vedeu
170
170
  log != nil
171
171
  end
172
172
 
173
+ # @return [Array<Symbol>]
174
+ def log_except
175
+ instance.options[:log_except] || []
176
+ end
177
+
173
178
  # @return [Array<Symbol>]
174
179
  def log_only
175
180
  instance.options[:log_only] || []
176
181
  end
177
182
 
183
+ # Returns true if the given type was included in the :log_only
184
+ # configuration option or not included in the :log_except
185
+ # option.
186
+ #
187
+ # @param type [Symbol]
188
+ # @return [Boolean]
189
+ def loggable?(type)
190
+ Vedeu::Configuration.log_only.include?(type) ||
191
+ !Vedeu::Configuration.log_except.include?(type)
192
+ end
193
+
178
194
  # Returns whether mouse support was enabled or disabled.
179
195
  #
180
196
  # @return [Boolean]
@@ -323,6 +339,7 @@ module Vedeu
323
339
  height: nil,
324
340
  interactive: true,
325
341
  log: nil,
342
+ log_except: [],
326
343
  log_only: [],
327
344
  mouse: true,
328
345
  once: false,
@@ -197,7 +197,7 @@ module Vedeu
197
197
  def hide
198
198
  super
199
199
 
200
- Vedeu.log(type: :output, message: "Hiding cursor: '#{name}'".freeze)
200
+ Vedeu.log(type: :cursor, message: "Hiding cursor: '#{name}'".freeze)
201
201
 
202
202
  render
203
203
  end
@@ -234,7 +234,7 @@ module Vedeu
234
234
  def show
235
235
  super
236
236
 
237
- Vedeu.log(type: :output, message: "Showing cursor: '#{name}'".freeze)
237
+ Vedeu.log(type: :cursor, message: "Showing cursor: '#{name}'".freeze)
238
238
 
239
239
  render
240
240
  end
@@ -53,7 +53,7 @@ module Vedeu
53
53
  def by_name
54
54
  refresh_view if refresh_view?
55
55
 
56
- Vedeu.log(type: :output,
56
+ Vedeu.log(type: :cursor,
57
57
  message: "Refreshing cursor: '#{name}' (x:#{x}, y:#{y}, " \
58
58
  "ox:#{ox}, oy:#{oy}, visible:#{visible})".freeze)
59
59
 
@@ -26,8 +26,7 @@ module Vedeu
26
26
  def log(message:, force: false, type: :info)
27
27
  output = log_entry(type, message)
28
28
 
29
- if (enabled? || force) && (Vedeu::Configuration.log_only.empty? ||
30
- Vedeu::Configuration.log_only.include?(type))
29
+ if (enabled? || force) && Vedeu::Configuration.loggable?(type)
31
30
  logger.debug(output)
32
31
  end
33
32
 
@@ -172,6 +171,7 @@ module Vedeu
172
171
  input: [:light_yellow, :yellow],
173
172
 
174
173
  compress: [:white, :light_grey],
174
+ cursor: [:light_green, :green],
175
175
  output: [:light_green, :green],
176
176
  render: [:light_green, :green],
177
177
 
@@ -48,7 +48,7 @@ module Vedeu
48
48
 
49
49
  # @return [Array<void>]
50
50
  def content
51
- (cells.flatten << reset_character).reject(&:cell?)
51
+ (cells.flatten << reset_character)
52
52
  end
53
53
 
54
54
  # Provides iteration over the collection.
@@ -244,12 +244,12 @@ module Vedeu
244
244
  #
245
245
  # @return [Fixnum]
246
246
  def width
247
- if present?(options[:name])
248
- geometry.bordered_width
249
-
250
- elsif present?(options[:width])
247
+ if present?(options[:width])
251
248
  options[:width]
252
249
 
250
+ elsif present?(options[:name])
251
+ geometry.bordered_width
252
+
253
253
  end
254
254
  end
255
255
 
@@ -145,3 +145,4 @@ require 'vedeu/renderers/file'
145
145
  require 'vedeu/renderers/html'
146
146
  require 'vedeu/renderers/json'
147
147
  require 'vedeu/renderers/terminal'
148
+ require 'vedeu/renderers/text'
@@ -0,0 +1,103 @@
1
+ module Vedeu
2
+
3
+ module Renderers
4
+
5
+ # Converts a grid of {Vedeu::Cells} objects or
6
+ # {Vedeu::Views::Char} objects into a stream of characters without
7
+ # escape sequences.
8
+ #
9
+ class Text < Vedeu::Renderers::File
10
+
11
+ include Vedeu::Common
12
+ include Vedeu::Renderers::Options
13
+
14
+ # Returns a new instance of Vedeu::Renderers::Text.
15
+ #
16
+ # @param options [Hash]
17
+ # @return [Vedeu::Renderers::Text]
18
+ def initialize(options = {})
19
+ @options = options || {}
20
+ end
21
+
22
+ # Render a cleared output.
23
+ #
24
+ # @return [String]
25
+ def clear
26
+ ''
27
+ end
28
+
29
+ # @param output [Vedeu::Models::Page]
30
+ # @return [Array<String>]
31
+ def render(output)
32
+ return '' unless present?(output)
33
+
34
+ output.each do |row|
35
+ row.each do |char|
36
+ next unless renderable?(char) &&
37
+ positionable?(char) &&
38
+ textual?(char)
39
+
40
+ # fail char.inspect
41
+
42
+ buffer[char.position.y - 1][char.position.x - 1] = char.text
43
+ end
44
+ end
45
+
46
+ ::File.write(filename, data) if write_file?
47
+
48
+ data
49
+ end
50
+
51
+ private
52
+
53
+ # @return [Array<String>]
54
+ def buffer
55
+ @buffer ||= Array.new(Vedeu.height) { Array.new(Vedeu.width) { ' ' } }
56
+ end
57
+
58
+ # @return [String]
59
+ def data
60
+ @data ||= buffer.map(&:join).join("\n").unpack('U*').map do |c|
61
+ (c > 255) ? ' ' : c.chr
62
+ end.join
63
+ end
64
+
65
+ # @return [Boolean]
66
+ def positionable?(char)
67
+ char.respond_to?(:position) &&
68
+ char.position.is_a?(Vedeu::Geometries::Position)
69
+ end
70
+
71
+ # @return [Array<Class>]
72
+ def renderables
73
+ [
74
+ Vedeu::Cells::Empty,
75
+ Vedeu::Cells::TopLeft,
76
+ Vedeu::Cells::TopHorizontal,
77
+ Vedeu::Cells::Char,
78
+ Vedeu::Cells::TopRight,
79
+ Vedeu::Views::Char,
80
+ Vedeu::Cells::Clear,
81
+ Vedeu::Cells::LeftVertical,
82
+ Vedeu::Cells::RightVertical,
83
+ Vedeu::Cells::BottomLeft,
84
+ Vedeu::Cells::BottomHorizontal,
85
+ Vedeu::Cells::BottomRight,
86
+ ]
87
+ end
88
+
89
+ # @return [Boolean]
90
+ def renderable?(char)
91
+ renderables.include?(char.class)
92
+ end
93
+
94
+ # @return [Boolean]
95
+ def textual?(char)
96
+ char.respond_to?(:text)
97
+ end
98
+
99
+ end # Text
100
+
101
+ end # Renderers
102
+
103
+ end # Vedeu
data/lib/vedeu/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Vedeu
2
2
 
3
3
  # The current version of Vedeu.
4
- VERSION = '0.7.1'.freeze
4
+ VERSION = '0.7.2'.freeze
5
5
 
6
6
  end
@@ -104,6 +104,15 @@ module Vedeu
104
104
  Vedeu::EscapeSequences::Esc.border { @value }
105
105
  end
106
106
 
107
+ # @return [String]
108
+ def text
109
+ if border
110
+ ' '
111
+ else
112
+ @value
113
+ end
114
+ end
115
+
107
116
  # Returns a Hash of all the values before coercion.
108
117
  #
109
118
  # @note
@@ -50,6 +50,14 @@ module Vedeu
50
50
  end
51
51
  end
52
52
 
53
+ describe '#text' do
54
+ let(:instance) { Vedeu::Cells::TopRight.new }
55
+
56
+ subject { instance.text }
57
+
58
+ it { subject.must_equal('+') }
59
+ end
60
+
53
61
  end # Corner
54
62
 
55
63
  end # Cells
@@ -9,6 +9,12 @@ module Vedeu
9
9
  let(:described) { Vedeu::Cells::Horizontal }
10
10
  let(:instance) { described.new }
11
11
 
12
+ describe '#text' do
13
+ subject { instance.text }
14
+
15
+ it { subject.must_equal('-') }
16
+ end
17
+
12
18
  describe '#type' do
13
19
  subject { instance.type }
14
20
 
@@ -9,6 +9,12 @@ module Vedeu
9
9
  let(:described) { Vedeu::Cells::Vertical }
10
10
  let(:instance) { described.new }
11
11
 
12
+ describe '#text' do
13
+ subject { instance.text }
14
+
15
+ it { subject.must_equal('|') }
16
+ end
17
+
12
18
  describe '#type' do
13
19
  subject { instance.type }
14
20
 
@@ -15,6 +15,12 @@ module Vedeu
15
15
  it { subject.must_equal(false) }
16
16
  end
17
17
 
18
+ describe '#text' do
19
+ subject { instance.text }
20
+
21
+ it { subject.must_equal('') }
22
+ end
23
+
18
24
  end # Char
19
25
 
20
26
  end # Cells
@@ -25,6 +25,8 @@ module Vedeu
25
25
  subject { instance.value }
26
26
 
27
27
  it { subject.must_equal(' ') }
28
+
29
+ it { instance.must_respond_to(:text) }
28
30
  end
29
31
 
30
32
  end # Clear
@@ -48,6 +48,12 @@ module Vedeu
48
48
  end
49
49
  end
50
50
 
51
+ describe '#text' do
52
+ subject { instance.text }
53
+
54
+ it { subject.must_equal(' ') }
55
+ end
56
+
51
57
  describe '#to_hash' do
52
58
  let(:position) { [1, 1] }
53
59
  let(:colour) { Vedeu::Colours::Colour.new(background: '#000000') }
@@ -241,6 +241,18 @@ module Vedeu
241
241
  end
242
242
  end
243
243
 
244
+ describe '#log_except' do
245
+ it 'sets the options to the desired value' do
246
+ configuration = Vedeu.configure { log_except :debug, :store }
247
+ configuration.log_except.must_equal([:debug, :store])
248
+ end
249
+
250
+ it 'sets the options to the desired value' do
251
+ configuration = Vedeu.configure { log_except [:debug, :info] }
252
+ configuration.log_except.must_equal([:debug, :info])
253
+ end
254
+ end
255
+
244
256
  describe '#log_only' do
245
257
  it 'sets the options to the desired value' do
246
258
  configuration = Vedeu.configure { log_only :debug, :store }
@@ -93,6 +93,22 @@ module Vedeu
93
93
  end
94
94
  end
95
95
 
96
+ describe '.log_except' do
97
+ context 'when log_except is not configured' do
98
+ it { described.log_except.must_equal([]) }
99
+ end
100
+
101
+ context 'when log_except is configured' do
102
+ before do
103
+ Vedeu.configure do
104
+ log_except :timer, :event
105
+ end
106
+ end
107
+
108
+ it { described.log_except.must_equal([:timer, :event]) }
109
+ end
110
+ end
111
+
96
112
  describe '.log_only' do
97
113
  context 'when log_only is not configured' do
98
114
  it { described.log_only.must_equal([]) }
@@ -109,6 +125,48 @@ module Vedeu
109
125
  end
110
126
  end
111
127
 
128
+ describe '.loggable?' do
129
+ let(:type) { :hydrogen }
130
+
131
+ subject { described.loggable?(type) }
132
+
133
+ context 'when the type exists in log_only and log_except' do
134
+ before do
135
+ described.stubs(:log_only).returns([:hydrogen])
136
+ described.stubs(:log_except).returns([:hydrogen])
137
+ end
138
+
139
+ it { subject.must_equal(true) }
140
+ end
141
+
142
+ context 'when the type exists in log_only' do
143
+ before do
144
+ described.stubs(:log_only).returns([:hydrogen])
145
+ described.stubs(:log_except).returns([])
146
+ end
147
+
148
+ it { subject.must_equal(true) }
149
+ end
150
+
151
+ context 'when the type exists in log_except' do
152
+ before do
153
+ described.stubs(:log_only).returns([])
154
+ described.stubs(:log_except).returns([:hydrogen])
155
+ end
156
+
157
+ it { subject.must_equal(false) }
158
+ end
159
+
160
+ context 'when the type does not exist in either' do
161
+ before do
162
+ described.stubs(:log_only).returns([])
163
+ described.stubs(:log_except).returns([])
164
+ end
165
+
166
+ it { subject.must_equal(true) }
167
+ end
168
+ end
169
+
112
170
  describe '.mouse?' do
113
171
  it { described.must_respond_to(:mouse) }
114
172
 
@@ -100,6 +100,7 @@ module Vedeu
100
100
  let(:expected) {
101
101
  [
102
102
  Vedeu::Views::Char.new(value: 'A'),
103
+ Vedeu::Cells::Empty.new(value: 'B'),
103
104
  Vedeu::Views::Char.new(value: 'C'),
104
105
  Vedeu::Views::Char.new(value: "\e[0m"),
105
106
  ]
@@ -0,0 +1,84 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module Renderers
6
+
7
+ describe Text do
8
+
9
+ let(:described) { Vedeu::Renderers::Text }
10
+ let(:instance) { described.new(options) }
11
+ let(:options) { {} }
12
+
13
+ let(:geometry) {
14
+ Vedeu::Geometries::Geometry.new(name: 'Vedeu::Renderers::Text',
15
+ x: 2,
16
+ xn: 4,
17
+ y: 2,
18
+ yn: 4)
19
+ }
20
+
21
+ describe '#initialize' do
22
+ it { instance.must_be_instance_of(described) }
23
+ end
24
+
25
+ describe '#clear' do
26
+ subject { instance.clear }
27
+
28
+ it { subject.must_equal('') }
29
+ end
30
+
31
+ describe '#render' do
32
+ let(:output) {}
33
+
34
+ before do
35
+ Vedeu.stubs(:height).returns(5)
36
+ Vedeu.stubs(:width).returns(5)
37
+ Vedeu.geometries.stubs(:by_name).returns(geometry)
38
+ ::File.stubs(:write)
39
+ end
40
+
41
+ subject { instance.render(output) }
42
+
43
+ context 'when the output is nil' do
44
+ it { subject.must_equal('') }
45
+ end
46
+
47
+ context 'when the output is a Vedeu::Models::Page' do
48
+ let(:output) { Vedeu::Models::Page.coerce(rows) }
49
+ let(:rows) {
50
+ [
51
+ Vedeu::Models::Row.new([
52
+ Vedeu::Cells::TopLeft.new,
53
+ Vedeu::Cells::TopHorizontal.new,
54
+ Vedeu::Cells::TopRight.new,
55
+ ]),
56
+ Vedeu::Models::Row.new([
57
+ Vedeu::Cells::LeftVertical.new,
58
+ Vedeu::Cells::Char.new,
59
+ Vedeu::Cells::RightVertical.new,
60
+ ]),
61
+ Vedeu::Models::Row.new([
62
+ Vedeu::Cells::BottomLeft.new,
63
+ Vedeu::Cells::BottomHorizontal.new,
64
+ Vedeu::Cells::BottomRight.new,
65
+ ]),
66
+ ]
67
+ }
68
+ let(:expected) {
69
+ " \n" \
70
+ " + + \n" \
71
+ " \n" \
72
+ " + + \n" \
73
+ " "
74
+ }
75
+
76
+ it { subject.must_equal(expected) }
77
+ end
78
+ end
79
+
80
+ end # Text
81
+
82
+ end # Renderers
83
+
84
+ end # Vedeu
@@ -109,6 +109,18 @@ module Vedeu
109
109
  it { subject.must_be_instance_of(Vedeu::Interfaces::Interface) }
110
110
  end
111
111
 
112
+ describe '#text' do
113
+ subject { instance.text }
114
+
115
+ it { subject.must_equal('a') }
116
+
117
+ context 'when there is a border defined' do
118
+ let(:border) { :horizontal }
119
+
120
+ it { subject.must_equal(' ') }
121
+ end
122
+ end
123
+
112
124
  describe '#to_hash' do
113
125
  let(:position) { Vedeu::Geometries::Position.coerce([17, 2]) }
114
126
  let(:expected) {
@@ -23,6 +23,7 @@ class VedeuMaterialColoursApp
23
23
  # foreground '#ffff00'
24
24
  # profile!
25
25
  log '/tmp/vedeu_material_colours_app.log'
26
+ log_except [:cursor, :update, :render]
26
27
  # height 11
27
28
  # width 20
28
29
  # renderers(Vedeu::Renderers::File
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vedeu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Laking
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-03 00:00:00.000000000 Z
11
+ date: 2015-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: guard
@@ -524,6 +524,7 @@ files:
524
524
  - lib/vedeu/renderers/options.rb
525
525
  - lib/vedeu/renderers/templates/html_renderer.vedeu
526
526
  - lib/vedeu/renderers/terminal.rb
527
+ - lib/vedeu/renderers/text.rb
527
528
  - lib/vedeu/repositories/all.rb
528
529
  - lib/vedeu/repositories/assemblage.rb
529
530
  - lib/vedeu/repositories/collection.rb
@@ -729,6 +730,7 @@ files:
729
730
  - test/lib/vedeu/renderers/json_test.rb
730
731
  - test/lib/vedeu/renderers/options_test.rb
731
732
  - test/lib/vedeu/renderers/terminal_test.rb
733
+ - test/lib/vedeu/renderers/text_test.rb
732
734
  - test/lib/vedeu/repositories/assemblage_test.rb
733
735
  - test/lib/vedeu/repositories/collection_test.rb
734
736
  - test/lib/vedeu/repositories/defaults_test.rb
@@ -971,6 +973,7 @@ test_files:
971
973
  - test/lib/vedeu/renderers/json_test.rb
972
974
  - test/lib/vedeu/renderers/options_test.rb
973
975
  - test/lib/vedeu/renderers/terminal_test.rb
976
+ - test/lib/vedeu/renderers/text_test.rb
974
977
  - test/lib/vedeu/repositories/assemblage_test.rb
975
978
  - test/lib/vedeu/repositories/collection_test.rb
976
979
  - test/lib/vedeu/repositories/defaults_test.rb