vedeu 0.0.23 → 0.0.24

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -96
  3. data/lib/vedeu.rb +1 -2
  4. data/lib/vedeu/launcher.rb +2 -0
  5. data/lib/vedeu/output/buffer/composition.rb +15 -0
  6. data/lib/vedeu/output/buffer/formatting.rb +6 -10
  7. data/lib/vedeu/output/buffer/line.rb +1 -1
  8. data/lib/vedeu/output/wordwrap.rb +8 -6
  9. data/lib/vedeu/repository/command.rb +6 -9
  10. data/lib/vedeu/repository/command_repository.rb +5 -6
  11. data/lib/vedeu/repository/interface.rb +2 -0
  12. data/lib/vedeu/support/event_loop.rb +2 -0
  13. data/lib/vedeu/support/json_parser.rb +25 -0
  14. data/lib/vedeu/support/terminal.rb +4 -0
  15. data/lib/vedeu/version.rb +1 -1
  16. data/test/lib/vedeu/output/buffer/composition_test.rb +38 -1
  17. data/test/lib/vedeu/output/buffer/formatting_test.rb +9 -0
  18. data/test/lib/vedeu/output/buffer/interface_test.rb +14 -0
  19. data/test/lib/vedeu/output/buffer/line_test.rb +25 -0
  20. data/test/lib/vedeu/output/buffer/stream_test.rb +22 -0
  21. data/test/lib/vedeu/output/compositor_test.rb +5 -5
  22. data/test/lib/vedeu/output/output_test.rb +1 -1
  23. data/test/lib/vedeu/output/wordwrap_test.rb +5 -1
  24. data/test/lib/vedeu/repository/command_repository_test.rb +12 -14
  25. data/test/lib/vedeu/repository/command_test.rb +21 -15
  26. data/test/lib/vedeu/support/json_parser_test.rb +46 -0
  27. data/test/support/multi_interface.json +34 -0
  28. data/test/support/single_interface.json +19 -0
  29. metadata +11 -8
  30. data/lib/vedeu/output/buffer/parser.rb +0 -28
  31. data/lib/vedeu/output/colour_pair.rb +0 -43
  32. data/test/lib/vedeu/output/buffer/parser_test.rb +0 -58
  33. data/test/lib/vedeu/output/colour_pair_test.rb +0 -104
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce06977605476701c2ac6f998a0af92fd38d5206
4
- data.tar.gz: 5a72b5086a86d4af8871d7318e07bce64fca2af7
3
+ metadata.gz: 046d21e705590582e93e96ebd7be2301265256ea
4
+ data.tar.gz: 0582a4583fb725376874b6b41c1d1508df473a35
5
5
  SHA512:
6
- metadata.gz: 8363bd8ce4582edc87027a0ab688d1f8b97f50e0e25f328f59f6ceebe7ef016022fc9893bfd091652252615f1da1a7daecaa9c373a094b0c1f12296220ab8552
7
- data.tar.gz: 1d1f967155fa6c2f747203703a2cb4aaa48934ad4926a6a6f5b2b27b89321b2b3b7776e6a16e92ea59fe09f5644728736d02450ca72da58a54f8c4b6d07185ef
6
+ metadata.gz: dd1aba71fdd4b148133c76e5e8e3506ab3a60c98c4e9167e68e8ab47329e641762d34a7f2ec3f1191a28745a37dac5aa21a5e6052de152f186c4053ea10519fd
7
+ data.tar.gz: bc2fba75fb393c82a0b6ef51d62fd6c3e7614010a432259cd8bc18ba779c464f5341e1c0cc5b540cd052415551ef38547388c2c4c9e4d143104ca54a96fcb165
data/README.md CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  Vedeu is my attempt at creating a terminal based application framework without the need for Ncurses.
6
6
 
7
+
7
8
  ## Installation
8
9
 
9
10
  Add this line to your application's Gemfile:
@@ -16,103 +17,8 @@ And then execute:
16
17
 
17
18
  ## Usage
18
19
 
19
- TODO: Write detailed documentation
20
-
21
- ## Notes
22
-
23
- Launcher
24
- |-- Application
25
- |-- EventLoop
26
- | |-- Input
27
- | | |-- Queue
28
- | | |-- Terminal
29
- | |
30
- | |-- Process
31
- | | |-- CommandRepository
32
- | | |-- Queue
33
- | |
34
- | |-- Output
35
- | |-- Compositor
36
- | |
37
- | |-- Directive
38
- | | |-- Colour
39
- | | | |-- Background < Base
40
- | | | |-- Foreground < Base
41
- | | |
42
- | | |-- Position
43
- | | | |-- Esc
44
- | | |
45
- | | |-- Style
46
- | | | |-- Cursor
47
- | | | |-- Esc
48
- | | |
49
- | | |-- Wordwrap
50
- | |
51
- | |-- InterfaceRepository
52
- | |-- Position
53
- | |-- Esc
54
- |
55
- |-- InterfaceRepository
56
- |-- Terminal
57
-
58
- Base
59
- |-- Esc
60
- |-- Translator
61
-
62
- Command
63
- |-- CommandRepository
64
-
65
- Exit
66
-
67
- Interface
68
- |-- Colour
69
- | |-- Background < Base
70
- | |-- Foreground < Base
71
- |
72
- |-- Geometry
73
- | |-- Terminal
74
- |
75
- |-- InterfaceRepository
76
-
77
- Repository
78
- |-- Storage
79
-
80
- Terminal
81
- |-- Cursor
82
- |-- Esc
83
- |-- Position
84
- |-- Esc
85
-
86
- ### On Interfaces
87
-
88
- When we create the interface we define it's width, height, and origin (y, x).
89
- These numbers are based on the area available to the terminal. If the terminal is 80x25, then our interface can use all or some of this area.
90
-
91
- ### On Composition
92
-
93
- To compose data suitable for output in Vedeu, you can use this EBNF. Diagrams are available in the `documentation` directory.
94
-
95
- Output ::= (('{' (Interface '=>' Stream) '}' (',' | ))* | ('[' (Stream (',' | ))* ']' (',' | ))* | ('[' (String (',' | ))* ']') (',' | ))*
96
- Stream ::= ('[' (Directive (',' | ) | String (',' | ))* ']' (',' | ))*
97
- Interface ::= String
98
- Directive ::= PositionDirective | ColourDirective | StyleDirective
99
- PositionDirective ::= '[' Fixnum ',' Fixnum ']'
100
- StyleDirective ::= Symbol
101
- ColourDirective ::= '[' Symbol ',' Symbol ']'
102
-
103
- Diagrams were produced using the Railroad Diagram Generator at `http://bottlecaps.de/rr/ui`.
104
-
105
- ## Usage
106
-
107
- class MyApp
108
- include Vedeu
109
-
110
- interface 'status', { y: 1, x: 1, width: :auto, height: 1 }
111
- interface 'main', { y: 2, x: 1, width: :auto, height: :auto, fg: :red, bg: :black }
20
+ Expect documentation soon!
112
21
 
113
- command 'exit', Vedeu::Exit.dispatch, { keyword: "exit", keypress: "q" }
114
- command 'help', MyApp.help, { keyword: "help", keypress: "h" }
115
- end
116
22
 
117
23
  ## Contributing
118
24
 
data/lib/vedeu.rb CHANGED
@@ -8,10 +8,10 @@ require_relative 'vedeu/input/input'
8
8
 
9
9
  require_relative 'vedeu/support/event_loop'
10
10
  require_relative 'vedeu/support/exit'
11
+ require_relative 'vedeu/support/json_parser'
11
12
  require_relative 'vedeu/support/queue'
12
13
  require_relative 'vedeu/support/terminal'
13
14
 
14
- require_relative 'vedeu/output/buffer/parser'
15
15
  require_relative 'vedeu/output/buffer/style'
16
16
  require_relative 'vedeu/output/buffer/formatting'
17
17
  require_relative 'vedeu/output/buffer/stream'
@@ -29,7 +29,6 @@ require_relative 'vedeu/output/geometry'
29
29
  require_relative 'vedeu/output/layer'
30
30
  require_relative 'vedeu/output/esc'
31
31
  require_relative 'vedeu/output/colour'
32
- require_relative 'vedeu/output/colour_pair'
33
32
  require_relative 'vedeu/output/output'
34
33
  require_relative 'vedeu/output/position'
35
34
  require_relative 'vedeu/output/renderer'
@@ -12,6 +12,7 @@ module Vedeu
12
12
  @exit_code = 1
13
13
  end
14
14
 
15
+ # :nocov:
15
16
  def execute!
16
17
  $stdin, $stdout, $stderr = @stdin, @stdout, @stderr
17
18
 
@@ -22,5 +23,6 @@ module Vedeu
22
23
  $stdin, $stdout, $stderr = STDIN, STDOUT, STDERR
23
24
  @kernel.exit(@exit_code)
24
25
  end
26
+ # :nocov:
25
27
  end
26
28
  end
@@ -4,6 +4,21 @@ module Vedeu
4
4
  include Virtus.model
5
5
 
6
6
  attribute :interface, Array[Buffer::Interface]
7
+
8
+ def to_compositor
9
+ interface.inject({}) do |acc, interface|
10
+ acc[interface.name] = interface.to_compositor
11
+ acc
12
+ end
13
+ end
14
+
15
+ def to_hash
16
+ Oj.load(to_json)
17
+ end
18
+
19
+ def to_json
20
+ Oj.dump(attributes, mode: :compat, circular: true)
21
+ end
7
22
  end
8
23
  end
9
24
  end
@@ -10,19 +10,15 @@ module Vedeu
10
10
  private
11
11
 
12
12
  def colour
13
- if foreground && background
14
- [foreground, background]
15
- elsif foreground.nil? || background.nil?
16
- []
17
- end
13
+ return [] if foreground.nil? || background.nil?
14
+
15
+ [foreground, background]
18
16
  end
19
17
 
20
18
  def styles
21
- if style
22
- style
23
- elsif style.nil?
24
- []
25
- end
19
+ return [] if style.nil?
20
+
21
+ style
26
22
  end
27
23
  end
28
24
  end
@@ -4,7 +4,7 @@ module Vedeu
4
4
  include Virtus.model
5
5
  include Formatting
6
6
 
7
- attribute :stream, Array[Buffer::Stream]
7
+ attribute :stream, Array[Buffer::Stream]
8
8
 
9
9
  def to_compositor
10
10
  [{ style: styles, colour: colour }, *stream.map(&:to_compositor)]
@@ -51,12 +51,14 @@ module Vedeu
51
51
  end
52
52
 
53
53
  def pruned
54
- return value if value.size <= pruned_width
55
- [
56
- value.chomp.slice(0..pruned_width),
57
- '...',
58
- Esc.reset
59
- ].join
54
+ if value.size <= pruned_width
55
+ value
56
+ else
57
+ [
58
+ value.chomp.slice(0..pruned_width),
59
+ '...'
60
+ ].join
61
+ end
60
62
  end
61
63
 
62
64
  def pruned_width
@@ -1,21 +1,18 @@
1
1
  module Vedeu
2
2
  class Command
3
- attr_accessor :attributes, :name, :entity, :keyword, :keypress
3
+ include Virtus.model
4
4
 
