vedeu 0.0.18 → 0.0.19

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: a2bb1e7b3e6b2af51afa6ca62e74793542fc45ed
4
- data.tar.gz: ea682085e35d4ff848ac4d91a7984e52c03306ba
3
+ metadata.gz: fb683143c7b17b1af0dfa7bed0e800cfa7f0c6c9
4
+ data.tar.gz: 6b58626d636f27909b8786cdde59d4617cf9f200
5
5
  SHA512:
6
- metadata.gz: b1578296de167f5b21d80e206c35e7cef51fa3ec9a0962ce1d1c0a363c683a6513cd9f3d060d0744709ea4ed182c8c12f8b7e5bb3a924f21df9137b253f1fb19
7
- data.tar.gz: 215e9dd91bd325aae7d951d59a7a5687eedb569789bed8a05b8cad748f32c373da8f6b2d23865026191099f3eebaa3a1d4525391f81013da8232de91b374fc77
6
+ metadata.gz: 22d4512e7ccbd63da7d11fc08b072458ed4f0622eba0ec69d33a0d75e43b217337b264f353ba97e16a2d270ddc9b963a39ccaade556837ceeff56d7642746561
7
+ data.tar.gz: b8149ebaf7937cc9af8fb7f33b1825e10c71d73318ae74c611fa5af7e6081f36be540c87aa49a32f8b4c9cefe4cc93dd3639f800c89be8f142d64298acd8a4d2
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ Documentation:
2
+ Enabled: false
data/Rakefile CHANGED
@@ -14,7 +14,7 @@ Rake::TestTask.new(:minitest) do |t|
14
14
  t.verbose = false
15
15
  end
16
16
 
17
- task :default => :minitest
17
+ task default: :minitest
18
18
 
19
19
  Rake::Task['minitest'].execute
20
20
 
data/lib/vedeu.rb CHANGED
@@ -11,7 +11,6 @@ require_relative 'vedeu/support/terminal'
11
11
 
12
12
  require_relative 'vedeu/output/base'
13
13
  require_relative 'vedeu/output/background'
14
- require_relative 'vedeu/output/buffer'
15
14
  require_relative 'vedeu/output/compositor'
16
15
  require_relative 'vedeu/output/cursor'
17
16
  require_relative 'vedeu/output/directive'
@@ -43,7 +42,7 @@ require_relative 'vedeu/version'
43
42
  module Vedeu
44
43
  def self.logger
45
44
  @logger ||= Logger.new(root_path + '/logs/vedeu.log').tap do |log|
46
- log.formatter = proc do |mode, time, prog, msg|
45
+ log.formatter = proc do |_, time, _, msg|
47
46
  "\n#{time.iso8601}: #{msg}\n"
48
47
  end
49
48
  end
@@ -34,7 +34,7 @@ module Vedeu
34
34
  output.map do |lines|
35
35
  if lines.size < height
36
36
  remaining = height - lines.size
37
- remaining.times { |i| lines << "" }
37
+ remaining.times { |i| lines << '' }
38
38
  end
39
39
 
40
40
  lines.each_with_index do |stream, index|
@@ -10,9 +10,7 @@ module Vedeu
10
10
 
11
11
  def render
12
12
  InterfaceRepository.update.map do |interface|
13
- interface.map do |stream|
14
- Terminal.output(stream) unless stream.nil?
15
- end
13
+ interface.map { |stream| Terminal.output(stream) unless stream.nil? }
16
14
  end
17
15
  end
18
16
  end
@@ -9,7 +9,7 @@ module Vedeu
9
9
  def initialize; end
10
10
 
11
11
  def evaluate
12
- raise Collapse if result == :stop
12
+ fail Collapse if result == :stop
13
13
 
14
14
  Compositor.arrange(result) unless no_result?
15
15
  end
@@ -12,8 +12,8 @@ module Vedeu
12
12
  @attributes = attributes || {}
13
13
  @name = attributes[:name]
14
14
  @klass = attributes[:klass]
