vedeu 0.1.18 → 0.1.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +5 -0
  3. data/Dockerfile +40 -0
  4. data/README.md +7 -30
  5. data/docs/api.md +79 -0
  6. data/docs/events.md +121 -0
  7. data/lib/vedeu.rb +61 -18
  8. data/lib/vedeu/api/api.rb +73 -53
  9. data/lib/vedeu/api/composition.rb +4 -1
  10. data/lib/vedeu/api/defined.rb +35 -0
  11. data/lib/vedeu/api/helpers.rb +20 -15
  12. data/lib/vedeu/api/interface.rb +17 -12
  13. data/lib/vedeu/api/line.rb +20 -12
  14. data/lib/vedeu/api/stream.rb +3 -0
  15. data/lib/vedeu/application.rb +34 -1
  16. data/lib/vedeu/configuration.rb +15 -3
  17. data/lib/vedeu/input/input.rb +77 -0
  18. data/lib/vedeu/launcher.rb +7 -0
  19. data/lib/vedeu/models/attributes/background.rb +15 -2
  20. data/lib/vedeu/models/attributes/coercions.rb +18 -3
  21. data/lib/vedeu/models/attributes/colour_translator.rb +23 -17
  22. data/lib/vedeu/models/attributes/foreground.rb +10 -2
  23. data/lib/vedeu/models/attributes/presentation.rb +62 -0
  24. data/lib/vedeu/models/colour.rb +7 -3
  25. data/lib/vedeu/models/composition.rb +17 -19
  26. data/lib/vedeu/models/geometry.rb +13 -5
  27. data/lib/vedeu/models/interface.rb +35 -19
  28. data/lib/vedeu/models/line.rb +24 -8
  29. data/lib/vedeu/models/stream.rb +13 -7
  30. data/lib/vedeu/models/style.rb +17 -7
  31. data/lib/vedeu/{support → output}/clear.rb +14 -0
  32. data/lib/vedeu/output/compositor.rb +77 -0
  33. data/lib/vedeu/output/refresh.rb +129 -0
  34. data/lib/vedeu/{support → output}/render.rb +49 -13
  35. data/lib/vedeu/{support → output}/view.rb +15 -8
  36. data/lib/vedeu/repositories/buffers.rb +181 -0
  37. data/lib/vedeu/{support → repositories}/events.rb +16 -6
  38. data/lib/vedeu/repositories/focus.rb +109 -0
  39. data/lib/vedeu/repositories/groups.rb +76 -0
  40. data/lib/vedeu/repositories/interfaces.rb +74 -0
  41. data/lib/vedeu/support/common.rb +20 -0
  42. data/lib/vedeu/support/cursor.rb +77 -0
  43. data/lib/vedeu/support/esc.rb +181 -46
  44. data/lib/vedeu/support/event.rb +22 -4
  45. data/lib/vedeu/support/grid.rb +10 -3
  46. data/lib/vedeu/support/log.rb +14 -1
  47. data/lib/vedeu/support/menu.rb +51 -12
  48. data/lib/vedeu/support/position.rb +9 -0
  49. data/lib/vedeu/support/terminal.rb +49 -15
  50. data/lib/vedeu/support/trace.rb +11 -4
  51. data/test/integration/defining_interfaces_test.rb +27 -0
  52. data/test/integration/views/basic_view_test.rb +767 -0
  53. data/test/lib/vedeu/api/api_test.rb +32 -37
  54. data/test/lib/vedeu/api/composition_test.rb +23 -61
  55. data/test/lib/vedeu/api/defined_test.rb +49 -0
  56. data/test/lib/vedeu/api/helpers_test.rb +91 -0
  57. data/test/lib/vedeu/api/interface_test.rb +136 -688
  58. data/test/lib/vedeu/api/line_test.rb +28 -32
  59. data/test/lib/vedeu/application_test.rb +6 -0
  60. data/test/lib/vedeu/configuration_test.rb +8 -4
  61. data/test/lib/vedeu/{support → input}/input_test.rb +9 -0
  62. data/test/lib/vedeu/launcher_test.rb +6 -0
  63. data/test/lib/vedeu/models/attributes/{coercer_test.rb → coercions_test.rb} +11 -10
  64. data/test/lib/vedeu/models/attributes/colour_translator_test.rb +13 -0
  65. data/test/lib/vedeu/models/attributes/presentation_test.rb +30 -0
  66. data/test/lib/vedeu/models/colour_test.rb +8 -0
  67. data/test/lib/vedeu/models/composition_test.rb +208 -200
  68. data/test/lib/vedeu/models/geometry_test.rb +39 -0
  69. data/test/lib/vedeu/models/interface_test.rb +11 -1
  70. data/test/lib/vedeu/models/line_test.rb +8 -1
  71. data/test/lib/vedeu/models/stream_test.rb +35 -0
  72. data/test/lib/vedeu/models/style_test.rb +8 -0
  73. data/test/lib/vedeu/{support → output}/clear_test.rb +1 -1
  74. data/test/lib/vedeu/output/compositor_test.rb +64 -0
  75. data/test/lib/vedeu/output/refresh_test.rb +48 -0
  76. data/test/lib/vedeu/{support → output}/render_test.rb +36 -0
  77. data/test/lib/vedeu/{support → output}/view_test.rb +0 -0
  78. data/test/lib/vedeu/repositories/buffers_test.rb +48 -0
  79. data/test/lib/vedeu/{support → repositories}/events_test.rb +0 -0
  80. data/test/lib/vedeu/repositories/focus_test.rb +74 -0
  81. data/test/lib/vedeu/repositories/groups_test.rb +66 -0
  82. data/test/lib/vedeu/repositories/interfaces_test.rb +6 -0
  83. data/test/lib/vedeu/support/common_test.rb +6 -0
  84. data/test/lib/vedeu/support/cursor_test.rb +79 -0
  85. data/test/lib/vedeu/support/log_test.rb +6 -0
  86. data/test/lib/vedeu/support/terminal_test.rb +6 -28
  87. data/test/lib/vedeu/support/trace_test.rb +6 -0
  88. data/test/test_helper.rb +37 -0
  89. data/vedeu.gemspec +1 -1
  90. metadata +65 -33
  91. data/bin/log +0 -13
  92. data/lib/vedeu/support/buffer.rb +0 -69
  93. data/lib/vedeu/support/buffers.rb +0 -106
  94. data/lib/vedeu/support/focus.rb +0 -83
  95. data/lib/vedeu/support/groups.rb +0 -61
  96. data/lib/vedeu/support/input.rb +0 -67
  97. data/test/lib/vedeu/support/buffer_test.rb +0 -83
  98. data/test/lib/vedeu/support/buffers_test.rb +0 -15
  99. data/test/lib/vedeu/support/focus_test.rb +0 -114
  100. data/test/lib/vedeu/support/groups_test.rb +0 -65