5
- def initialize(attributes = {})
6
- @attributes = attributes || {}
7
- @name = attributes[:name]
8
- @entity = attributes[:entity]
9
- @keyword = attributes.fetch(:options, {}).fetch(:keyword, '')
10
- @keypress = attributes.fetch(:options, {}).fetch(:keypress, '')
11
- end
5
+ attribute :name, String
6
+ attribute :entity, Class
7
+ attribute :keyword, String, default: ''
8
+ attribute :keypress, String, default: ''
12
9
 
13
10
  def execute(args = [])
14
11
  executable.call(*args)
15
12
  end
16
13
 
17
14
  def executable
18
- proc { |*args| attributes[:entity].dispatch(*args) }
15
+ proc { |*args| entity.dispatch(*args) }
19
16
  end
20
17
  end
21
18
  end
@@ -22,13 +22,12 @@ module Vedeu
22
22
 
23
23
  # :nocov:
24
24
  module ClassMethods
25
- def command(name, entity, options = {})
26
- command_name = name.is_a?(Symbol) ? name.to_s : name
27
-
25
+ def command(name, entity, keypress = '', keyword = '')
28
26
  CommandRepository.create({
29
- name: command_name,
30
- entity: entity,
31
- options: options
27
+ name: name,
28
+ entity: entity,
29
+ keypress: keypress,
30
+ keyword: keyword
32
31
  })
33
32
  end
34
33
  end
@@ -11,6 +11,7 @@ module Vedeu
11
11
  @current = []
12
12
  end
13
13
 
14
+ # :nocov:
14
15
  def refresh
15
16
  if enqueued?
16
17
  @current = dequeue
@@ -22,6 +23,7 @@ module Vedeu
22
23
  @current
23
24
  end
24
25
  end
26
+ # :nocov:
25
27
 
26
28
  def geometry
27
29
  @geometry ||= Geometry.new(attributes)
@@ -12,6 +12,7 @@ module Vedeu
12
12
  @running = true
13
13
  end
14
14
 
15
+ # :nocov:
15
16
  def main_sequence
16
17
  while @running do
17
18
  Input.capture
@@ -23,6 +24,7 @@ module Vedeu
23
24
  rescue Collapse
24
25
  stop
25
26
  end
27
+ # :nocov:
26
28
 
27
29
  def stop
28
30
  @running = false
@@ -0,0 +1,25 @@
1
+ module Vedeu
2
+ class JSONParser
3
+ class << self
4
+ def parse(json = '')
5
+ new(json).parse
6
+ end
7
+ end
8
+
9
+ def initialize(json = '')
10
+ @json = json || ''
11
+ end
12
+
13
+ def parse
14
+ Buffer::Composition.new(as_hash)
15
+ end
16
+
17
+ private
18
+
19
+ attr_reader :json
20
+
21
+ def as_hash
22
+ Oj.load(json)
23
+ end
24
+ end
25
+ end
@@ -35,6 +35,7 @@ module Vedeu
35
35
  reset_position
36
36
  end
37
37
 
38
+ # :nocov:
38
39
  def cooked(instance, &block)
39
40
  console.cooked do
40
41
  instance.initial_setup!
@@ -52,6 +53,7 @@ module Vedeu
52
53
  end if block_given?
53
54
  end
54
55
  alias_method :open_raw, :raw
56
+ # :nocov:
55
57
 
56
58
  def console
57
59
  IO.console
@@ -101,6 +103,7 @@ module Vedeu
101
103
 
102
104
  private
103
105
 
106
+ # :nocov:
104
107
  def terminal_mode(&block)
105
108
  {
106
109
  cooked: proc { Terminal.cooked(self, &block) },
@@ -114,6 +117,7 @@ module Vedeu
114
117
  hide: proc { Terminal.hide_cursor }
115
118
  }
116
119
  end
120
+ # :nocov:
117
121
 
118
122
  def set_cursor
119
123
  cursor_mode.fetch(cursor).call
data/lib/vedeu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vedeu
2
- VERSION = '0.0.23'
2
+ VERSION = '0.0.24'
3
3
  end
@@ -6,7 +6,8 @@ module Vedeu
6
6
  let(:described_class) { Composition }
7
7
  let(:described_instance) { described_class.new(attributes) }
8
8
  let(:subject) { described_instance }
9
- let(:attributes) { { interface: [] } }
9
+ let(:json) { File.read(Vedeu.root_path + '/test/support/single_interface.json') }
10
+ let(:attributes) { Oj.load(json) }
10
11
 
11
12
  it 'returns a Composition instance' do
12
13
  subject.must_be_instance_of(Composition)
@@ -15,6 +16,42 @@ module Vedeu
15
16
  it 'has an interface attribute' do
16
17
  subject.interface.must_be_instance_of(Array)
17
18
  end
19
+
20
+ describe '#to_compositor' do
21
+ let(:subject) { described_instance.to_compositor }
22
+
23
+ it 'returns a Hash' do
24
+ subject.must_be_instance_of(Hash)
25
+ end
26
+
27
+ it 'returns the composition as a Compositor format' do
28
+ subject.must_equal({"dummy"=>[[{:style=>[], :colour=>[]}, {:style=>[:normal], :colour=>[:yellow, :black], :text=>"Some text..."}]]})
29
+ end
30
+ end
31
+
32
+ describe '#to_hash' do
33
+ let(:subject) { described_instance.to_hash }
34
+
35
+ it 'returns a Hash' do
36
+ subject.must_be_instance_of(Hash)
37
+ end
38
+
39
+ it 'returns the composition as a Hash' do
40
+ subject.must_equal({"interface"=>[{"name"=>"dummy", "line"=>[{"style"=>nil, "foreground"=>nil, "background"=>nil, "stream"=>[{"style"=>["normal"], "foreground"=>"yellow", "background"=>"black", "text"=>"Some text..."}]}]}]})
41
+ end
42
+ end
43
+
44
+ describe '#to_json' do
45
+ let(:subject) { described_instance.to_json }
46
+
47
+ it 'returns a String' do
48
+ subject.must_be_instance_of(String)
49
+ end
50
+
51
+ it 'returns a String' do
52
+ subject.must_equal("{\"interface\":[{\"name\":\"dummy\",\"line\":[{\"style\":null,\"foreground\":null,\"background\":null,\"stream\":[{\"style\":[\"normal\"],\"foreground\":\"yellow\",\"background\":\"black\",\"text\":\"Some text...\"}]}]}]}")
53
+ end
54
+ end
18
55
  end