15
- @keyword = attributes.fetch(:options, {}).fetch(:keyword, "")
16
- @keypress = attributes.fetch(:options, {}).fetch(:keypress, "")
15
+ @keyword = attributes.fetch(:options, {}).fetch(:keyword, '')
16
+ @keypress = attributes.fetch(:options, {}).fetch(:keypress, '')
17
17
  end
18
18
 
19
19
  def create
@@ -26,7 +26,7 @@ module Vedeu
26
26
  end
27
27
 
28
28
  def executable
29
- Proc.new { |*args| attributes[:klass].dispatch(*args) }
29
+ proc { |*args| attributes[:klass].dispatch(*args) }
30
30
  end
31
31
  end
32
32
 
@@ -2,7 +2,7 @@ module Vedeu
2
2
  class Interface
3
3
  include Queue
4
4
 
5
- attr_accessor :id, :attributes, :active, :name
5
+ attr_accessor :id, :attributes, :active, :name, :cursor, :current
6
6
 
7
7
  class << self
8
8
  def create(attributes = {})
@@ -16,6 +16,7 @@ module Vedeu
16
16
  @active = false
17
17
  @name = attributes[:name]
18
18
  @cursor = attributes.fetch(:cursor, true)
19
+ @current = []
19
20
  end
20
21
 
21
22
  def create
@@ -28,9 +29,9 @@ module Vedeu
28
29
 
29
30
  def update
30
31
  if enqueued?
31
- dequeue
32
+ @current = dequeue
32
33
  else
33
- [cursor, colour.reset, geometry.origin]
34
+ @current
34
35
  end
35
36
  end
36
37
 
@@ -24,11 +24,9 @@ module Vedeu
24
24
  end
25
25
 
26
26
  def find_by_name(value)
27
- interface = query(klass, :name, value)
28
-
29
- raise UndefinedInterface if interface.nil?
30
-
31
- interface
27
+ query(klass, :name, value).tap do |interface|
28
+ fail UndefinedInterface unless interface
29
+ end
32
30
  end
33
31
 
34
32
  def update
@@ -4,16 +4,12 @@ module Vedeu
4
4
  @adaptor ||= Storage.new
5
5
  end
6
6
 
7
- def adaptor=(adaptor)
8
- @adaptor = adaptor
9
- end
10
-
11
7
  def find(id)
12
- adaptor.find(self.klass, id)
8
+ adaptor.find(klass, id)
13
9
  end
14
10
 
15
11
  def all
16
- adaptor.all(self.klass)
12
+ adaptor.all(klass)
17
13
  end
18
14
 
19
15
  def query(klass, attribute, value)
@@ -29,7 +25,7 @@ module Vedeu
29
25
  end
30
26
 
31
27
  def reset
32
- adaptor.reset(self.klass)
28
+ adaptor.reset(klass)
33
29
  end
34
30
  end
35
31
  end
@@ -2,11 +2,11 @@ module Vedeu
2
2
  class Storage
3
3
  def initialize
4
4
  @counter = 0
5
- @map = {}
5
+ @map = {}
6
6
  end
7
7
 
8
8
  def create(record)
9
- @counter = @counter + 1
9
+ @counter += 1
10
10
  record.id ||= @counter
11
11
  map_for(record)[record.id] = record
12
12
  end
@@ -28,7 +28,7 @@ module Vedeu
28
28
  end
29
29
 
30
30
  def query(klass, attribute, value)
31
- map_for_class(klass).select do |id, result|
31
+ map_for_class(klass).select do |_, result|
32
32
  return result if result.send(attribute) == value
33
33
  end
34
34
 
@@ -22,6 +22,7 @@ module Vedeu
22
22
  def clear
23
23
  store.clear
24
24
  end
25
+ alias_method :reset, :clear
25
26
 
26
27
  def view
27
28
  store.inspect
@@ -30,7 +31,7 @@ module Vedeu
30
31
  private
31
32
 
32
33
  def store
33
- @store ||= Array.new
34
+ @store ||= []
34
35
  end
35
36
  end
36
37
  end
@@ -63,7 +63,7 @@ module Vedeu
63
63
  end
64
64
 
65
65
  def clear_line(index)
