vedeu 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78eafb32b9a942a36cbc9ed4d65bf96542e39c03
4
- data.tar.gz: 6e79f409e8be1e884060585b04066ae0995e7aac
3
+ metadata.gz: e3051d98a552c6a3129de526b25593c3e7f0be00
4
+ data.tar.gz: 32c2e964c4556e84f06f02bd0278fd466281693b
5
5
  SHA512:
6
- metadata.gz: 3fb0a166b340bae5d0ba423c698f6304f20777291ab316defa98b5b4dbcdf91fed7160b1c567663346052fdced575e11d32fc0aec7fc6c59cae10ce48993cccb
7
- data.tar.gz: c4e0c6cdea25d795fde8bc46358f74656efc15e69609efcd390c24d8464ce9f1163dcceaf44337ecf6f9b05081e7ce2d248a692e7905ebe0899440546b190c71
6
+ metadata.gz: b9fd3e03a60603baf573466fcf384b8b625fa5be156ab87e321c060eb391fbe84b1113ff4f27c1dc1a0fbc307fb536802436a894c958f864b5f1b2ea24564d8b
7
+ data.tar.gz: a09c6e80a05b2a44bfc029b563acbb79d09d2fd16b00355b29d074176a72090d2a2dd3745e12b17a5b414f7b2c953f50a7f7278294ae682e634e029faf101ac2
data/README.md CHANGED
@@ -28,24 +28,6 @@ TODO: Write detailed documentation
28
28
  |-- Interfaces
29
29
  | |-- Dummy < Interface
30
30
  |
31
- |-- Process
32
- | |-- Commands
33
- | | |-- Command
34
- | |
35
- | |-- Compositor
36
- | | |-- Directive
37
- | | | |-- Colour
38
- | | | | |-- Foreground < Base
39
- | | | | |-- Background < Base
40
- | | | |
41
- | | | |-- Position
42
- | | | |-- Style
43
- | | | |-- Esc
44
- | | |
45
- | | |-- Terminal
46
- | |
47
- | |-- Terminal
48
- |
49
31
  |-- Terminal
50
32
 
51
33
  Base
@@ -53,6 +35,22 @@ TODO: Write detailed documentation
53
35
  |-- Esc
54
36
 
55
37
  Interface
38
+ |-- Commands
39
+ | |-- Command
40
+ | |-- Exit
41
+ |
42
+ |-- Compositor
43
+ | |-- Directive
44
+ | | |-- Colour
45
+ | | | |-- Foreground < Base
46
+ | | | |-- Background < Base
47
+ | | |
48
+ | | |-- Position
49
+ | | |-- Style
50
+ | | |-- Esc
51
+ | |
52
+ | |-- Terminal
53
+ |
56
54
  |-- Terminal
57
55
 
58
56
  Terminal
@@ -1,5 +1,4 @@
1
1
  require 'io/console'
2
- require 'singleton'
3
2
 
4
3
  require_relative 'vedeu/support/terminal'
5
4
 
@@ -21,7 +20,6 @@ require_relative 'vedeu/interface/dummy'
21
20
  require_relative 'vedeu/process/commands'
22
21
  require_relative 'vedeu/process/command'
23
22
  require_relative 'vedeu/process/exit'
24
- require_relative 'vedeu/process/process'
25
23
 
26
24
  require_relative 'vedeu/application'
27
25
  require_relative 'vedeu/version'
@@ -1,18 +1,20 @@
1
1
  module Vedeu
2
2
  class Application
3
3
  class << self
4
- def start(interfaces = nil, options = {})
5
- new(interfaces, options).start
4
+ def start(options = {})
5
+ new(options).main_sequence
6
6
  end
7
7
  end
8
8
 
9
- def initialize(interfaces = nil, options = {})
10
- @interfaces, @options = interfaces, options
9
+ def initialize(options = {})
10
+ @options = options
11
11
  end
12
12
 
13
- def start
13
+ def main_sequence
14
14
  Terminal.open(options) do
15
- Process.main_sequence(interfaces)
15
+ initial_state
16
+
17
+ event_loop
16
18
  end
17
19
  ensure
18
20
  Terminal.close