19
56
  end
20
57
  end
@@ -0,0 +1,9 @@
1
+ require_relative '../../../../test_helper'
2
+
3
+ module Vedeu
4
+ module Buffer
5
+ describe Formatting do
6
+ let(:described_class) { Formatting }
7
+ end
8
+ end
9
+ end
@@ -14,10 +14,24 @@ module Vedeu
14
14
 
15
15
  it 'has a name attribute' do
16
16
  subject.name.must_be_instance_of(String)
17
+
18
+ subject.name.must_equal('dummy')
17
19
  end
18
20
 
19
21
  it 'has a line attribute' do
20
22
  subject.line.must_be_instance_of(Array)
23
+
24
+ subject.line.must_equal([])
25
+ end
26
+
27
+ describe '#to_compositor' do
28
+ let(:subject) { described_instance.to_compositor }
29
+
30
+ it 'returns an Array' do
31
+ subject.must_be_instance_of(Array)
32
+
33
+ subject.must_equal([])
34
+ end
21
35
  end
22
36
  end
23
37
  end
@@ -21,18 +21,43 @@ module Vedeu
21
21
 
22
22
  it 'has a style attribute' do
23
23
  subject.style.must_be_instance_of(Array)
24
+
25
+ subject.style.must_equal([:normal])
24
26
  end
25
27
 
26
28
  it 'has a foreground attribute' do
27
29
  subject.foreground.must_be_instance_of(Symbol)
30
+
31
+ subject.foreground.must_equal(:red)
28
32
  end
29
33
 
30
34
  it 'has a background attribute' do
31
35
  subject.background.must_be_instance_of(Symbol)
36
+
37
+ subject.background.must_equal(:black)
32
38
  end
33
39
 
34
40
  it 'has a stream attribute' do
35
41
  subject.stream.must_be_instance_of(Array)
42
+
43
+ subject.stream.must_equal([])
44
+ end
45
+
46
+ describe '#to_compositor' do
47
+ let(:subject) { described_instance.to_compositor }
48
+
49
+ it 'returns an Array' do
50
+ subject.must_be_instance_of(Array)
51
+
52
+ subject.must_equal(
53
+ [
54
+ {
55
+ style: [:normal],
56
+ colour: [:red, :black]
57
+ }
58
+ ]
59
+ )
60
+ end
36
61
  end
37
62
  end
38
63
  end
@@ -21,18 +21,40 @@ module Vedeu
21
21
 
22
22
  it 'has a foreground attribute' do
23
23
  subject.foreground.must_be_instance_of(Symbol)
24
+
25
+ subject.foreground.must_equal(:red)
24
26
  end
25
27
 
26
28
  it 'has a background attribute' do
27
29
  subject.background.must_be_instance_of(Symbol)
30
+
31
+ subject.background.must_equal(:black)
28
32
  end
29
33
 
30
34
  it 'has a text attribute' do
31
35
  subject.text.must_be_instance_of(String)
36
+
37
+ subject.text.must_equal('Some text')
32
38
  end
33
39
 
34
40
  it 'has a style attribute' do
35
41
  subject.style.must_be_instance_of(Array)
42
+
43
+ subject.style.must_equal([:normal])
44
+ end
45
+
46
+ describe '#to_compositor' do
47
+ let(:subject) { described_instance.to_compositor }
48
+
49
+ it 'returns a Hash' do
50
+ subject.must_be_instance_of(Hash)
51
+
52
+ subject.must_equal({
53
+ style: [:normal],
54
+ colour: [:red, :black],
55
+ text: "Some text"
56
+ })
57
+ end
36
58
  end
37
59
  end
38
60
  end
@@ -84,7 +84,7 @@ module Vedeu
84
84
  [
85
85
  [
86
86
  "\e[38;2;39m\e[48;2;49m\e[1;1H \e[1;1HSome text...\e[38;2;39m\e[48;2;49m\e[?25h",
87
- "\e[38;2;39m\e[48;2;49m\e[2;1H \e[2;1HSome more tex...\e[0m\e[38;2;39m\e[48;2;49m\e[?25h"
87
+ "\e[38;2;39m\e[48;2;49m\e[2;1H \e[2;1HSome more tex...\e[38;2;39m\e[48;2;49m\e[?25h"
88
88
  ]
89
89
  ]
90
90
  }
@@ -146,7 +146,7 @@ module Vedeu
146
146
  [
147
147
  [
148
148
  "\e[38;2;39m\e[48;2;49m\e[1;1H \e[1;1H\e[38;2;31m\e[48;2;47mSome text...\e[38;2;39m\e[48;2;49m\e[?25h",
149
- "\e[38;2;39m\e[48;2;49m\e[2;1H \e[2;1H\e[38;2;34m\e[48;2;43mSome more tex...\e[0m\e[38;2;39m\e[48;2;49m\e[?25h"
149
+ "\e[38;2;39m\e[48;2;49m\e[2;1H \e[2;1H\e[38;2;34m\e[48;2;43mSome more tex...\e[38;2;39m\e[48;2;49m\e[?25h"
150
150
  ]
151
151
  ]
152
152
  }