66
- output(Position.set(index, 1) + (" " * width) + Position.set(index, 1))
66
+ output(Position.set(index, 1) + (' ' * width) + Position.set(index, 1))
67
67
  end
68
68
 
69
69
  def show_cursor
@@ -103,15 +103,15 @@ module Vedeu
103
103
 
104
104
  def terminal_mode(&block)
105
105
  {
106
- cooked: Proc.new { Terminal.cooked(self, &block) },
107
- raw: Proc.new { Terminal.raw(self, &block) }
106
+ cooked: proc { Terminal.cooked(self, &block) },
107
+ raw: proc { Terminal.raw(self, &block) }
108
108
  }
109
109
  end
110
110
 
111
111
  def cursor_mode
112
112
  {
113
- show: Proc.new { Terminal.show_cursor },
114
- hide: Proc.new { Terminal.hide_cursor }
113
+ show: proc { Terminal.show_cursor },
114
+ hide: proc { Terminal.hide_cursor }
115
115
  }
116
116
  end
117
117
 
@@ -128,11 +128,11 @@ module Vedeu
128
128
  end
129
129
 
130
130
  def clear_screen?
131
- return options.fetch(:clear)
131
+ options.fetch(:clear)
132
132
  end
133
133
 
134
134
  def noop
135
- Proc.new {}
135
+ proc {}
136
136
  end
137
137
 
138
138
  def options
data/lib/vedeu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vedeu
2
- VERSION = "0.0.18"
2
+ VERSION = '0.0.19'
3
3
  end
@@ -3,7 +3,7 @@ require_relative '../../../test_helper'
3
3
  module Vedeu
4
4
  describe Input do
5
5
  let(:described_class) { Input }
6
- let(:input) { "" }
6
+ let(:input) { '' }
7
7
  let(:subject) { described_class.new }
8
8
 
9
9
  before { Terminal.stubs(:input).returns(input) }
@@ -12,7 +12,7 @@ module Vedeu
12
12
  end
13
13
 
14
14
  it 'sets an instance variable' do
15
- subject.instance_variable_get("@pair").must_equal([])
15
+ subject.instance_variable_get('@pair').must_equal([])
16
16
  end
17
17
 
18
18
  describe '.set' do
@@ -23,11 +23,11 @@ module Vedeu
23
23
  end
24
24
 
25
25
  it 'sets an instance variable' do
26
- subject.instance_variable_get("@output").must_equal([[]])
26
+ subject.instance_variable_get('@output').must_equal([[]])
27
27
  end
28
28
 
29
29
  it 'sets an instance variable' do
30
- subject.instance_variable_get("@interface").must_equal("dummy")
30
+ subject.instance_variable_get('@interface').must_equal('dummy')
31
31
  end
32
32
 
33
33
  describe '.arrange' do
@@ -22,11 +22,11 @@ module Vedeu
22
22
  end
23
23
 
24
24
  it 'sets an instance variable' do
25
- subject.instance_variable_get("@interface").must_be_instance_of(Interface)
25
+ subject.instance_variable_get('@interface').must_be_instance_of(Interface)
26
26
  end
27
27
 
28
28
  it 'sets an instance variable' do
29
- subject.instance_variable_get("@directives").must_be_instance_of(Hash)
29
+ subject.instance_variable_get('@directives').must_be_instance_of(Hash)
30
30
  end
31
31
 
32
32
  describe '.enact' do
@@ -24,8 +24,8 @@ module Vedeu
24
24
 
25
25
  context 'when coordinates are provided' do
26
26
  let(:subject) { described_class.set(y, x) }
27
- let(:y) { 12 }
28
- let(:x) { 19 }
27
+ let(:y) { 12 }
28
+ let(:x) { 19 }
29
29
 
30
30
  it 'returns a position escape sequence' do
31
31
  subject.must_equal("\e[12;19H")
@@ -6,7 +6,7 @@ module Vedeu
6
6
 
7
7
  describe '.set' do
8
8
  let(:subject) { described_class.set(style) }
9
- let(:style) {}
9
+ let(:style) {}
10
10
 
11
11
  it 'returns a String' do
12
12
  subject.must_be_instance_of(String)
