vedeu 0.0.8 → 0.0.9

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: f52154b63c5d3fdf54cecda5b7937e995c505901
4
- data.tar.gz: 65d02119eee86d923a1ab265260767ae2e475743
3
+ metadata.gz: b55b3f6827a2162d61c3ba3893197cee7990149d
4
+ data.tar.gz: 98cc092488b3d8b9982168d967339209736de888
5
5
  SHA512:
6
- metadata.gz: 77cab7109821b024cb2ffd7bfe4d705a6df42ced0b17f0c3805b9e183516ac0070bd5ed85eb3e5899ffdf83ea7d2eb054b6472a222b5afb2ac3f70c3edb82b47
7
- data.tar.gz: fc489cc11f1671cfd6efff9df4d0b333c46da375f93f4bb3f9073f7ac5d45d5818008911d61c13907ef06df0b10fd4f6216a256e7cf48912f39aac1afec0f7ad
6
+ metadata.gz: 8bb473799314f117db0eb91f879954e319497e998dd561e173d53b5831706222eef7f6074543fe7516876bb813bc89e40d6dcc2b5a0624d86f8df497b1e84b91
7
+ data.tar.gz: 26f9a8f0072eee4c6639243de7eb2c57a8fa1a3807295cda06dc42f7d0338e53cd81bfe444e73dc13706565780990f695a1f842061650a340a310dbaf2c5bd36
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')
3
+
4
+ -> { its -> { a } }
5
+ trap('INT') { exit! }
6
+
7
+ require 'vedeu'
8
+ print Vedeu::Esc.clear
9
+
10
+ geometry = {
11
+ geometry: {
12
+ y: 2,
13
+ x: 2,
14
+ width: 20,
15
+ height: 10
16
+ }
17
+ }
18
+ interface = Vedeu::Interface.new(geometry)
19
+ Vedeu::Renderer.new(interface).clear_interface_rows
20
+
21
+ geometry = {
22
+ geometry: {
23
+ y: 2,
24
+ x: 23,
25
+ width: 20,
26
+ height: 10
27
+ }
28
+ }
29
+ interface = Vedeu::Interface.new(geometry)
30
+ Vedeu::Renderer.new(interface).clear_interface_rows
31
+
32
+ geometry = {
33
+ geometry: {
34
+ y: 2,
35
+ x: 44,
36
+ width: 20,
37
+ height: 10
38
+ }
39
+ }
40
+ interface = Vedeu::Interface.new(geometry)
41
+ Vedeu::Renderer.new(interface).clear_interface_rows
42
+
43
+ print Vedeu::Esc.reset
44
+ print Vedeu::Position.reset
data/examples/3_lines ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')
3
+
4
+ -> { its -> { a } }
5
+ trap('INT') { exit! }
6
+
7
+ require 'vedeu'
8
+ print Vedeu::Esc.clear
9
+
10
+ geometry = {
11
+ geometry: {
12
+ y: 2,
13
+ x: 2,
14
+ width: 20,
15
+ height: 10
16
+ }
17
+ }
18
+ interface = Vedeu::Interface.new(geometry)
19
+
20
+ Vedeu::Renderer.new(interface).write
21
+
22
+ print Vedeu::Esc.reset
23
+ print Vedeu::Position.reset
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')
3
+
4
+ -> { its -> { a } }
5
+ trap('INT') { exit! }
6
+
7
+ require 'vedeu'
8
+
9
+ # stream = [
10
+ # [
11
+ # [
12
+ # [],
13
+ # 'Lorem ipsum dolor sit amet, consectetur adipiscing'
14
+ # ],[
15
+ # [],
16
+ # 'elit. Cras sed ipsum ut purus imperdiet molestie'
17
+ # ],[
18
+ # [],
19
+ # 'in id neque. Sed auctor venenatis ultrices. Morbi'
20
+ # ],[
21
+ # [],
22
+ # 'ullamcorper libero et euismod malesuada. Aliquam'
23
+ # ],[
24
+ # [],
25
+ # 'dignissim metus eget tellus condimentum, ac dictum'
26
+ # ],[
27
+ # [],
28
+ # 'enim posuere. Curabitur posuere arcu elementum'
29
+ # ],[
30
+ # [],
31
+ # 'rutrum pulvinar. Nullam et dui eu lectus'
32
+ # ],[
33
+ # [],
34
+ # 'sollicitudin hendrerit eu at nibh. Cum sociis.'
35
+ # ]
36
+ # ]
37
+ # ]
38
+
39
+ stream = [
40
+ [
41
+ [[:underline, "test1"],
42
+ [[[:red, :black]], "test2"],
43
+ [[], "test3"]
44
+ ]
45
+ ]
46
+
47
+ geometry = { geometry: { y: 0, x: 0, width: 50, height: 15 } }
48
+ interface = Vedeu::Interface.new(geometry)
49
+
50
+ Vedeu::Compositor.write(stream, interface)
51
+
52
+ print "\n"
data/lib/vedeu.rb CHANGED
@@ -22,6 +22,7 @@ require_relative 'vedeu/interface/dummy'
22
22
 
23
23
  require_relative 'vedeu/process/commands'
24
24
  require_relative 'vedeu/process/command'
25
+ require_relative 'vedeu/process/event_loop'
25
26
  require_relative 'vedeu/process/exit'
26
27
 
27
28
  require_relative 'vedeu/application'
@@ -12,9 +12,9 @@ module Vedeu
12
12
 
13
13
  def main_sequence
14
14
  Terminal.open(options) do
15
- initial_state
15
+ Interfaces.initial_state
16
16
 
17
- event_loop
17
+ EventLoop.start
18
18
  end
19
19
  ensure
20
20
  Terminal.close
@@ -24,18 +24,6 @@ module Vedeu
24
24
 
25
25
  attr_reader :options
26
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
38
-
39
27
  def options
40
28
  defaults.merge!(@options)
41
29
  end
@@ -1,22 +1,14 @@
1
1
  module Vedeu
2
2
  class Dummy < Interface
3
- def initial_state; end
4
-
5
- # def input; end
6
-
7
- # def output; end
3
+ def initial_state
4
+ end
8
5
 
9
- private
6
+ def input
7
+ super
8
+ end
10
9
 
11
- def options
12
- {
13
- geometry: {
14
- y: 1,
15
- x: 1,
16
- width: :auto,
17
- height: :auto
18
- }
19
- }
10
+ def output
11
+ super
20
12
  end
21
13
  end
22
14
  end
@@ -10,16 +10,6 @@ module Vedeu
10
10
  raise NotImplementedError, 'Subclasses implement this method.'
11
11
  end
12
12
 
13
- def event_loop
14
- while true do
15
- command = input
16
-
17
- break if command == :stop
18
-
19
- output(command)
20
- end
21
- end
22
-
23
13
  def input
24
14
  evaluate
25
15
  end
@@ -50,7 +40,12 @@ module Vedeu
50
40
 
51
41
  def defaults
52
42
  {
53
- geometry: {}
43
+ geometry: {
44
+ y: 1,
45
+ x: 1,
46
+ width: :auto,
47
+ height: :auto
48
+ }
54
49
  }
55
50
  end
56
51
  end
@@ -14,30 +14,28 @@ module Vedeu
14
14
  end
15
15
 
16
16
  def defined
17
- interfaces.empty? ? nil : self
18
- end
19
-
20
- def default
21
- add(:dummy, Dummy)
17
+ interfaces.empty? ? default : self
22
18
  end
23
19
 
24
20
  def list
25
21
  interfaces.inspect
26
22
  end
27
23
 
28
- def add(name, klass, options = {})
29
- if valid?(klass)
30
- interfaces[name] = Proc.new { klass.new(options) }
31
- self
32
- end
24
+ def add(name, options = {}, klass = Dummy)
25
+ interfaces[name] = klass.new(options) if valid?(klass)
26
+ self
33
27
  end
34
28
 
35
29
  def initial_state
36
- interfaces.values.map { |io| io.call.initial_state }
30
+ interfaces.values.map { |io| io.initial_state }
37
31
  end
38
32
 
39
- def event_loop
40
- interfaces.values.map { |io| io.call.event_loop }
33
+ def input
34
+ interfaces.values.map { |io| io.input }
35
+ end
36
+
37
+ def output(stream)
38
+ interfaces.values.map { |io| io.output(stream) }
41
39
  end
42
40
 
43
41
  private
@@ -47,6 +45,12 @@ module Vedeu
47
45
  true
48
46
  end
49
47
 
48
+ def default
49
+ add(:dummy)
50
+
51
+ self
52
+ end
53
+
50
54
  def interfaces
51
55
  @interfaces ||= {}
52
56
  end
@@ -18,7 +18,7 @@ module Vedeu
18
18
 
19
19
  private
20
20
 
21
- attr_reader :output, :interface
21
+ attr_reader :interface
22
22
 
23
23
  def composition
24
24
  container = []
@@ -26,12 +26,7 @@ module Vedeu
26
26
  output.map do |line|
27
27
  line.each_with_index do |stream, index|
28
28
  streams << clear_line(index)
29
-
30
- if stream.is_a?(String)
31
- streams << stream
32
- else
33
- streams << Directive.enact(stream)
34
- end
29
+ streams << Directive.enact(stream)
35
30
  end
36
31
  container << streams.join
37
32
  streams = []
@@ -40,7 +35,7 @@ module Vedeu
40
35
  end
41
36
 
42
37
  def clear_line(index)
43
- [position(vy(index), vx), (" " * width), position(vy(index), vx)].join
38
+ [position(vy(index), vx), (' ' * width), position(vy(index), vx)].join
44
39
  end
45
40
 
46
41
  def vx(index = 0)
@@ -62,5 +57,10 @@ module Vedeu
62
57
  def position(y, x)
63
58
  Position.set(y, x)
64
59
  end
60
+
61
+ def output
62
+ return @output.split if @output.is_a?(String)
63
+ @output
64
+ end
65
65
  end
66
66
  end
@@ -13,6 +13,7 @@ module Vedeu
13
13
  end
14
14
 
15
15
  def enact
16
+ return directives if string?
16
17
  [set_position, set_colour, set_style].join
17
18
  end
18
19
 
@@ -20,6 +21,10 @@ module Vedeu
20
21
 
21
22
  attr_reader :directives
22
23
 
24
+ def string?
25
+ directives.is_a?(String)
26
+ end
27
+
23
28
  def set_position
24
29
  Position.set(*position)
25
30
  end
@@ -29,7 +29,7 @@ module Vedeu
29
29
  end
30
30
 
31
31
  def commands
32
- @commands ||= { 'exit' => Proc.new { Exit.dispatch } }
32
+ @commands ||= { :exit => Proc.new { Exit.dispatch } }
33
33
  end
34
34
  end
35
35
  end
@@ -0,0 +1,31 @@
1
+ module Vedeu
2
+ class EventLoop
3
+ class << self
4
+ def start
5
+ new.start
6
+ end
7
+ end
8
+
9
+ def initialize
10
+ @running = true
11
+ end
12
+
13
+ def start
14
+ tick
15
+ end
16
+
17
+ def stop
18
+ @running = false
19
+ end
20
+
21
+ def tick
22
+ while @running do
23
+ command = Interfaces.defined.input
24
+
25
+ stop if command == "stop"
26
+
27
+ Interfaces.defined.output(command)
28
+ end
29
+ end
30
+ end
31
+ end
data/lib/vedeu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vedeu
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -9,14 +9,13 @@ module Vedeu
9
9
  it { described_instance.must_be_instance_of(Application) }
10
10
 
11
11
  describe '.start' do
12
- let(:subject) { described_class.start(options) }
13
- let(:interfaces) { mock("Interfaces", event_loop: nil,
14
- initial_state: nil) }
12
+ let(:subject) { described_class.start(options) }
15
13
 
16
14
  before do
17
15
  Terminal.stubs(:open).yields(self)
16
+ Interfaces.stubs(:initial_state)
17
+ EventLoop.stubs(:start)
18
18
  Terminal.stubs(:close)
19
- Interfaces.stubs(:defined).returns(interfaces)
20
19
  end
21
20
 
22
21
  it { subject.must_be_instance_of(NilClass) }
@@ -14,12 +14,6 @@ module Vedeu
14
14
  it { proc { subject }.must_raise(NotImplementedError) }
15
15
  end
16
16
 
17
- describe '#event_loop' do
18
- let(:subject) { described_instance.event_loop }
19
-
20
- it { skip }
21
- end
22
-
23
17
  describe '#input' do
24
18
  let(:subject) { described_instance.input }
25
19
 
@@ -14,6 +14,12 @@ module Vedeu
14
14
  let(:subject) { described_class.define }
15
15
 
16
16
  it { subject.must_be_instance_of(Module) }
17
+
18
+ context 'when a block is given' do
19
+ let(:subject) { described_class.define { :some_block } }
20
+
21
+ it { subject.must_be_instance_of(Symbol) }
22
+ end
17
23
  end
18
24
 
19
25
  describe '.defined' do
@@ -24,28 +30,20 @@ module Vedeu
24
30
  context 'when interfaces are not defined' do
25
31
  before { described_class.interfaces = {} }
26
32
 
27
- it { subject.must_be_instance_of(NilClass) }
33
+ it 'adds the default interface and returns all interfaces' do
34
+ subject.must_be_instance_of(Module)
35
+ end
28
36
  end
29
37
 
30
- context 'when no interfaces are defined' do
38
+ context 'when interfaces are defined' do
31
39
  before { described_class.interfaces = { mock: :interface } }
32
40
 
33
41
  it { subject.must_be_instance_of(Module) }
34
42
  end
35
43
  end
36
44
 
37
- describe '.default' do
38
- let(:subject) { described_class.default }
39
-
40
- it { subject.must_be_instance_of(Module) }
41
-
42
- it 'adds the dummy interface to the interface list' do
43
- described_class.list.wont_be_empty
44
- end
45
- end
46
-
47
45
  describe '.add' do
48
- let(:subject) { described_class.add(interface, klass, options) }
46
+ let(:subject) { described_class.add(interface, options, klass) }
49
47
  let(:interface) {}
50
48
  let(:klass) { DummyInterface }
51
49
  let(:options) { {} }
@@ -70,16 +68,5 @@ module Vedeu
70
68
 
71
69
  it { subject.must_be_instance_of(Array) }
72
70
  end
73
-
74
- describe '.event_loop' do
75
- let(:subject) { described_class.event_loop }
76
-
77
- before do
78
- Terminal.stubs(:input)
79
- Commands.stubs(:execute).returns(:stop)
80
- end
81
-
82
- it { subject.must_be_instance_of(Array) }
83
- end
84
71
  end
85
72
  end
@@ -35,7 +35,7 @@ module Vedeu
35
35
  end
36
36
 
37
37
  context 'when the command exists' do
38
- let(:command) { 'exit' }
38
+ let(:command) { :exit }
39
39
 
40
40
  before { Exit.stubs(:dispatch).returns(true) }
41
41
 
@@ -51,7 +51,7 @@ module Vedeu
51
51
 
52
52
  describe '.add' do
53
53
  let(:subject) { described_class.add(command_name, command_klass, args, options) }
54
- let(:command_name) { "some_name" }
54
+ let(:command_name) { :some_name }
55
55
  let(:command_klass) { DummyCommand }
56
56
  let(:args) { [] }
57
57
  let(:options) { {} }
@@ -0,0 +1,20 @@
1
+ require_relative '../../../test_helper'
2
+
3
+ module Vedeu
4
+ describe EventLoop do
5
+ let(:described_class) { EventLoop }
6
+ let(:defined) { mock }
7
+
8
+ before do
9
+ Interfaces.stubs(:defined).returns(defined)
10
+ defined.stubs(:input).returns("stop")
11
+ defined.stubs(:output).returns(NilClass)
12
+ end
13
+
14
+ describe '.start' do
15
+ let(:subject) { described_class.start }
16
+
17
+ it { subject.must_be_instance_of(NilClass) }
18
+ end
19
+ end
20
+ 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.8
4
+ version: 0.0.9
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-25 00:00:00.000000000 Z
11
+ date: 2014-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -152,6 +152,9 @@ files:
152
152
  - README.md
153
153
  - Rakefile
154
154
  - bin/vedeu
155
+ - examples/3_interfaces
156
+ - examples/3_lines
157
+ - examples/composition
155
158
  - lib/vedeu.rb
156
159
  - lib/vedeu/application.rb
157
160
  - lib/vedeu/interface/dummy.rb
@@ -172,6 +175,7 @@ files:
172
175
  - lib/vedeu/output/wordwrap.rb
173
176
  - lib/vedeu/process/command.rb
174
177
  - lib/vedeu/process/commands.rb
178
+ - lib/vedeu/process/event_loop.rb
175
179
  - lib/vedeu/process/exit.rb
176
180
  - lib/vedeu/support/terminal.rb
177
181
  - lib/vedeu/version.rb
@@ -194,6 +198,7 @@ files:
194
198
  - test/lib/vedeu/output/wordwrap_test.rb
195
199
  - test/lib/vedeu/process/command_test.rb
196
200
  - test/lib/vedeu/process/commands_test.rb
201
+ - test/lib/vedeu/process/event_loop_test.rb
197
202
  - test/lib/vedeu/process/exit_test.rb
198
203
  - test/lib/vedeu/support/terminal_test.rb
199
204
  - test/lib/vedeu/version_test.rb
@@ -243,7 +248,9 @@ test_files:
243
248
  - test/lib/vedeu/output/wordwrap_test.rb
244
249
  - test/lib/vedeu/process/command_test.rb
245
250
  - test/lib/vedeu/process/commands_test.rb
251
+ - test/lib/vedeu/process/event_loop_test.rb
246
252
  - test/lib/vedeu/process/exit_test.rb
247
253
  - test/lib/vedeu/support/terminal_test.rb
248
254
  - test/lib/vedeu/version_test.rb
249
255
  - test/test_helper.rb
256
+ has_rdoc: