vedeu 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/Gemfile +0 -1
  4. data/Guardfile +0 -8
  5. data/README.md +33 -1
  6. data/Rakefile +0 -8
  7. data/bin/vedeu +9 -0
  8. data/lib/vedeu.rb +23 -6
  9. data/lib/vedeu/application.rb +47 -0
  10. data/lib/vedeu/interface/interface.rb +37 -0
  11. data/lib/vedeu/interface/interfaces.rb +49 -0
  12. data/lib/vedeu/output/background.rb +23 -0
  13. data/lib/vedeu/output/base.rb +49 -0
  14. data/lib/vedeu/output/colour.rb +30 -0
  15. data/lib/vedeu/output/compositor.rb +60 -0
  16. data/lib/vedeu/output/directive.rb +34 -0
  17. data/lib/vedeu/output/esc.rb +37 -0
  18. data/lib/vedeu/output/foreground.rb +23 -0
  19. data/lib/vedeu/output/position.rb +22 -0
  20. data/lib/vedeu/output/style.rb +32 -0
  21. data/lib/vedeu/output/translator.rb +62 -0
  22. data/lib/vedeu/process/command.rb +51 -0
  23. data/lib/vedeu/process/commands.rb +58 -0
  24. data/lib/vedeu/process/process.rb +31 -0
  25. data/lib/vedeu/support/terminal.rb +139 -0
  26. data/lib/vedeu/version.rb +1 -1
  27. data/test/lib/vedeu/application_test.rb +18 -0
  28. data/test/lib/vedeu/interface/interface_test.rb +76 -0
  29. data/test/lib/vedeu/interface/interfaces_test.rb +63 -0
  30. data/test/lib/vedeu/output/background_test.rb +10 -0
  31. data/test/lib/vedeu/output/base_test.rb +10 -0
  32. data/test/lib/vedeu/output/colour_test.rb +67 -0
  33. data/test/lib/vedeu/output/compositor_test.rb +106 -0
  34. data/test/lib/vedeu/output/directive_test.rb +55 -0
  35. data/test/lib/vedeu/output/esc_test.rb +71 -0
  36. data/test/lib/vedeu/output/foreground_test.rb +10 -0
  37. data/test/lib/vedeu/output/position_test.rb +33 -0
  38. data/test/lib/vedeu/output/style_test.rb +59 -0
  39. data/test/lib/vedeu/output/translator_test.rb +52 -0
  40. data/test/lib/vedeu/process/command_test.rb +54 -0
  41. data/test/lib/vedeu/process/commands_test.rb +62 -0
  42. data/test/lib/vedeu/process/process_test.rb +11 -0
  43. data/test/lib/vedeu/support/terminal_test.rb +140 -0
  44. data/test/lib/vedeu/version_test.rb +9 -0
  45. data/test/support/test_app/bin/testapp +32 -0
  46. data/test/test_helper.rb +4 -0
  47. data/vedeu.gemspec +0 -6
  48. metadata +60 -99
  49. data/.rubocop.yml +0 -2
  50. data/features/.gitkeep +0 -0
  51. data/lib/vedeu/buffer.rb +0 -106
  52. data/lib/vedeu/colour.rb +0 -98
  53. data/lib/vedeu/terminal.rb +0 -25
  54. data/test/lib/vedeu/buffer_test.rb +0 -114
  55. data/test/lib/vedeu/colour_test.rb +0 -57
  56. data/test/lib/vedeu/terminal_test.rb +0 -30