@@ -189,7 +189,7 @@ module Vedeu
189
189
  [
190
190
  [
191
191
  "\e[38;2;39m\e[48;2;49m\e[1;1H \e[1;1H\e[7mSome text...\e[38;2;39m\e[48;2;49m\e[?25h",
192
- "\e[38;2;39m\e[48;2;49m\e[2;1H \e[2;1H\e[4mSome more tex...\e[0m\e[38;2;39m\e[48;2;49m\e[?25h"
192
+ "\e[38;2;39m\e[48;2;49m\e[2;1H \e[2;1H\e[4mSome more tex...\e[38;2;39m\e[48;2;49m\e[?25h"
193
193
  ]
194
194
  ]
195
195
  }
@@ -231,8 +231,8 @@ module Vedeu
231
231
  let(:composition) {
232
232
  [
233
233
  [
234
- "\e[38;2;39m\e[48;2;49m\e[1;1H \e[1;1H\e[38;2;31m\e[48;2;40m\e[24m\e[21m\e[27m\e[38;2;33m\e[48;2;40m\e[4m\e[7mSome text...\e[38;2;32m\e[48;2;40m\e[24m\e[21m\e[27mSome more tex...\e[0m\e[38;2;39m\e[48;2;49m\e[?25h",
235
- "\e[38;2;39m\e[48;2;49m\e[2;1H \e[2;1HEven more tex...\e[0m\e[38;2;39m\e[48;2;49m\e[?25h"
234
+ "\e[38;2;39m\e[48;2;49m\e[1;1H \e[1;1H\e[38;2;31m\e[48;2;40m\e[24m\e[21m\e[27m\e[38;2;33m\e[48;2;40m\e[4m\e[7mSome text...\e[38;2;32m\e[48;2;40m\e[24m\e[21m\e[27mSome more tex...\e[38;2;39m\e[48;2;49m\e[?25h",
235
+ "\e[38;2;39m\e[48;2;49m\e[2;1H \e[2;1HEven more tex...\e[38;2;39m\e[48;2;49m\e[?25h"
236
236
  ]
237
237
  ]
238
238
  }
@@ -24,7 +24,7 @@ module Vedeu
24
24
  let(:output) {
25
25
  [
26
26
  [
27
- "\e[38;2;39m\e[48;2;49m\e[1;1H \e[1;1HTesting Outpu...\e[0m\e[38;2;39m\e[48;2;49m\e[?25h",
27
+ "\e[38;2;39m\e[48;2;49m\e[1;1H \e[1;1HTesting Outpu...\e[38;2;39m\e[48;2;49m\e[?25h",
28
28
  "\e[38;2;39m\e[48;2;49m\e[2;1H \e[2;1H\e[38;2;39m\e[48;2;49m\e[?25h"
29
29
  ]
30
30
  ]
@@ -39,6 +39,10 @@ module Vedeu
39
39
 
40
40
  subject { described_class.this(value, options) }
41
41
 
42
+ it 'returns a String' do
43
+ subject.must_be_instance_of(String)
44
+ end
45
+
42
46
  it 'returns formatted text' do
43
47
  subject.must_equal(formatted_value)
44
48
  end
@@ -47,7 +51,7 @@ module Vedeu
47
51
  let(:options) { { width: 70, prune: true } }
48
52
  let(:formatted_value) {
49
53
  'Lorem ipsum dolor sit amet, consectetur adipiscing elit.' \
50
- " Curabitur a...\e[0m"
54
+ " Curabitur a..."
51
55
  }
52
56
 
53
57
  it 'returns formatted text' do
@@ -6,20 +6,18 @@ module Vedeu
6
6
  let(:input) {}
7
7
 
8
8
  before do
9
- CommandRepository.create({ name: 'apple',
10
- entity: DummyCommand,
11
- options: {
12
- keypress: 'a',
13
- keyword: 'apple'
14
- }
15
- })
16
- CommandRepository.create({ name: 'banana',
17
- entity: DummyCommand,
18
- options: {
19
- keypress: 'b',
20
- keyword: 'banana'
21
- }
22
- })
9
+ CommandRepository.create({
10
+ name: 'apple',
11
+ entity: DummyCommand,
12
+ keypress: 'a',
13
+ keyword: 'apple'
14
+ })
15
+ CommandRepository.create({
16
+ name: 'banana',
17
+ entity: DummyCommand,
18
+ keypress: 'b',
19
+ keyword: 'banana'
20
+ })
23
21
  end
24
22
 
25
23
  after { CommandRepository.reset }
@@ -9,10 +9,8 @@ module Vedeu
9
9
  {
10
10
  name: 'dummy',
11
11
  entity: DummyCommand,
12
- options: {
13
- keyword: "dummy",
14
- keypress: "d"
15
- }
12
+ keyword: "dummy",
13
+ keypress: "d"
16
14
  }
17
15
  }
18
16
 
@@ -20,24 +18,28 @@ module Vedeu
20
18
  subject.must_be_instance_of(Command)
21
19
  end
22
20
 
23
- it 'sets an instance variable' do
24
- subject.instance_variable_get('@attributes').must_equal(attributes)
25
- end
21
+ it 'has a name attribute' do
22
+ subject.name.must_be_instance_of(String)
26
23
 
27
- it 'sets an instance variable' do
28
- subject.instance_variable_get('@name').must_equal('dummy')
24
+ subject.name.must_equal('dummy')
29
25
  end
30
26
 
31
- it 'sets an instance variable' do
32
- subject.instance_variable_get('@entity').must_equal(DummyCommand)
27
+ it 'has an entity attribute' do
28
+ subject.entity.must_be_instance_of(Class)
29
+
30
+ subject.entity.must_equal(DummyCommand)
33
31
  end
34
32
 