@@ -20,7 +22,19 @@ module Vedeu
20
22
 
21
23
  private
22
24
 
23
- attr_reader :interfaces, :options
25
+ attr_reader :options
26
+
27
+ def event_loop
28
+ interfaces.event_loop
29
+ end
30
+
31
+ def initial_state
32
+ interfaces.initial_state
33
+ end
34
+
35
+ def interfaces
36
+ @interfaces ||= Interfaces.defined || Interfaces.default
37
+ end
24
38
 
25
39
  def options
26
40
  defaults.merge!(@options)
@@ -1,21 +1,27 @@
1
1
  module Vedeu
2
2
  class UndefinedInterface < StandardError; end
3
3
 
4
- class Interfaces
5
- class << self
6
- def default
7
- new { |io| io.add(:dummy, Dummy) }
8
- end
4
+ module Interfaces
5
+ extend self
9
6
 
10
- def define(&block)
11
- new(&block)
12
- end
7
+ def default
8
+ add(:dummy, Dummy)
13
9
  end
14
10
 
15
- def initialize(&block)
16
- @interfaces ||= {}
11
+ def defined
12
+ interfaces.empty? ? nil : interfaces
13
+ end
14
+
15
+ def define(&block)
16
+ if block_given?
17
+ yield self
18
+ else
19
+ self
20
+ end
21
+ end
17
22
 
18
- yield self if block_given?
23
+ def list
24
+ interfaces.inspect
19
25
  end
20
26
 
21
27
  def add(name, klass, options = {})
@@ -25,10 +31,6 @@ module Vedeu
25
31
  end
26
32
  end
27
33
 
28
- def show
29
- interfaces
30
- end
31
-
32
34
  def initial_state
33
35
  interfaces.values.map { |io| io.call.initial_state }
34
36
  end
@@ -39,11 +41,13 @@ module Vedeu
39
41
 
40
42
  private
41
43
 
42
- attr_accessor :interfaces
43
-
44
44
  def valid?(klass)
45
45
  raise UndefinedInterface unless Object.const_defined?(klass.to_s)
46
46
  true
47
47
  end
48
+
49
+ def interfaces
50
+ @interfaces ||= {}
51
+ end
48
52
  end
49
53
  end
@@ -1,15 +1,15 @@
1
1
  module Vedeu
2
2
  class Compositor
3
3
  class << self
4
- def write(output = [], options = {})
4
+ def write(output = [])
5
5
  return if output.nil? || output.empty?
6
6
 
7
- new(output, options).write
7
+ new(output).write
8
8
  end
9
9
  end
10
10
 
11
- def initialize(output = [], options = {})
12
- @output, @options = output, options
11
+ def initialize(output = [])
12
+ @output = output
13
13
  end
14
14
 
15
15
  def write
@@ -48,13 +48,5 @@ module Vedeu
48
48
  def write_line(data)
49
49
  Terminal.output(data)
50
50
  end
51
-
52
- def options
53
- defaults.merge!(@options)
54
- end
55
-
56
- def defaults
57
- {}
58
- end
59
51
  end
60
52
  end
@@ -12,7 +12,7 @@ module Vedeu
12
12
 
13
13
  def translate
14
14
  return unless valid?
15
- [term_colour_base, red, green, blue].inject(:+)
15
+ [16, red, green, blue].inject(:+)
16
16
  end
17
17
 
18
18
  private
@@ -20,31 +20,15 @@ module Vedeu
20
20
  attr_reader :html_colour
21
21
 
22
22
  def red
23
- (html_colour[1..2].to_i(16) / colour_divide) * 36
23
+ (html_colour[1..2].to_i(16) / 51) * 36
24
24
  end
25
25
 
26
26
  def green
27
- (html_colour[3..4].to_i(16) / colour_divide) * 6
27
+ (html_colour[3..4].to_i(16) / 51) * 6
28
28
  end
29
29
 
30
30
  def blue
31
- (html_colour[5..6].to_i(16) / colour_divide) * 1
32
- end
33
-
34
- def colour_divide
35
- source_values / target_values
36
- end
37
-
38
- def source_values
39
- 256
40
- end
41
-
42
- def target_values
43
- 5
44
- end
45
-
46
- def term_colour_base
47
- 16
31
+ (html_colour[5..6].to_i(16) / 51) * 1
48
32
  end
49
33
 
50
34
  def valid?
@@ -1,38 +1,16 @@
1
1
  module Vedeu
2
- class Commands
3
- include Singleton
4
-
5
- class << self
6
- def instance(&block)
7
- @instance ||= new(&block)
8
- end
9
- alias_method :define, :instance
10
-
11
- # def define(name, klass, args = [], options = {}, &block)
12
- # instance.define(name, klass, args = [], options = {})
13
- # end
14
-
15
- def execute(command = "")
16
- instance.execute(command)
17
- end
18
-
19
- def list
20
- instance.list
2
+ module Commands
3
+ extend self
4
+
5
+ def define(&block)
6
+ if block_given?
7
+ yield self
8
+ else
9
+ self
21
10
  end
22
11
  end
23
12
 
24
- def initialize(&block)
25
- @commands ||= { 'exit' => Proc.new { Exit.dispatch } }
26
-
27
- yield self if block_given?
28
- end
29
-
30
- def define(name, klass, args = [], options = {})
31
- commands.merge!(Command.define(name, klass, args, options))
32
- end
33
- alias_method :add, :define
34
-
35
- def execute(command)
13
+ def execute(command = "")
36
14
  commands.fetch(command).call if exists?(command)
37
15
  end
38
16
 
@@ -40,13 +18,18 @@ module Vedeu
40
18
  commands.inspect
41
19
  end
42
20
 
43
- private
21
+ def add(name, klass, args = [], options = {})
22
+ commands.merge!(Command.define(name, klass, args, options))
23
+ end
44
24
 
45
- attr_accessor :commands
46
- attr_accessor :instance
25
+ private
47
26
 
48
27
  def exists?(command)
49
28
  commands.fetch(command, false)
50
29
  end
30
+
31
+ def commands
32
+ @commands ||= { 'exit' => Proc.new { Exit.dispatch } }
33
+ end
51
34
  end
52
35
  end
@@ -1,3 +1,3 @@
1
1
  module Vedeu
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -3,14 +3,11 @@ require_relative '../../test_helper'
3
3
  module Vedeu
4
4
  describe Application do
5
5
  let(:described_class) { Application }
6
- let(:instance) { described_class.new(interfaces, options) }
7
- let(:interfaces) {}
6
+ let(:instance) { described_class.new(options) }
8
7
  let(:options) { {} }
9
8
 
10
- describe '#start' do
11
- before { Esc.stubs(:clear).returns('') }
12
-
13
- subject { instance.start }
9
+ describe '.start' do
10
+ subject { described_class.start(options) }
14
11
 
15
12
  it { skip }
16
13
  end
@@ -1,35 +1,43 @@
1
1
  require_relative '../../../test_helper'
2
2
 
3
3
  module Vedeu
4
- describe Interfaces do
5
- let(:described_class) { Interfaces }
6
- let(:instance) { described_class.new }
7
- let(:block) {}
4
+ class DummyInterface < Interface
5
+ def initial_state; end
6
+
7
+ def event_loop; end
8
+ end
8
9
 
9
- it { instance.must_be_instance_of(Interfaces) }
10
+ describe Interfaces do
11
+ let(:described_class) { Interfaces }
10
12
 
11
13
  describe '.default' do
12
14
  subject { described_class.default }
13
15
 
14
- it { subject.must_be_instance_of(Interfaces) }
16
+ it { subject.must_be_instance_of(Hash) }
15
17
 
16
18
  it 'adds the dummy interface to the interface list' do
17
- subject.show.wont_be_empty
19
+ described_class.list.wont_be_empty
18
20
  end
19
21
  end
20
22
 
23
+ describe '.defined' do
24
+ subject { described_class.defined }
25
+
26
+ it { subject.must_be_instance_of(Hash) }
27
+ end
28
+
21
29
  describe '.define' do
22
30
  subject { described_class.define }
23
31
 
24
- it { subject.must_be_instance_of(Interfaces) }
32
+ it { subject.must_be_instance_of(Module) }
25
33
  end
26
34
 