@@ -3,7 +3,7 @@ require_relative '../../../test_helper'
3
3
  module Vedeu
4
4
  describe Translator do
5
5
  let(:described_class) { Translator }
6
- let(:html_colour) {}
6
+ let(:html_colour) {}
7
7
 
8
8
  it 'returns a Translator instance' do
9
9
  described_class.new(html_colour).must_be_instance_of(Translator)
@@ -21,23 +21,23 @@ module Vedeu
21
21
  end
22
22
 
23
23
  it 'sets an instance variable' do
24
- subject.instance_variable_get("@attributes").must_equal(attributes)
24
+ subject.instance_variable_get('@attributes').must_equal(attributes)
25
25
  end
26
26
 
27
27
  it 'sets an instance variable' do
28
- subject.instance_variable_get("@name").must_equal('dummy')
28
+ subject.instance_variable_get('@name').must_equal('dummy')
29
29
  end
30
30
 
31
31
  it 'sets an instance variable' do
32
- subject.instance_variable_get("@klass").must_equal(DummyCommand)
32
+ subject.instance_variable_get('@klass').must_equal(DummyCommand)
33
33
  end
34
34
 
35
35
  it 'sets an instance variable' do
36
- subject.instance_variable_get("@keyword").must_equal('dummy')
36
+ subject.instance_variable_get('@keyword').must_equal('dummy')
37
37
  end
38
38
 
39
39
  it 'sets an instance variable' do
40
- subject.instance_variable_get("@keypress").must_equal('d')
40
+ subject.instance_variable_get('@keypress').must_equal('d')
41
41
  end
42
42
 
43
43
  describe '#create' do
@@ -19,20 +19,22 @@ module Vedeu
19
19
  }
20
20
  let(:result) {}
21
21
 
22
+ after { InterfaceRepository.reset }
23
+
22
24
  it 'returns an Interface instance' do
23
25
  subject.must_be_instance_of(Interface)
24
26
  end
25
27
 
26
28
  it 'sets an instance variable' do
27
- subject.instance_variable_get("@attributes").must_equal(attributes)
29
+ subject.instance_variable_get('@attributes').must_equal(attributes)
28
30
  end
29
31
 
30
32
  it 'sets an instance variable' do
31
- subject.instance_variable_get("@active").must_equal(false)
33
+ subject.instance_variable_get('@active').must_equal(false)
32
34
  end
33
35
 
34
36
  it 'sets an instance variable' do
35
- subject.instance_variable_get("@name").must_equal('dummy')
37
+ subject.instance_variable_get('@name').must_equal('dummy')
36
38
  end
37
39
 
38
40
  describe '#create' do
@@ -36,15 +36,6 @@ module Vedeu
36
36
  end
37
37
  end
38
38
 
39
- describe '#adaptor=' do
40
- let(:subject) { described_class.adaptor=(adaptor) }
41
- let(:adaptor) { Storage.new }
42
-
43
- it 'returns a Storage' do
44
- subject.must_be_instance_of(Storage)
45
- end
46
- end
47
-
48
39
  describe '#find' do
49
40
  let(:subject) { described_class.find(id) }
50
41
  let(:id) { @dummy.id }
@@ -12,11 +12,11 @@ module Vedeu
12
12
  end
13
13
 
14
14
  it 'sets an instance variable' do
15
- subject.instance_variable_get("@counter").must_equal(0)
15
+ subject.instance_variable_get('@counter').must_equal(0)
16
16
  end
17
17
 
18
18
  it 'sets an instance variable' do
19
- subject.instance_variable_get("@map").must_equal({})
19
+ subject.instance_variable_get('@map').must_equal({})
20
20
  end
21
21
 
22
22
  describe '#create' do
@@ -17,7 +17,7 @@ module Vedeu
17
17
  end
18
18
 
19
19
  it 'sets an instance variable' do
20
- subject.instance_variable_get("@running").must_equal(true)
20
+ subject.instance_variable_get('@running').must_equal(true)
21
21
  end
22
22
 
23
23
  describe '.main_sequence' do
@@ -4,21 +4,19 @@ module Vedeu
4
4
  describe Queue do