data/bin/log DELETED
@@ -1,13 +0,0 @@
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
- loop do
10
- Vedeu.log('-B<-------------------------------------------------------------------')
11
-
12
- sleep 60
13
- end
@@ -1,69 +0,0 @@
1
- module Vedeu
2
- class Buffer
3
-
4
- attr_reader :back, :front, :interface
5
-
6
- # @param [Hash] attributes The buffer attributes.
7
- # @option attributes :back [Hash] The next view to be rendered.
8
- # @option attributes :front [Hash] The view which is currently on screen.
9
- # @option attributes :interface [Hash] An attribute form of the interface from
10
- # which we can create a new front or back.
11
- # @return [Buffer]
12
- def initialize(attributes = {})
13
- @attributes = attributes
14
-
15
- @back = attributes.fetch(:back)
16
- @front = attributes.fetch(:front)
17
- @interface = attributes.fetch(:interface)
18
- end
19
-
20
- # @param view [Interface]
21
- # @return [Buffer]
22
- def enqueue(view)
23
- merge({ back: view })
24
- end
25
-
26
- # @return [Buffer]
27
- def refresh
28
- return merge({ front: back, back: nil }).render if content_available?
29
- return clear if no_content_available?
30
- return render
31
- end
32
-
33
- # @return [Buffer]
34
- def render
35
- Terminal.output(front.to_s)
36
-
37
- self
38
- end
39
-
40
- # @return [Buffer]
41
- def clear
42
- Terminal.output(interface.clear)
43
-
44
- self
45
- end
46
-
47
- private
48
-
49
- # @api private
50
- # @param new_attributes [Hash]
51
- # @return [Buffer]
52
- def merge(new_attributes)
53
- Buffer.new(@attributes.merge(new_attributes))
54
- end
55
-
56
- # @api private
57
- # @return [TrueClass|FalseClass]
58
- def content_available?
59
- !!(back)
60
- end
61
-
62
- # @api private
63
- # @return [TrueClass|FalseClass]
64
- def no_content_available?
65
- front.nil?
66
- end
67
-
68
- end
69
- end
@@ -1,106 +0,0 @@
1
- module Vedeu
2
- module Buffers
3
-
4
- extend self
5
-
6
- # @param attributes [Hash]
7
- # @return [Hash]
8
- def create(attributes)
9
- store_attributes(attributes)
10
-
11
- groups.add(attributes[:group], attributes[:name], attributes[:delay])
12
-
13
- focus.add(attributes[:name])
14
-
15
- store_interface(Interface.new(attributes))
16
- end
17
-
18
- # @return [Hash]
19
- def reset
20
- @_storage = {}
21
- @_buffers = {}
22
- groups.reset
23
- end
24
-
25
- # @param name [String]
26
- # @return [Hash]
27
- def retrieve_attributes(name)
28
- storage.fetch(name) { fail EntityNotFound, 'Interface was not found.' }
29
- end
30
-
31
- # @param name [String]
32
- # @return [Buffer]
33
- def retrieve_interface(name)
34
- buffers.fetch(name) { fail EntityNotFound, 'Interface was not found.' }
35
- end
36
-
37
- # @param attributes [Hash]
38
- # @return [Hash]
39
- def store_attributes(attributes)
40
- storage.store(attributes[:name], attributes)
41
- end
42
-
43
- # @param interface [Interface]
44
- # @return [Buffer]
45
- def store_interface(interface)
46
- update(interface.name,
47
- Buffer.new(interface: interface, back: nil, front: nil))
48
- end
49
-
50
- # @param name [String]
51
- # @param view [Interface]
52
- # @return []
53
- def enqueue(name, view)
54
- update(name, retrieve_interface(name).enqueue(view))
55
- end
56
-
57
- # @return [Array]
58
- def refresh_all
59
- buffers.keys.map { |name| refresh(name) }
60
- end
61
-
62
- # @return [Array]
63
- def refresh_group(group_name)
64
- groups.find(group_name).map { |name| refresh(name) }
65
- end
66
-
67
- # @param name [String]
68
- # @return []
69
- def refresh(name)
70
- update(name, retrieve_interface(name).refresh)
71
- end
72
-
73
- private
74
-
75
- # @api private
76
- # @return []
77
- def update(name, buffer)
78
- buffers.store(name, buffer)
79
- end
80
-
81
- # @api private
82
- # @return [Focus]
83
- def focus
84
- @_focus ||= Focus.new
85
- end
86
-
87
- # @api private
88
- # @return [Groups]
89
- def groups
90
- @_groups ||= Groups.new
91
- end
92
-
93
- # @api private
94
- # @return [Hash]
95
- def buffers
96
- @_buffers ||= {}
97
- end
98
-
99
- # @api private
100
- # @return [Hash]
101
- def storage
102
- @_storage ||= {}
103
- end
104
-
105
- end
106
- end
@@ -1,83 +0,0 @@
1
- module Vedeu
2
-
3
- # Maintains which interface is current in focus.
4
- class Focus
5
-
6
- # @return [Focus]
7
- def initialize
8
- register_events
9
-
10
- self
11
- end
12
-
13
- # @param name [String]
14
- # @return [Array]
15
- def add(name)
16
- if registered?(name)
17
- storage
18
-
19
- else
20
- storage << name
21
-
22
- end
23
- end
24
-
25
- # @param name [String]
26
- # @return [String]
27
- def by_name(name)
28
- fail InterfaceNotFound unless storage.include?(name)
29
-
30
- storage.rotate!(storage.index(name))
31
-
32
- current
33
- end
34
-
35
- # @return [String]
36
- def current
37
- fail NoInterfacesDefined if storage.empty?
38
-
39
- storage.first
40
- end
41
-
42
- # @return [String]
43
- def next_item
44
- storage.rotate!
45
-
46
- current
47
- end
48
-
49
- # @return [String]
50
- def prev_item
51
- storage.rotate!(-1)
52
-
53
- current
54
- end
55
-
56
- # @return [TrueClass]
57
- def register_events
58
- Vedeu.event(:_focus_next_) { next_item }
59
- Vedeu.event(:_focus_prev_) { prev_item }
60
- Vedeu.event(:_focus_by_name_) { |name| by_name(name) }
61
- Vedeu.event(:_focussed_) { current }
62
-
63
- true
64
- end
65
-
66
- private
67
-
68
- # @api private
69
- # @return [TrueClass|FalseClass]
70
- def registered?(name)
71
- return false if storage.empty?
72
-
73
- storage.include?(name)
74
- end
75
-
76
- # @api private
77
- # @return [Array]
78
- def storage
79
- @storage ||= []
80
- end
81
-
82
- end
83
- end
@@ -1,61 +0,0 @@
1
- module Vedeu
2
- class Groups
3
-
4
- # @return [Groups]
5
- def initialize; end
6
-
7
- # @return [Set]
8
- def all
9
- @_storage
10
- end
11
-
12
- # @param name [String]
13
- # @return [Set]
14
- def find(name)
15
- storage.fetch(name) do
16
- fail GroupNotFound, 'Cannot find interface group with this name.'
17
- end
18
- end
19
-
20
- # @param group [String]
21
- # @param name [String]
22
- # @param delay [Float]
23
- # @return [Groups|FalseClass]
24
- def add(group, name, delay = 0.0)
25
- return false if group.empty?
26
-
27
- storage[group] << name
28
-
29
- register_group_refresh_event(group, delay)
30
-
31
- self
32
- end
33
-
34
- # @return [Hash]
35
- def reset
36
- @_storage = in_memory
37
- end
38
-
39
- private
40
-
41
- # @api private
42
- # @return []
43
- def register_group_refresh_event(group, delay = 0.0)
44
- Vedeu.event("_refresh_group_#{group}_".to_sym, { delay: delay }) do
45
- Buffers.refresh_group(group)
46
- end
47
- end
48
-
49
- # @api private
50
- # @return [Hash]
51
- def storage
52
- @_storage ||= in_memory
53
- end
54
-
55
- # @api private
56
- # @return [Hash]
57
- def in_memory
58
- Hash.new { |hash, key| hash[key] = Set.new }
59
- end
60
- end
61
- end
@@ -1,67 +0,0 @@
1
- module Vedeu
2
- class Input
3
-
4
- # @return [String|Symbol]
5
- def self.capture
6
- new.capture
7
- end
8
-
9
- # @return [Input]
10
- def initialize; end
11
-
12
- # @return []
13
- def capture
14
- Vedeu.trigger(:_keypress_, keypress)
15
- end
16
-
17
- private
18
-
19
- # @api private
20
- # @return [String]
21
- def input
22
- @_input ||= Terminal.input
23
- end
24
-
25
- # @api private
26
- # @return [String|Symbol]
27
- def keypress
28
- key = input
29
- translated = case key
30
- when "\r" then :enter
31
- when "\t" then :tab
32
- when "\e" then :escape
33
- when "\e[A" then :up
34
- when "\e[B" then :down
35
- when "\e[C" then :right
36
- when "\e[D" then :left
37
- when "\e[5~" then :page_up
38
- when "\e[6~" then :page_down
39
- when "\e[H" then :home
40
- when "\e[3~" then :delete
41
- when "\e[F" then :end
42
- when "\e[Z" then :shift_tab
43
- when "\eOP" then :f1
44
- when "\eOQ" then :f2
45
- when "\eOR" then :f3
46
- when "\eOS" then :f4
47
- when "\e[15~" then :f5
48
- when "\e[17~" then :f6
49
- when "\e[18~" then :f7
50
- when "\e[19~" then :f8
51
- when "\e[20~" then :f9
52
- when "\e[21~" then :f10
53
- when "\e[23~" then :f11
54
- when "\e[24~" then :f12
55
- when "\e[1;2P" then :print_screen
56
- when "\e[1;2Q" then :scroll_lock
57
- when "\e[1;2R" then :pause_break
58
- when "\u007F" then :backspace
59
- else
60
- key
61
- end
62
-
63
- translated
64
- end
65
-
66
- end
67
- end
@@ -1,83 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Vedeu
4
- describe Buffer do
5
- let(:vars) {
6
- {
7
- back: '',
8
- front: '',
9
- interface: mock('Interface'),
10
- }
11
- }
12
-
13
- describe '#initialize' do
14
- it 'returns a Buffer instance when all the vars are set' do
15
- #vars = { name: 'interface', clear: '', current: '', group: '', next: '' }
16
- Buffer.new(vars).must_be_instance_of(Buffer)
17
- end
18
-
19
- it 'raises an exception if a var is not set' do
20
- vars = {}
21
- proc { Buffer.new(vars) }.must_raise(KeyError)
22
- end
23
- end
24
-
25
- describe '#enqueue' do
26
- it 'creates a new Buffer instance with the sequence assigned to @_next' do
27
- buffer = Buffer.new(vars)
28
- new_buffer = buffer.enqueue('some_sequence')
29
-
30
- buffer.back.must_equal('')
31
- new_buffer.wont_equal(buffer)
32
- new_buffer.back.must_equal('some_sequence')
33
- end
34
- end
35
-
36
- describe '#refresh' do
37
- it 'renders the fresh content if available' do
38
- interface = Interface.new
39
- buffer = Buffer.new({ back: interface, front: nil, interface: interface })
40
- Terminal.stub(:output, '') do
41
- buffer.refresh.must_be_instance_of(Buffer)
42
- buffer.refresh.wont_equal(buffer)
43
- end
44
- end
45
-
46
- it 'clears the interface if no content is available' do
47
- interface = Interface.new
48
- buffer = Buffer.new({ back: nil, front: nil, interface: interface })
49
- Terminal.stub(:output, '') do
50
- buffer.refresh.must_equal(buffer)
51
- end
52
- end
53
-
54
- it 'renders the previous/old content if nothing new has arrived' do
55
- interface = Interface.new
56
- buffer = Buffer.new({ back: nil, front: interface, interface: interface })
57
- Terminal.stub(:output, '') do
58
- buffer.refresh.must_equal(buffer)
59
- end
60
- end
61
- end
62
-
63
- describe '#render' do
64
- it 'renders the interface and returns the Buffer instance' do
65
- interface = Interface.new
66
- buffer = Buffer.new({ back: nil, front: nil, interface: interface })
67
- Terminal.stub(:output, '') do
68
- buffer.render.must_equal(buffer)
69
- end
70
- end
71
- end
72
-
73
- describe '#clear' do
74
- it 'clears the interface and returns the Buffer instance' do
75
- interface = Interface.new
76
- buffer = Buffer.new({ back: nil, front: nil, interface: interface })
77
- Terminal.stub(:output, '') do
78
- buffer.clear.must_equal(buffer)
79
- end
80
- end
81
- end
82
- end
83
- end