27
- describe '#add' do
28
- let(:interface_name) {}
29
- let(:klass) { Class }
30
- let(:options) { {} }
35
+ describe '.add' do
36
+ let(:interface) {}
37
+ let(:klass) { DummyInterface }
38
+ let(:options) { {} }
31
39
 
32
- subject { instance.add(interface_name, klass, options) }
40
+ subject { described_class.add(interface, klass, options) }
33
41
 
34
42
  it { subject.must_be_instance_of(Hash) }
35
43
 
@@ -42,20 +50,25 @@ module Vedeu
42
50
  end
43
51
  end
44
52
 
45
- describe '#show' do
46
- subject { instance.show }
53
+ describe '.list' do
54
+ subject { described_class.list }
47
55
 
48
- it { subject.must_be_instance_of(Hash) }
56
+ it { subject.must_be_instance_of(String) }
49
57
  end
50
58
 
51
- describe '#initial_state' do
52
- subject { instance.initial_state }
59
+ describe '.initial_state' do
60
+ subject { described_class.initial_state }
53
61
 
54
62
  it { subject.must_be_instance_of(Array) }
55
63
  end
56
64
 
57
- describe '#event_loop' do
58
- subject { instance.event_loop }
65
+ describe '.event_loop' do
66
+ before do
67
+ Terminal.stubs(:input)
68
+ Commands.stubs(:execute).returns(:stop)
69
+ end
70
+
71
+ subject { described_class.event_loop }
59
72
 
60
73
  it { subject.must_be_instance_of(Array) }
61
74
  end
@@ -2,7 +2,7 @@ require_relative '../../../test_helper'
2
2
 
3
3
  module Vedeu
4
4
  describe Compositor do
5
- let(:described_class) { Compositor }
5
+ let(:described_class) { Compositor }
6
6
  let(:instance) { described_class.new(rows) }
7
7
  let(:rows) { [[]] }
8
8
 
@@ -43,6 +43,12 @@ module Vedeu
43
43
  it { subject.must_equal("\e[0m") }
44
44
  end
45
45
 
46
+ context 'when the style is normal' do
47
+ let(:style) { :normal }
48
+
49
+ it { subject.must_equal("\e[0m") }
50
+ end
51
+
46
52
  context 'when the style is show_cursor' do
47
53
  let(:style) { :show_cursor }
48
54
 
@@ -2,11 +2,10 @@ require_relative '../../../test_helper'
2
2
 
3
3
  module Vedeu
4
4
  describe Translator do
5
- let(:described_class) { Translator }
6
- let(:instance) { described_class.new(html_colour) }
5
+ let(:described_class) { Translator }
7
6
  let(:html_colour) {}
8
7
 
9
- it { instance.must_be_instance_of(Translator) }
8
+ it { described_class.new(html_colour).must_be_instance_of(Translator) }
10
9
 
11
10
  describe '#translate' do