5
5
  let(:described_class) { Queue }
6
6
 
7
- before { described_class.enqueue(:result) }
8
- after { described_class.clear }
9
-
10
7
  describe '.dequeue' do
11
8
  let(:subject) { described_class.dequeue }
12
9
 
13
10
  context 'when the queue is empty' do
14
- before { described_class.clear }
15
-
16
11
  it 'returns a NilClass' do
17
12
  subject.must_be_instance_of(NilClass)
18
13
  end
19
14
  end
20
15
 
21
16
  context 'when the queue is not empty' do
17
+ before { described_class.enqueue(:result) }
18
+ after { described_class.clear }
19
+
22
20
  it 'returns the first entry added' do
23
21
  subject.must_be_instance_of(Symbol)
24
22
  end
@@ -26,15 +24,16 @@ module Vedeu
26
24
  end
27
25
 
28
26
  describe '.enqueue' do
29
- let(:subject) { described_class.enqueue(result) }
30
- let(:result) { :result }
27
+ let(:subject) { described_class.enqueue(:result) }
28
+
29
+ after { described_class.clear }
31
30
 
32
31
  it 'returns an Array' do
33
32
  subject.must_be_instance_of(Array)
34
33
  end
35
34
 
36
35
  it 'contains the enqueued item' do
37
- subject.size.must_equal(2)
36
+ subject.size.must_equal(1)
38
37
  end
39
38
  end
40
39
 
@@ -42,14 +41,15 @@ module Vedeu
42
41
  let(:subject) { described_class.enqueued? }
43
42
 
44
43
  context 'when the queue contains data' do
44
+ before { described_class.enqueue(:result) }
45
+ after { described_class.clear }
46
+
45
47
  it 'returns a TrueClass' do
46
48
  subject.must_be_instance_of(TrueClass)
47
49
  end
48
50
  end
49
51
 
50
52
  context 'when the queue is empty' do
51
- before { described_class.clear }
52
-
53
53
  it 'returns a FalseClass' do
54
54
  subject.must_be_instance_of(FalseClass)
55
55
  end
@@ -64,7 +64,7 @@ module Vedeu
64
64
  end
65
65
 
66
66
  it 'returns the size of the queue' do
67
- subject.must_equal(1)
67
+ subject.must_equal(0)
68
68
  end
69
69
  end
70
70
 
@@ -88,7 +88,7 @@ module Vedeu
88
88
  end
89
89
 
90
90
  it 'returns the queue as a String' do
91
- subject.must_equal("[:result]")
91
+ subject.must_equal('[]')
92
92
  end
93
93
  end
94
94
  end
@@ -21,7 +21,7 @@ module Vedeu
21
21
  end
22
22
 
23
23
  it 'returns the entered string' do
24
- subject.must_equal("test")
24
+ subject.must_equal('test')
25
25
  end
26
26
  end
27
27
 
@@ -33,7 +33,7 @@ module Vedeu
33
33
  end
34
34
 
35
35
  it 'returns the output' do
36
- subject.must_equal("")
36
+ subject.must_equal('')
37
37
  end
38
38
  end
39
39
 
data/test/test_helper.rb CHANGED
@@ -6,7 +6,7 @@ require 'pry'
6
6
  SimpleCov.start do
7
7
  command_name 'MiniTest::Spec'
8
8
  add_filter '/test/'
9
- end unless ENV["no_simplecov"]
9
+ end unless ENV['no_simplecov']
10
10
 
11
11
  module MiniTest
12
12
  class Spec
@@ -22,7 +22,10 @@ end
22
22
 
23
23
  # commented out by default (makes tests slower)
24
24
  # require 'minitest/reporters'
25
- # Minitest::Reporters.use!(Minitest::Reporters::SpecReporter.new)
25
+ # Minitest::Reporters.use!(
26
+ # Minitest::Reporters::DefaultReporter.new({ color: true, slow_count: 5 })
27
+ # Minitest::Reporters::SpecReporter.new
28
+ # )
26
29
 
27
30
  require_relative '../lib/vedeu.rb'
28
31
 