35
- it 'sets an instance variable' do
36
- subject.instance_variable_get('@keyword').must_equal('dummy')
33
+ it 'has a keypress attribute' do
34
+ subject.keypress.must_be_instance_of(String)
35
+
36
+ subject.keypress.must_equal('d')
37
37
  end
38
38
 
39
- it 'sets an instance variable' do
40
- subject.instance_variable_get('@keypress').must_equal('d')
39
+ it 'has an keyword attribute' do
40
+ subject.keyword.must_be_instance_of(String)
41
+
42
+ subject.keyword.must_equal('dummy')
41
43
  end
42
44
 
43
45
  describe '#execute' do
@@ -55,6 +57,10 @@ module Vedeu
55
57
 
56
58
  describe '#executable' do
57
59
  let(:subject) { described_instance.executable }
60
+
61
+ it 'returns a proc' do
62
+ subject.class.to_s.must_equal('Proc')
63
+ end
58
64
  end
59
65
  end
60
66
  end
@@ -0,0 +1,46 @@
1
+ require_relative '../../../test_helper'
2
+
3
+ module Vedeu
4
+ describe JSONParser do
5
+ let(:described_class) { JSONParser }
6
+ let(:described_instance) { described_class.new(json) }
7
+ let(:subject) { described_instance }
8
+ let(:json) { "[]" }
9
+
10
+ it 'returns a JSONParser instance' do
11
+ subject.must_be_instance_of(JSONParser)
12
+ end
13
+
14
+ it 'sets an instance variable' do
15
+ subject.instance_variable_get("@json").must_equal(json)
16
+ end
17
+
18
+ context 'when the instance variable is nil' do
19
+ let(:json) {}
20
+
21
+ it 'set the instance variable to empty string' do
22
+ subject.instance_variable_get("@json").must_equal('')
23
+ end
24
+ end
25
+
26
+ describe '#parse' do
27
+ let(:subject) { described_instance.parse }
28
+
29
+ context 'when the JSON contains a single interface' do
30
+ let(:json) { File.read('test/support/single_interface.json') }
31
+
32
+ it 'returns a Composition instance' do
33
+ subject.must_be_instance_of(Buffer::Composition)
34
+ end
35
+ end
36
+
37
+ context 'when the JSON contains multiple interfaces' do
38
+ let(:json) { File.read('test/support/multi_interface.json') }
39
+
40
+ it 'returns a Composition instance' do
41
+ subject.must_be_instance_of(Buffer::Composition)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,34 @@
1
+ {
2
+ "interface":[
3
+ {
4
+ "name":"dummy",
5
+ "line":[
6
+ {
7
+ "stream":[
8
+ {
9
+ "style":"normal",
10
+ "foreground":"yellow",
11
+ "background":"black",
12
+ "text":"Some text..."
13
+ }
14
+ ]
15
+ }
16
+ ]
17
+ },
18
+ {
19
+ "name":"dumber",
20
+ "line":[
21
+ {
22
+ "stream":[
23
+ {
24
+ "style":"normal",
25
+ "foreground":"red",
26
+ "background":"black",
27
+ "text":"Some more text..."
28
+ }
29
+ ]
30
+ }
31
+ ]
32
+ }
33
+ ]
34
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "interface":[
3
+ {
4
+ "name":"dummy",
5
+ "line":[
6
+ {
7
+ "stream":[
8
+ {
9
+ "style":"normal",
10
+ "foreground":"yellow",
11
+ "background":"black",
12
+ "text":"Some text..."
13
+ }
14
+ ]
15
+ }
16
+ ]
17
+ }
18
+ ]
19
+ }
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.23
4
+ version: 0.0.24
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-23 00:00:00.000000000 Z
11
+ date: 2014-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aruba
@@ -263,11 +263,9 @@ files:
263
263
  - lib/vedeu/output/buffer/formatting.rb
264
264
  - lib/vedeu/output/buffer/interface.rb
265
265
  - lib/vedeu/output/buffer/line.rb
266
- - lib/vedeu/output/buffer/parser.rb
267
266
  - lib/vedeu/output/buffer/stream.rb
268
267
  - lib/vedeu/output/buffer/style.rb
269
268
  - lib/vedeu/output/colour.rb
270
- - lib/vedeu/output/colour_pair.rb
271
269
  - lib/vedeu/output/compositor.rb
272
270
  - lib/vedeu/output/cursor.rb
273
271
  - lib/vedeu/output/directive.rb
@@ -292,6 +290,7 @@ files:
292
290
  - lib/vedeu/repository/storage.rb
293
291
  - lib/vedeu/support/event_loop.rb
294
292
  - lib/vedeu/support/exit.rb
293
+ - lib/vedeu/support/json_parser.rb
295
294
  - lib/vedeu/support/queue.rb
296
295
  - lib/vedeu/support/terminal.rb
297
296
  - lib/vedeu/version.rb
@@ -301,12 +300,11 @@ files:
301
300
  - test/lib/vedeu/output/background_test.rb
302
301
  - test/lib/vedeu/output/base_test.rb
303
302
  - test/lib/vedeu/output/buffer/composition_test.rb
303
+ - test/lib/vedeu/output/buffer/formatting_test.rb
304
304
  - test/lib/vedeu/output/buffer/interface_test.rb
305
305
  - test/lib/vedeu/output/buffer/line_test.rb
306
- - test/lib/vedeu/output/buffer/parser_test.rb
307
306
  - test/lib/vedeu/output/buffer/stream_test.rb
308
307
  - test/lib/vedeu/output/buffer/style_test.rb
309
- - test/lib/vedeu/output/colour_pair_test.rb
310
308
  - test/lib/vedeu/output/colour_test.rb
311
309
  - test/lib/vedeu/output/compositor_test.rb
312
310
  - test/lib/vedeu/output/cursor_test.rb
@@ -332,6 +330,7 @@ files:
332
330
  - test/lib/vedeu/repository/storage_test.rb
333
331
  - test/lib/vedeu/support/event_loop_test.rb
334
332
  - test/lib/vedeu/support/exit_test.rb
333
+ - test/lib/vedeu/support/json_parser_test.rb
335
334
  - test/lib/vedeu/support/queue_test.rb
336
335
  - test/lib/vedeu/support/terminal_test.rb
337
336
  - test/lib/vedeu/version_test.rb
@@ -340,6 +339,8 @@ files:
340
339
  - test/support/composition.json
341
340
  - test/support/composition.rb
342
341
  - test/support/composition.xml
342
+ - test/support/multi_interface.json
343
+ - test/support/single_interface.json
343
344
  - test/test_helper.rb
344
345
  - vedeu.gemspec
345
346
  homepage: http://www.gavinlaking.name/
@@ -376,12 +377,11 @@ test_files:
376
377
  - test/lib/vedeu/output/background_test.rb
377
378
  - test/lib/vedeu/output/base_test.rb
378
379
  - test/lib/vedeu/output/buffer/composition_test.rb
380
+ - test/lib/vedeu/output/buffer/formatting_test.rb
379
381
  - test/lib/vedeu/output/buffer/interface_test.rb
380
382
  - test/lib/vedeu/output/buffer/line_test.rb
381
- - test/lib/vedeu/output/buffer/parser_test.rb
382
383
  - test/lib/vedeu/output/buffer/stream_test.rb
383
384
  - test/lib/vedeu/output/buffer/style_test.rb
384
- - test/lib/vedeu/output/colour_pair_test.rb
385
385
  - test/lib/vedeu/output/colour_test.rb
386
386
  - test/lib/vedeu/output/compositor_test.rb
387
387
  - test/lib/vedeu/output/cursor_test.rb
@@ -407,6 +407,7 @@ test_files:
407
407
  - test/lib/vedeu/repository/storage_test.rb
408
408
  - test/lib/vedeu/support/event_loop_test.rb
409
409
  - test/lib/vedeu/support/exit_test.rb
410
+ - test/lib/vedeu/support/json_parser_test.rb
410
411
  - test/lib/vedeu/support/queue_test.rb
411
412
  - test/lib/vedeu/support/terminal_test.rb
412
413
  - test/lib/vedeu/version_test.rb
@@ -415,5 +416,7 @@ test_files:
415
416
  - test/support/composition.json
416
417
  - test/support/composition.rb
417
418
  - test/support/composition.xml
419
+ - test/support/multi_interface.json
420
+ - test/support/single_interface.json
418
421
  - test/test_helper.rb
419
422
  has_rdoc:
@@ -1,28 +0,0 @@
1
- module Vedeu
2
- module Buffer
3
- class Parser
4
- def initialize(composition)
5
- @composition = composition
6
- end
7
-
8
- def to_compositor
9
- composition.interface.inject({}) do |acc, interface|
10
- acc[interface.name] = interface.to_compositor
11
- acc
12
- end
13
- end
14
-
15
- def to_hash
16
- Oj.load(to_json)
17
- end
18
-
19
- def to_json
20
- Oj.dump(composition, mode: :compat, circular: true)
21
- end
22
-
23
- private
24
-
25
- attr_reader :composition
26
- end
27
- end
28
- end
@@ -1,43 +0,0 @@
1
- module Vedeu
2
- class ColourPair
3
- class << self
4
- def define(pair = [])
5
- return '' if pair.empty?
6
-
7
- new(pair).define
8
- end
9
- alias_method :set, :define
10
-
11
- def reset
12
- new.reset
13
- end
14
- end
15
-
16
- def initialize(pair = [])
17
- @pair = pair || []
18
- end
19
-
20
- def define
21
- [foreground, background].join
22
- end
23
- alias_method :set, :define
24
-
25
- def reset
26
- [foreground(:default), background(:default)].join
27
- end
28
-
29
- def foreground(value = pair[0])
30
- @foreground ||= Foreground.escape_sequence(value)
31
- end
32
- alias_method :fg, :foreground
33
-
34
- def background(value = pair[1])
35
- @background ||= Background.escape_sequence(value)
36
- end
37
- alias_method :bg, :background
38
-
39
- private
40
-
41
- attr_reader :pair
42
- end
43
- end
@@ -1,58 +0,0 @@
1
- require_relative '../../../../test_helper'
2
-
3
- module Vedeu
4
- module Buffer
5
- describe Parser do
6
- let(:described_class) { Parser }
7
- let(:described_instance) { described_class.new(composition) }
8
- let(:subject) { described_instance }
9
- let(:json) { File.read(Vedeu.root_path + '/test/support/composition.json') }
10
- let(:json_as_hash) { Oj.load(json) }
11
- let(:composition) { Vedeu::Buffer::Composition.new(json_as_hash) }
12
-
13
- it 'returns a Parser instance' do
14
- subject.must_be_instance_of(Buffer::Parser)
15
- end
16
-
17
- it 'sets an instance variable' do
18
- subject.instance_variable_get('@composition').must_equal(composition)
19
- end
20
-
21
- describe '#to_compositor' do
22
- let(:subject) { described_instance.to_compositor }
23
-
24
- it 'returns a Hash' do
25
- subject.must_be_instance_of(Hash)
26
- end
27
-
28
- it 'returns the composition as a Compositor format' do
29
- subject.must_equal({"dumb"=>[[{:style=>[:normal], :colour=>[:red, :black]}, {:style=>[:underline, :negative], :colour=>[:yellow, :black], :text=>"Some text..."}, {:style=>[:normal], :colour=>[:green, :black], :text=>"Some more text..."}], [{:style=>[], :colour=>[]}, {:style=>[], :colour=>[], :text=>"Even more text..."}]], "dumber"=>[[{:style=>[], :colour=>[]}, {:style=>[], :colour=>[], :text=>"Yet more text..."}]]})
30
- end
31
- end
32
-
33
- describe '#to_hash' do
34
- let(:subject) { described_instance.to_hash }
35
-
36
- it 'returns a Hash' do
37
- subject.must_be_instance_of(Hash)
38
- end
39
-
40
- it 'returns the composition as a Hash' do
41
- subject.must_equal({"interface"=>[{"name"=>"dumb", "line"=>[{"style"=>["normal"], "foreground"=>"red", "background"=>"black", "stream"=>[{"style"=>["underline", "negative"], "foreground"=>"yellow", "background"=>"black", "text"=>"Some text..."}, {"style"=>["normal"], "foreground"=>"green", "background"=>"black", "text"=>"Some more text..."}]}, {"style"=>nil, "foreground"=>nil, "background"=>nil, "stream"=>[{"style"=>nil, "foreground"=>nil, "background"=>nil, "text"=>"Even more text..."}]}]}, {"name"=>"dumber", "line"=>[{"style"=>nil, "foreground"=>nil, "background"=>nil, "stream"=>[{"style"=>nil, "foreground"=>nil, "background"=>nil, "text"=>"Yet more text..."}]}]}]})
42
- end
43
- end
44
-
45
- describe '#to_json' do
46
- let(:subject) { described_instance.to_json }
47
-
48
- it 'returns a String' do
49
- subject.must_be_instance_of(String)
50
- end
51
-
52
- it 'returns a String' do
53
- subject.must_equal("{\"interface\":[{\"name\":\"dumb\",\"line\":[{\"style\":[\"normal\"],\"foreground\":\"red\",\"background\":\"black\",\"stream\":[{\"style\":[\"underline\",\"negative\"],\"foreground\":\"yellow\",\"background\":\"black\",\"text\":\"Some text...\"},{\"style\":[\"normal\"],\"foreground\":\"green\",\"background\":\"black\",\"text\":\"Some more text...\"}]},{\"style\":null,\"foreground\":null,\"background\":null,\"stream\":[{\"style\":null,\"foreground\":null,\"background\":null,\"text\":\"Even more text...\"}]}]},{\"name\":\"dumber\",\"line\":[{\"style\":null,\"foreground\":null,\"background\":null,\"stream\":[{\"style\":null,\"foreground\":null,\"background\":null,\"text\":\"Yet more text...\"}]}]}]}")
54
- end
55
- end
56
- end
57
- end
58
- end
@@ -1,104 +0,0 @@
1
- require_relative '../../../test_helper'
2
-
3
- module Vedeu
4
- describe Colour do
5
- let(:described_class) { Colour }
6
- let(:described_instance) { described_class.new }
7
- let(:subject) { described_instance }
8
- let(:pair) { [] }
9
-
10
- it 'returns a Colour instance' do
11
- subject.must_be_instance_of(Colour)
12
- end
13
-
14
- it 'sets an instance variable' do
15
- subject.instance_variable_get('@pair').must_equal([])
16
- end
17
-
18
- describe '.set' do
19
- let(:subject) { described_class.set(pair) }
20
-
21
- it 'returns a String' do
22
- subject.must_be_instance_of(String)
23
- end
24
-
25
- context 'when the foreground and background are specified as symbols' do
26
- context 'when both the foreground and background is specified' do
27
- let(:pair) { [:red, :yellow] }
28
-
29
- it 'returns the code for red on yellow' do
30
- subject.must_equal("\e[38;2;31m\e[48;2;43m")
31
- end
32
- end
33
-
34
- context 'when a foreground is specified' do
35
- let(:pair) { [:blue] }
36
-
37
- it 'returns the code for blue on default' do
38
- subject.must_equal("\e[38;2;34m\e[48;2;49m")
39
- end
40
- end
41
-
42
- context 'when a background is specified' do
43
- let(:pair) { [nil, :cyan] }
44
-
45
- it 'returns the code for default with cyan background' do
46
- subject.must_equal("\e[38;2;39m\e[48;2;46m")
47
- end
48
- end
49
-
50
- context 'when an invalid foreground/background is specified' do
51
- let(:pair) { [:melon, :raspberry] }
52
-
53
- it 'returns the default code' do
54
- subject.must_equal("\e[38;2;39m\e[48;2;49m")
55
- end
56
- end
57
-
58
- context 'when no foreground/background is specified' do
59
- let(:pair) { [] }
60
-
61
- it 'return an empty string' do
62
- subject.must_equal('')
63
- end
64
- end
65
- end
66
-
67
- context 'when the foreground and background are specified as strings' do
68
- let(:pair) { ['#ff0000', '#0000ff'] }
69
-
70
- it 'returns the default code' do
71
- subject.must_equal("\e[38;5;196m\e[48;5;21m")
72
- end
73
- end
74
- end
75
-
76
- describe '.reset' do
77
- let(:subject) { described_class.reset }
78
-
79
- it 'returns a String' do
80
- subject.must_be_instance_of(String)
81
- end
82
-
83
- it 'returns an escape sequence' do
84
- subject.must_equal("\e[38;2;39m\e[48;2;49m")
85
- end
86
- end
87
-
88
- describe '#foreground' do
89
- let(:subject) { described_instance.foreground }
90
-
91
- it 'returns a String' do
92
- subject.must_be_instance_of(String)
93
- end
94
- end
95
-
96
- describe '#background' do
97
- let(:subject) { described_instance.background }
98
-
99
- it 'returns a String' do
100
- subject.must_be_instance_of(String)
101
- end
102
- end
103
- end
104
- end