12
11
  {
@@ -31,7 +30,7 @@ module Vedeu
31
30
  described_class.translate.must_equal(nil)
32
31
  end
33
32
 
34
- it 'returns nil when the wrong type' do
33
+ it 'returns nil when the wrong type!' do
35
34
  described_class.translate(:wrong_type).must_equal(nil)
36
35
  end
37
36
 
@@ -1,16 +1,20 @@
1
1
  require_relative '../../../test_helper'
2
2
 
3
3
  module Vedeu
4
- class DummyCommandKlass
5
- def self.dispatch; end
4
+ class DummyCommand
5
+ def self.dispatch
6
+ :noop
7
+ end
6
8
  end
7
9
 
8
10
  describe Commands do
9
- let(:described_class) { Commands }
10
- let(:instance) { described_class.instance }
11
- let(:block) {}
11
+ let(:described_class) { Commands }
12
+
13
+ describe '.define' do
14
+ subject { described_class.define }
12
15
 
13
- it { instance.must_be_instance_of(Commands) }
16
+ it { skip }
17
+ end
14
18
 
15
19
  describe '.execute' do
16
20
  subject { described_class.execute }
@@ -24,27 +28,15 @@ module Vedeu
24
28
  it { subject.must_be_instance_of(String) }
25
29
  end
26
30
 
27
- describe '#define' do
31
+ describe '.add' do
28
32
  let(:command_name) { "some_name" }
29
- let(:command_klass) { DummyCommandKlass }
33
+ let(:command_klass) { DummyCommand }
30
34
  let(:args) { [] }
31
35
  let(:options) { {} }
32
36
 
33
- subject { instance.define(command_name, command_klass, args, options) }
37
+ subject { described_class.add(command_name, command_klass, args, options) }
34
38
 
35
39
  it { subject.must_be_instance_of(Hash) }
36
40
  end
37
-
38
- describe '#execute' do
39
- subject { instance.execute }
40
-
41
- it { skip }
42
- end
43
-
44
- describe '#list' do
45
- subject { instance.list }
46
-
47
- it { subject.must_be_instance_of(String) }
48
- end
49
41
  end
50
42
  end
@@ -103,6 +103,12 @@ module Vedeu
103
103
  end
104
104
  end
105
105
 
106
+ describe '.clear_line' do
107
+ subject { described_class.clear_line }
108
+
109
+ it { skip }
110
+ end
111
+
106
112
  describe '.show_cursor' do
107
113
  before { console.stubs(:puts) }
108
114
 
@@ -131,6 +137,18 @@ module Vedeu
131
137
  end
132
138
  end
133
139
 
140
+ describe '#initialize' do
141
+ subject { described_class.new }
142
+
143
+ it { skip }
144
+ end
145
+
146
+ describe '#open' do
147
+ subject { described_class.new.open }
148
+
149
+ it { skip }
150
+ end
151
+
134
152
  describe '#initial_setup!' do
135
153
  subject { described_class.new.initial_setup! }
136
154
 
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.5
4
+ version: 0.0.6
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-05-21 00:00:00.000000000 Z
11
+ date: 2014-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -170,7 +170,6 @@ files:
170
170
  - lib/vedeu/process/command.rb
171
171
  - lib/vedeu/process/commands.rb
172
172
  - lib/vedeu/process/exit.rb
173
- - lib/vedeu/process/process.rb
174
173
  - lib/vedeu/support/terminal.rb
175
174
  - lib/vedeu/version.rb
176
175
  - test/lib/vedeu/application_test.rb
@@ -190,7 +189,6 @@ files:
190
189
  - test/lib/vedeu/process/command_test.rb
191
190
  - test/lib/vedeu/process/commands_test.rb
192
191
  - test/lib/vedeu/process/exit_test.rb
193
- - test/lib/vedeu/process/process_test.rb
194
192
  - test/lib/vedeu/support/terminal_test.rb
195
193
  - test/lib/vedeu/version_test.rb
196
194
  - test/support/test_app/bin/testapp
@@ -238,7 +236,6 @@ test_files:
238
236
  - test/lib/vedeu/process/command_test.rb
239
237
  - test/lib/vedeu/process/commands_test.rb
240
238
  - test/lib/vedeu/process/exit_test.rb
241
- - test/lib/vedeu/process/process_test.rb
242
239
  - test/lib/vedeu/support/terminal_test.rb
243
240
  - test/lib/vedeu/version_test.rb
244
241
  - test/support/test_app/bin/testapp
@@ -1,33 +0,0 @@
1
- module Vedeu
2
- class Process
3
- class << self
4
- def main_sequence(interfaces = nil)
5
- new(interfaces).main_sequence
6
- end
7
- end
8
-
9
- def initialize(interfaces = nil)
10
- @interfaces = interfaces
11
- end
12
-
13
- def main_sequence
14
- initial_state
15
-
16
- event_loop
17
- end
18
-
19
- private
20
-
21
- def event_loop
22
- interfaces.event_loop
23
- end
24
-
25
- def initial_state
26
- interfaces.initial_state
27
- end
28
-
29
- def interfaces
30
- @interfaces ||= Interfaces.default
31
- end
32
- end
33
- end
@@ -1,10 +0,0 @@
1
- require_relative '../../../test_helper'
2
-
3
- module Vedeu
4
- describe Process do
5
- let(:described_class) { Process }
6
- let(:instance) { described_class.new }
7
-
8
- it { instance.must_be_instance_of(Process) }
9
- end
10
- end