data/vedeu.gemspec CHANGED
@@ -4,29 +4,30 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'vedeu/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "vedeu"
7
+ spec.name = 'vedeu'
8
8
  spec.version = Vedeu::VERSION
9
- spec.authors = ["Gavin Laking"]
10
- spec.email = ["gavinlaking@gmail.com"]
9
+ spec.authors = ['Gavin Laking']
10
+ spec.email = ['gavinlaking@gmail.com']
11
11
  spec.summary = %q{A terminal case of wonderland.}
12
- spec.homepage = "http://www.gavinlaking.name/"
13
- spec.license = "MIT"
12
+ spec.homepage = 'http://www.gavinlaking.name/'
13
+ spec.license = 'MIT'
14
14
 
15
15
  spec.files = `git ls-files -z`.split("\x0")
16
16
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
- spec.require_paths = ["lib"]
18
+ spec.require_paths = ['lib']
19
19
 
20
- spec.add_development_dependency "aruba", "0.5.4"
21
- spec.add_development_dependency "bundler", "~> 1.5"
22
- spec.add_development_dependency "cucumber", "1.3.15"
23
- spec.add_development_dependency "guard-cucumber", "1.4.1"
24
- spec.add_development_dependency "guard", "2.6.1"
25
- spec.add_development_dependency "guard-minitest", "2.3.0"
26
- spec.add_development_dependency "minitest", "5.3.4"
27
- spec.add_development_dependency "minitest-reporters", "1.0.4"
28
- spec.add_development_dependency "mocha", "1.1.0"
29
- spec.add_development_dependency "pry", "0.10.0"
30
- spec.add_development_dependency "rake", "10.3.2"
31
- spec.add_development_dependency "simplecov", "0.8.2"
20
+ spec.add_development_dependency 'aruba', '0.5.4'
21
+ spec.add_development_dependency 'bundler', '~> 1.5'
22
+ spec.add_development_dependency 'cucumber', '1.3.15'
23
+ spec.add_development_dependency 'guard-cucumber', '1.4.1'
24
+ spec.add_development_dependency 'guard', '2.6.1'
25
+ spec.add_development_dependency 'guard-minitest', '2.3.0'
26
+ spec.add_development_dependency 'minitest', '5.3.4'
27
+ spec.add_development_dependency 'minitest-reporters', '1.0.4'
28
+ spec.add_development_dependency 'mocha', '1.1.0'
29
+ spec.add_development_dependency 'pry', '0.10.0'
30
+ spec.add_development_dependency 'rake', '10.3.2'
31
+ spec.add_development_dependency 'rubocop'
32
+ spec.add_development_dependency 'simplecov', '0.8.2'
32
33
  end
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.0.18
4
+ version: 0.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Laking
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-17 00:00:00.000000000 Z
11
+ date: 2014-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aruba
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - '='
165
165
  - !ruby/object:Gem::Version
166
166
  version: 10.3.2
167
+ - !ruby/object:Gem::Dependency
168
+ name: rubocop
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: simplecov
169
183
  requirement: !ruby/object:Gem::Requirement
@@ -187,6 +201,7 @@ extensions: []
187
201
  extra_rdoc_files: []
188
202
  files:
189
203
  - ".gitignore"
204
+ - ".rubocop.yml"
190
205
  - ".ruby-version"
191
206
  - Gemfile
192
207
  - Guardfile
@@ -214,7 +229,6 @@ files:
214
229
  - lib/vedeu/launcher.rb
215
230
  - lib/vedeu/output/background.rb
216
231
  - lib/vedeu/output/base.rb
217
- - lib/vedeu/output/buffer.rb
218
232
  - lib/vedeu/output/colour.rb
219
233
  - lib/vedeu/output/compositor.rb
220
234
  - lib/vedeu/output/cursor.rb
@@ -246,7 +260,6 @@ files:
246
260
  - test/lib/vedeu/launcher_test.rb
247
261
  - test/lib/vedeu/output/background_test.rb
248
262
  - test/lib/vedeu/output/base_test.rb
249
- - test/lib/vedeu/output/buffer_test.rb
250
263
  - test/lib/vedeu/output/colour_test.rb
251
264
  - test/lib/vedeu/output/compositor_test.rb
252
265
  - test/lib/vedeu/output/cursor_test.rb
@@ -310,7 +323,6 @@ test_files:
310
323
  - test/lib/vedeu/launcher_test.rb
311
324
  - test/lib/vedeu/output/background_test.rb
312
325
  - test/lib/vedeu/output/base_test.rb
313
- - test/lib/vedeu/output/buffer_test.rb
314
326
  - test/lib/vedeu/output/colour_test.rb
315
327
  - test/lib/vedeu/output/compositor_test.rb
316
328
  - test/lib/vedeu/output/cursor_test.rb
@@ -1,96 +0,0 @@
1
- module Vedeu
2
- class OutOfRangeError < StandardError; end
3
-
4
- class Buffer
5
- include Enumerable
6
-
7
- attr_accessor :buffer
8
-
9
- def initialize(options = {})
10
- @options = options
11
- @buffer = Array.new(height) { Array.new(width) { :cell } }
12
- end
13
-
14
- def to_s
15
- each { |row| puts row.inspect }
16
- nil
17
- end
18
-
19
- def each(&block)
20
- buffer.each(&block)
21
- end
22
-
23
- def cell(y, x)
24
- raise OutOfRangeError if invalid_reference?(y, x)
25
- buffer[y][x]
26
- end
27
-
28
- def set_cell(y, x, v = '')
29
- raise OutOfRangeError if invalid_reference?(y, x)
30
- buffer[y][x] = v
31
- end
32
-
33
- def set_row(y = 0, v = '')
34
- if v.is_a?(String)
35
- v.chars.each_with_index { |c, i| set_cell(y, i, c) }
36
- else
37
- v.each_with_index { |el, i| set_cell(y, i, el) }
38
- end
39
- row(y)
40
- end
41
-
42
- def row(y = 0)
43
- buffer[y]
44
- end
45
- alias_method :y, :row
46
-
47
- def set_column(x = 0, v = '')
48
- if v.is_a?(String)
49
- v.chars.each_with_index { |c, i| set_cell(i, x, c) }
50
- else
51
- v.each_with_index { |el, i| set_cell(i, x, el) }
52
- end
53
- column(x)
54
- end
55
-
56
- def column(x = 0)
57
- buffer.inject([]) { |a, e| a << e[x] }
58
- end
59
- alias_method :x, :column
60
-
61
- private
62
-
63
- def invalid_reference?(y, x)
64
- invalid_line?(y) || invalid_column?(x)
65
- end
66
-
67
- def invalid_line?(y)
68
- y < 0 || y > (height - 1)
69
- end
70
-
71
- def invalid_column?(x)
72
- x < 0 || x > (width - 1)
73
- end
74
-
75
- def width
76
- options.fetch(:width)
77
- end
78
- alias_method :columns, :width
79
-
80
- def height
81
- options.fetch(:height)
82
- end
83
- alias_method :lines, :height
84
-
85
- def options
86
- defaults.merge!(@options)
87
- end
88
-
89
- def defaults
90
- {
91
- width: Terminal.width,
92
- height: Terminal.height
93
- }
94
- end
95
- end
96
- end
@@ -1,167 +0,0 @@
1
- require_relative '../../../test_helper'
2
-
3
- module Vedeu
4
- describe Buffer do
5
- let(:described_class) { Buffer }
6
- let(:described_instance) { described_class.new(options) }
7
- let(:options) { { width: 4, height: 3 } }
8
- let(:subject) { described_instance }
9
-
10
- it 'returns a Buffer instance' do
11
- subject.must_be_instance_of(Buffer)
12
- end
13
-
14
- it 'sets an instance variable' do
15
- subject.instance_variable_get("@options").must_equal(options)
16
- end
17
-
18
- describe '#to_s' do
19
- let(:subject) { capture_io { described_instance.to_s }.join }
20
-
21
- # real method should return NilClass; want to capture io rather
22
- # than have it spew into minitest output in terminal; see test
23
- # below.
24
- # it { subject.must_be_instance_of(NilClass) }
25
-
26
- it "outputs the content of the buffer" do
27
- subject.must_equal("[:cell, :cell, :cell, :cell]\n" \
28
- "[:cell, :cell, :cell, :cell]\n" \
29
- "[:cell, :cell, :cell, :cell]\n")
30
- end
31
- end
32
-
33
- describe '#each' do
34
- let(:subject) { described_instance.each }
35
-
36
- it 'returns an Enumerator' do
37
- subject.must_be_instance_of(Enumerator)
38
- end
39
- end
40
-
41
- describe '#cell' do
42
- let(:subject) { described_instance.cell(y, x) }
43
- let(:y) { 1 }
44
- let(:x) { 2 }
45
-
46
- it 'returns a Symbol' do
47
- subject.must_be_instance_of(Symbol)
48
- end
49
-
50
- context 'when the reference is in range' do
51
- it 'returns the value at that location' do
52
- subject.must_equal(:cell)
53
- end
54
- end
55
-
56
- context 'when the reference is out of range' do
57
- let(:y) { 4 }
58
-
59
- it 'raises an exception' do
60
- proc { subject }.must_raise(OutOfRangeError)
61
- end
62
- end
63
- end
64
-
65
- describe '#set_cell' do
66
- let(:subject) { described_instance.set_cell(y, x, v) }
67
- let(:y) { 1 }
68
- let(:x) { 2 }
69
- let(:v) { '*' }
70
-
71
- it 'returns a String' do
72
- subject.must_be_instance_of(String)
73
- end
74
-
75
- context 'when the reference is in range' do
76
- it 'returns the value at that location' do
77
- subject.must_equal('*')
78
- end
79
- end
80
-
81
- context 'when the reference is out of range' do
82
- let(:y) { 3 }
83
- let(:x) { 4 }
84
-
85
- it 'raises an exception' do
86
- proc { subject }.must_raise(OutOfRangeError)
87
- end
88
- end
89
- end
90
-
91
- describe '#set_row' do
92
- let(:subject) { described_instance.set_row(y, v) }
93
- let(:y) { 1 }
94
- let(:v) { '****' }
95
-
96
- it 'returns an Array' do
97
- subject.must_be_instance_of(Array)
98
- end
99
-
100
- context 'when the value is a String' do
101
- let(:v) { '****' }
102
-
103
- it 'sets the row' do
104
- subject.must_equal(['*', '*', '*', '*'])
105
- end
106
- end
107
-
108
- context 'when the value is an Array' do
109
- let(:v) { ['*','*','*','*'] }
110
-
111
- it 'sets the row' do
112
- subject.must_equal(['*', '*', '*', '*'])
113
- end
114
- end
115
- end
116
-
117
- describe '#row' do
118
- let(:subject) { described_instance.row }
119
-
120
- it 'returns an Array' do
121
- subject.must_be_instance_of(Array)
122
- end
123
-
124
- it 'returns the content of the row at position y' do
125
- subject.must_equal([:cell, :cell, :cell, :cell])
126
- end
127
- end
128
-
129
- describe '#set_column' do
130
- let(:subject) { described_instance.set_column(x, v) }
131
- let(:x) { 2 }
132
- let(:v) { '***' }
133
-
134
- it 'returns an Array' do
135
- subject.must_be_instance_of(Array)
136
- end
137
-
138
- context 'when the value is a String' do
139
- let(:v) { '***' }
140
-
141
- it 'sets the row' do
142
- subject.must_equal(['*', '*', '*'])
143
- end
144
- end
145
-
146
- context 'when the value is an Array' do
147
- let(:v) { ['*', '*', '*'] }
148
-
149
- it 'sets the row' do
150
- subject.must_equal(['*', '*', '*'])
151
- end
152
- end
153
- end
154
-
155
- describe '#column' do
156
- let(:subject) { described_instance.column }
157
-
158
- it 'returns an Array' do
159
- subject.must_be_instance_of(Array)
160
- end
161
-
162
- it 'returns the content of the column at position x' do
163
- subject.must_equal([:cell, :cell, :cell])
164
- end
165
- end
166
- end
167
- end