@@ -0,0 +1,10 @@
1
+ require_relative '../../../test_helper'
2
+
3
+ module Vedeu
4
+ describe Foreground do
5
+ let(:described_class) { Foreground }
6
+ let(:instance) { described_class.new }
7
+
8
+ it { instance.must_be_instance_of(Foreground) }
9
+ end
10
+ end
@@ -0,0 +1,33 @@
1
+ require_relative '../../../test_helper'
2
+
3
+ module Vedeu
4
+ describe Position do
5
+ let(:described_class) { Position }
6
+ let(:instance) { described_class.new }
7
+
8
+ it { instance.must_be_instance_of(Position) }
9
+
10
+ describe '.set' do
11
+ subject { described_class.set }
12
+
13
+ it { subject.must_be_instance_of(String) }
14
+
15
+ context 'when no coordinates are provided' do
16
+ it 'returns a position escape sequence' do
17
+ subject.must_equal("\e[1;1H")
18
+ end
19
+ end
20
+
21
+ context 'when coordinates are provided' do
22
+ let(:y) { 12 }
23
+ let(:x) { 19 }
24
+
25
+ subject { described_class.set(y, x) }
26
+
27
+ it 'returns a position escape sequence' do
28
+ subject.must_equal("\e[13;20H")
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,59 @@
1
+ require_relative '../../../test_helper'
2
+
3
+ module Vedeu
4
+ describe Style do
5
+ let(:described_class) { Style }
6
+
7
+ describe '.set' do
8
+ let(:style) {}
9
+
10
+ subject { described_class.set(style) }
11
+
12
+ it { subject.must_be_instance_of(String) }
13
+
14
+ it { subject.must_equal('') }
15
+
16
+ context 'when the style is bold' do
17
+ let(:style) { :bold }
18
+
19
+ it { subject.must_equal("\e[1m") }
20
+ end
21
+
22
+ context 'when the style is clear' do
23
+ let(:style) { :clear }
24
+
25
+ it { subject.must_equal("\e[2J") }
26
+ end
27
+
28
+ context 'when the style is hide_cursor' do
29
+ let(:style) { :hide_cursor }
30
+
31
+ it { subject.must_equal("\e[?25l") }
32
+ end
33
+
34
+ context 'when the style is inverse' do
35
+ let(:style) { :inverse }
36
+
37
+ it { subject.must_equal("\e[7m") }
38
+ end
39
+
40
+ context 'when the style is reset' do
41
+ let(:style) { :reset }
42
+
43
+ it { subject.must_equal("\e[0m") }
44
+ end
45
+
46
+ context 'when the style is show_cursor' do
47
+ let(:style) { :show_cursor }
48
+
49
+ it { subject.must_equal("\e[?25h") }
50
+ end
51
+
52
+ context 'when the style is underline' do
53
+ let(:style) { :underline }
54
+
55
+ it { subject.must_equal("\e[4m") }
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,52 @@
1
+ require_relative '../../../test_helper'
2
+
3
+ module Vedeu
4
+ describe Translator do
5
+ let(:described_class) { Translator }
6
+ let(:instance) { described_class.new(html_colour) }
7
+ let(:html_colour) {}
8
+
9
+ it { instance.must_be_instance_of(Translator) }
10
+
11
+ describe '#translate' do
12
+ {
13
+ '#ff0000' => 196, # red
14
+ '#00ff00' => 46, # green
15
+ '#0000ff' => 21, # blue
16
+ '#ffffff' => 231, # white
17
+ '#aadd00' => 148, # lime green
18
+ '#b94f1c' => 130, # sunset orange
19
+ }.map do |html_colour, terminal_colour|
20
+ context 'valid' do
21
+ it 'translation is performed' do
22
+ described_class.translate(html_colour).must_be_instance_of(Fixnum)
23
+
24
+ described_class.translate(html_colour).must_equal(terminal_colour)
25
+ end
26
+ end
27
+ end
28
+
29
+ context 'invalid' do
30
+ it 'returns nil when not present' do
31
+ described_class.translate.must_equal(nil)
32
+ end
33
+
34
+ it 'returns nil when the wrong type' do
35
+ described_class.translate(:wrong_type).must_equal(nil)
36
+ end
37
+
38
+ it 'returns nil when invalid format' do
39
+ described_class.translate('345678').must_equal(nil)
40
+ end
41
+
42
+ it 'returns nil when invalid format' do
43
+ described_class.translate('#h11111').must_equal(nil)
44
+ end
45
+
46
+ it 'returns nil when invalid format' do
47
+ described_class.translate('#1111').must_equal(nil)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,54 @@
1
+ require_relative '../../../test_helper'
2
+
3
+ module Vedeu
4
+ class DummyCommand
5
+ class << self
6
+ def dispatch; end
7
+ end
8
+ end
9
+
10
+ describe Command do
11
+ let(:described_class) { Command }
12
+ let(:instance) { described_class.new(cmd_name, cmd_klass, cmd_args, cmd_options) }
13
+ let(:cmd_name) { "dummy" }
14
+ let(:cmd_klass) { DummyCommand }
15
+ let(:cmd_args) { [] }
16
+ let(:cmd_options) { {} }
17
+
18
+ it { instance.must_be_instance_of(Command) }
19
+
20
+ describe '#define' do
21
+ subject do
22
+ described_class.define(cmd_name, cmd_klass, cmd_args, cmd_options)
23
+ end
24
+
25
+ it { subject.must_be_instance_of(Hash) }
26
+
27
+ it { subject.wont_be_empty }
28
+
29
+ context "when the command name is empty" do
30
+ let(:cmd_name) { "" }
31
+
32
+ it { proc { subject }.must_raise(InvalidCommand) }
33
+ end
34
+
35
+ context "when the command class is empty" do
36
+ let(:cmd_klass) { "" }
37
+
38
+ it { proc { subject }.must_raise(InvalidCommand) }
39
+ end
40
+
41
+ context "when the command class is not defined" do
42
+ before { Object.stubs(:const_defined?).returns(false) }
43
+
44
+ it { proc { subject }.must_raise(InvalidCommand) }
45
+ end
46
+
47
+ context "when the command class doesn't have a .dispatch method" do
48
+ before { cmd_klass.stubs(:singleton_methods).returns([]) }
49
+
50
+ it { proc { subject }.must_raise(InvalidCommand) }
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,62 @@
1
+ require_relative '../../../test_helper'
2
+
3
+ module Vedeu
4
+ class DummyCommandKlass
5
+ def self.dispatch; end
6
+ end
7
+
8
+ describe Commands do
9
+ let(:described_class) { Commands }
10
+ let(:instance) { described_class.instance }
11
+ let(:block) {}
12
+
13
+ it { instance.must_be_instance_of(Commands) }
14
+
15
+ describe '.execute' do
16
+ subject { described_class.execute }
17
+
18
+ it { skip }
19
+ end
20
+
21
+ describe '.list' do
22
+ subject { described_class.list }
23
+
24
+ it { subject.must_be_instance_of(String) }
25
+ end
26
+
27
+ describe '#define' do
28
+ let(:command_name) { "some_name" }
29
+ let(:command_klass) { DummyCommandKlass }
30
+ let(:args) { [] }
31
+ let(:options) { {} }
32
+
33
+ subject { instance.define(command_name, command_klass, args, options) }
34
+
35
+ it { subject.must_be_instance_of(Hash) }
36
+ 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
+ end
50
+
51
+ describe Exit do
52
+ let(:described_class) { Exit }
53
+
54
+ describe '.dispatch' do
55
+ subject { described_class.dispatch }
56
+
57
+ it { subject.must_be_instance_of(Symbol) }
58
+
59
+ it { subject.must_equal(:stop) }
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,11 @@
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
+ let(:block) {}
8
+
9
+ it { instance.must_be_instance_of(Process) }
10
+ end
11
+ end
@@ -0,0 +1,140 @@
1
+ require_relative '../../../test_helper'
2
+
3
+ module Vedeu
4
+ describe Terminal do
5
+ let(:described_class) { Terminal }
6
+ let(:console) { stub }
7
+
8
+ before do
9
+ IO.stubs(:console).returns(console)
10
+ console.stubs(:winsize).returns([25, 80])
11
+ end
12
+
13
+ describe '.input' do
14
+ before { console.stubs(:gets).returns("test") }
15
+
16
+ subject { described_class.input }
17
+
18
+ it { subject.must_be_instance_of(String) }
19
+ end
20
+
21
+ describe '.output' do
22
+ before { console.stubs(:puts).returns("test") }
23
+
24
+ subject { described_class.output }
25
+
26
+ it { subject.must_be_instance_of(String) }
27
+ end
28
+
29
+ describe '.width' do
30
+ subject { described_class.width }
31
+
32
+ it { subject.must_be_instance_of(Fixnum) }
33
+
34
+ it 'returns the width of the terminal' do
35
+ subject.must_equal(80)
36
+ end
37
+ end
38
+
39
+ describe '.height' do
40
+ subject { described_class.height }
41
+
42
+ it { subject.must_be_instance_of(Fixnum) }
43
+
44
+ it 'returns the height of the terminal' do
45
+ subject.must_equal(25)
46
+ end
47
+ end
48
+
49
+ describe '.size' do
50
+ subject { described_class.size }
51
+
52
+ it { subject.must_be_instance_of(Array) }
53
+
54
+ it 'returns the width and height of the terminal' do
55
+ subject.must_equal([25, 80])
56
+ end
57
+ end
58
+
59
+ describe '.open' do
60
+ subject { described_class.open }
61
+
62
+ it { skip }
63
+ end
64
+
65
+ describe '.close' do
66
+ subject { described_class.close }
67
+
68
+ it { skip }
69
+ end
70
+
71
+ describe '.cooked' do
72
+ subject { described_class.cooked }
73
+
74
+ it { skip }
75
+ end
76
+
77
+ describe '.raw' do
78
+ subject { described_class.raw }
79
+
80
+ it { skip }
81
+ end
82
+
83
+ describe '.console' do
84
+ subject { described_class.console }
85
+
86
+ it { skip }
87
+ end
88
+
89
+ describe '.clear_screen' do
90
+ before do
91
+ Esc.stubs(:clear).returns('')
92
+ console.stubs(:puts)
93
+ end
94
+
95
+ subject { described_class.clear_screen }
96
+
97
+ it { subject.must_be_instance_of(NilClass) }
98
+
99
+ context 'capturing output' do
100
+ let(:io) { capture_io { subject }.join }
101
+
102
+ it { io.must_be_instance_of(String) }
103
+ end
104
+ end
105
+
106
+ describe '.show_cursor' do
107
+ before { console.stubs(:puts) }
108
+
109
+ subject { described_class.show_cursor }
110
+
111
+ it { subject.must_be_instance_of(NilClass) }
112
+
113
+ context 'capturing output' do
114
+ let(:io) { capture_io { subject }.join }
115
+
116
+ it { io.must_be_instance_of(String) }
117
+ end
118
+ end
119
+
120
+ describe '.hide_cursor' do
121
+ before { console.stubs(:puts) }
122
+
123
+ subject { described_class.hide_cursor }
124
+
125
+ it { subject.must_be_instance_of(NilClass) }
126
+
127
+ context 'capturing output' do
128
+ let(:io) { capture_io { subject }.join }
129
+
130
+ it { io.must_be_instance_of(String) }
131
+ end
132
+ end
133
+
134
+ describe '#initial_setup!' do
135
+ subject { described_class.new.initial_setup! }
136
+
137
+ it { skip }
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,9 @@
1
+ require_relative '../../test_helper'
2
+
3
+ module Vedeu
4
+ describe VERSION do
5
+ let(:described_class) { VERSION }
6
+
7
+ it { described_class.must_be_instance_of(String) }
8
+ end
9
+ end
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ -> { its -> { a } }
4
+ trap('INT') { exit! }
5
+
6
+ require_relative '../../../../lib/vedeu'
7
+
8
+ # define an interface
9
+ # Vedeu::Interfaces.define do |interface|
10
+ # interface.add("", ...)
11
+ # end
12
+
13
+ class Fake
14
+ def self.dispatch
15
+ puts "Fake dispatched..."
16
+ [
17
+ [[:white, :red], "Fake executed...", :reset],
18
+ [[:white, :green], "Test executed...", :reset],
19
+ ]
20
+ end
21
+ end
22
+
23
+ # use default interface
24
+ Vedeu::Interfaces.default
25
+
26
+ # define some commands
27
+ Vedeu::Commands.define do |command|
28
+ command.add("test", Fake)
29
+ end
30
+
31
+ # create main loop
32
+ Vedeu::Application.start