vedeu 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/Guardfile +5 -0
  3. data/README.md +34 -0
  4. data/deps.md +13 -13
  5. data/lib/vedeu.rb +1 -1
  6. data/lib/vedeu/instrumentation.rb +1 -1
  7. data/lib/vedeu/models/geometry.rb +76 -0
  8. data/lib/vedeu/models/interface.rb +9 -21
  9. data/lib/vedeu/models/stream.rb +16 -4
  10. data/lib/vedeu/output/clear_interface.rb +4 -4
  11. data/lib/vedeu/{support/translator.rb → output/colour_translator.rb} +1 -1
  12. data/lib/vedeu/output/erb_parser.rb +11 -0
  13. data/lib/vedeu/output/raw_parser.rb +9 -1
  14. data/lib/vedeu/output/render_interface.rb +3 -3
  15. data/lib/vedeu/support/esc.rb +8 -6
  16. data/lib/vedeu/support/helpers.rb +39 -18
  17. data/lib/vedeu/support/interface_template.rb +42 -19
  18. data/test/lib/vedeu/models/composition_test.rb +27 -21
  19. data/test/lib/vedeu/models/geometry_test.rb +183 -0
  20. data/test/lib/vedeu/models/interface_test.rb +26 -59
  21. data/test/lib/vedeu/models/stream_test.rb +57 -7
  22. data/test/lib/vedeu/output/clear_interface_test.rb +8 -4
  23. data/test/lib/vedeu/{support/translator_test.rb → output/colour_translator_test.rb} +8 -8
  24. data/test/lib/vedeu/output/erb_parser_test.rb +158 -70
  25. data/test/lib/vedeu/output/render_interface_test.rb +4 -3
  26. data/test/lib/vedeu/support/esc_test.rb +10 -2
  27. data/test/lib/vedeu/support/helpers_test.rb +11 -4
  28. data/test/lib/vedeu/support/interface_template_test.rb +58 -34
  29. data/test/support/colours.rb +2 -2
  30. data/test/support/erb/line.erb +4 -0
  31. data/test/support/erb/line_2x.erb +10 -0
  32. data/test/support/erb/line_foreground.erb +4 -0
  33. data/test/support/erb/line_foreground_2x.erb +5 -0
  34. data/vedeu.gemspec +2 -1
  35. metadata +30 -8
  36. data/lib/vedeu/support/geometry.rb +0 -172
  37. data/test/lib/vedeu/support/geometry_test.rb +0 -408
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 831514463a8bea83f3e218ddd59dccc347049e34
4
- data.tar.gz: 2e6f495bc8b2bed85942a4335ff3b3bca86b07dd
3
+ metadata.gz: 7c4536e9fdde25f748de839f9a992e805b97f308
4
+ data.tar.gz: 0a951cfde4234e720dcbdf943bf6f91c2b95dc41
5
5
  SHA512:
6
- metadata.gz: 9de37b9db1bc093309b4465f0ca3104b29ff9e2870b3a0eca008a9040e2c3317063ea74f4b67436a32dc952310f7314e05751fade11f0f7532ba18fc7757499f
7
- data.tar.gz: 0d681db9caef7bebfbb5fcb01b48f3a4890ef8d62d8594c8efb496d7a7c8189ca1f46a02a3794d5775a4ba56696feedddb0760727900f219467860fa7c7377b3
6
+ metadata.gz: f92b9b9b3bdccb7a55df3aedddde6bd9ae67a88925c1c1584d274ebcdab52a98624377968ff91f8a1f61c854567cd363e848cb67d356665e4bf7be02b07ff8b2
7
+ data.tar.gz: 839cbdab1f3b684e35874975b2dc6c2052487edb94cdbef65aa12c72282ab679b711fac9dc11743a85849d1e817e4992143760509541e1adaac65cc3ed283d8e
data/Guardfile CHANGED
@@ -5,3 +5,8 @@ guard :minitest, all_after_pass: true, focus_on_failed: true, env: { 'no_simplec
5
5
  end
6
6
  watch(%r{^test/test_helper\.rb}) { 'test' }
7
7
  end
8
+
9
+ guard :bundler do
10
+ watch('Gemfile')
11
+ watch(/^.+\.gemspec/)
12
+ end
data/README.md CHANGED
@@ -58,6 +58,20 @@ Expect proper documentation soon!
58
58
  end
59
59
 
60
60
 
61
+ ### Building Views
62
+
63
+ Views with Vedeu are made up of simple building blocks. These blocks can be arranged in a multitude of ways which I hope is more than sufficient for your design needs.
64
+
65
+ - Interfaces (`Interface`) are made up of lines. (`Line`)
66
+ - Lines are made up of zero, one or multiple streams. (`Stream`)
67
+ - An interface, line or stream can have a colour (`colour`) attribute.
68
+ - An interface, line or stream can have a style (`style`) attribute.
69
+ - Interfaces have a position (`y`, `x`) on the screen, and a size. (`width`, `height`)
70
+ - Interfaces can be placed relative to each other based on their attributes. (`top`, `right`, `bottom`, `left`)
71
+ - Colours are defined in CSS-style values, i.e. `#ff0000` would be red.
72
+ - Styles are named. See the table below for supported styles.
73
+
74
+
61
75
  ### Some Terms
62
76
 
63
77
  To understand how Vedeu works, you need to familiarise yourself with some terms.
@@ -133,6 +147,26 @@ Vedeu has a range of symbol styles which are compatible with most terminals whic
133
147
 
134
148
  Like colours, they can be defined in either interfaces, for specific lines or within streams. Styles are applied as encountered.
135
149
 
150
+ | Style name | Escape Sequence |
151
+ |---------------|--------------------------|
152
+ | bg_reset | `\e[48;2;49m` |
153
+ | blink | `\e[5m` |
154
+ | blink_off | `\e[25m` |
155
+ | bold | `\e[1m` |
156
+ | bold_off | `\e[21m` |
157
+ | clear | `\e[2J` |
158
+ | colour_reset | `\e[38;2;39m\e[48;2;49m` |
159
+ | fg_reset | `\e[38;2;39m` |
160
+ | hide_cursor | `\e[?25l` |
161
+ | negative | `\e[7m` |
162
+ | positive | `\e[27m` |
163
+ | reset | `\e[0m` |
164
+ | normal | `\e[24m\e[21m\e[27m` |
165
+ | dim | `\e[2m` |
166
+ | show_cursor | `\e[?25h` |
167
+ | underline | `\e[4m` |
168
+ | underline_off | `\e[24m` |
169
+
136
170
 
137
171
  ### Templates
138
172
 
data/deps.md CHANGED
@@ -26,7 +26,7 @@ Geometry
26
26
  ERBParser
27
27
 
28
28
  Esc
29
- Translator
29
+ ColourTranslator
30
30
 
31
31
  Events
32
32
 
@@ -113,7 +113,7 @@ Terminal
113
113
 
114
114
  TextAdaptor
115
115
 
116
- Translator
116
+ ColourTranslator
117
117
 
118
118
  Wordwrap
119
119
 
@@ -140,7 +140,7 @@ Launcher
140
140
  Queue
141
141
  Terminal
142
142
  Esc
143
- Translator
143
+ ColourTranslator
144
144
  Process
145
145
  Parser
146
146
  Composition
@@ -150,41 +150,41 @@ Launcher
150
150
  ClearInterface
151
151
  Colour
152
152
  Esc
153
- Translator
153
+ ColourTranslator
154
154
  Geometry
155
155
  Esc
156
- Translator
156
+ ColourTranslator
157
157
  Terminal
158
158
  Esc
159
- Translator
159
+ ColourTranslator
160
160
  LineCollection
161
161
  Collection
162
162
  Line
163
163
  Colour
164
164
  Esc
165
- Translator
165
+ ColourTranslator
166
166
  StreamCollection
167
167
  Collection
168
168
  Stream
169
169
  Colour
170
170
  Esc
171
- Translator
171
+ ColourTranslator
172
172
  Style
173
173
  Esc
174
- Translator
174
+ ColourTranslator
175
175
  Style
176
176
  Esc
177
- Translator
177
+ ColourTranslator
178
178
 
179
179
  Queue
180
180
  RenderInterface
181
181
  ClearInterface
182
182
  Style
183
183
  Esc
184
- Translator
184
+ ColourTranslator
185
185
  Terminal
186
186
  Esc
187
- Translator
187
+ ColourTranslator
188
188
  ERBParser
189
189
  Template
190
190
  RawParser
@@ -194,5 +194,5 @@ Launcher
194
194
  Queue
195
195
  Terminal
196
196
  Esc
197
- Translator
197
+ ColourTranslator
198
198
  Configuration
data/lib/vedeu.rb CHANGED
@@ -3,7 +3,7 @@ require 'vedeu/support/interface_template'
3
3
  require 'vedeu/support/events'
4
4
  require 'vedeu/support/interface_store'
5
5
 
6
- require 'vedeu/support/geometry'
6
+ require 'vedeu/models/geometry'
7
7
  require 'vedeu/support/menu'
8
8
  require 'vedeu/output/view'
9
9
  require 'vedeu/launcher'
@@ -70,7 +70,7 @@ module Vedeu
70
70
  def defaults
71
71
  {
72
72
  event: 'call',
73
- klass: /^Vedeu::(?!.*Instrumentation|Interface|Line|Stream|Style|Colour|Geometry|Terminal|Esc|Translator).*/
73
+ klass: /^Vedeu::(?!.*Instrumentation|Interface|Line|Stream|Style|Colour|Geometry|Terminal|Esc|ColourTranslator).*/
74
74
  }
75
75
  end
76
76
 
@@ -0,0 +1,76 @@
1
+ require 'virtus'
2
+
3
+ require 'vedeu/support/esc'
4
+ require 'vedeu/support/terminal'
5
+
6
+ module Vedeu
7
+ class Geometry
8
+ include Virtus.model
9
+
10
+ attribute :y, Integer, default: 1
11
+ attribute :x, Integer, default: 1
12
+ attribute :width, Integer, default: Terminal.width
13
+ attribute :height, Integer, default: Terminal.height
14
+ attribute :centred, Boolean, default: false
15
+
16
+ def origin(index = 0)
17
+ Esc.set_position(virtual_y[index], left)
18
+ end
19
+
20
+ def top
21
+ if centred
22
+ centre_y - (height / 2)
23
+ else
24
+ y
25
+ end
26
+ end
27
+
28
+ def left
29
+ if centred
30
+ centre_x - (width / 2)
31
+ else
32
+ x
33
+ end
34
+ end
35
+
36
+ def bottom
37
+ top + height
38
+ end
39
+
40
+ def right
41
+ left + width
42
+ end
43
+
44
+ def position
45
+ {
46
+ y: top,
47
+ x: left,
48
+ height: height,
49
+ width: width,
50
+ centred: centred,
51
+ top: top,
52
+ bottom: bottom,
53
+ left: left,
54
+ right: right,
55
+ }
56
+ end
57
+
58
+ private
59
+
60
+ def centre
61
+ @_centre ||= Terminal.centre
62
+ end
63
+
64
+ def centre_y
65
+ centre.first
66
+ end
67
+
68
+ def centre_x
69
+ centre.last
70
+ end
71
+
72
+ def virtual_y
73
+ @_virtual_y ||= (top..bottom).to_a
74
+ end
75
+ end
76
+ end
@@ -6,7 +6,7 @@ require 'vedeu/models/colour'
6
6
  require 'vedeu/models/style'
7
7
  require 'vedeu/output/clear_interface'
8
8
  require 'vedeu/output/render_interface'
9
- require 'vedeu/support/geometry'
9
+ require 'vedeu/models/geometry'
10
10
  require 'vedeu/support/queue'
11
11
  require 'vedeu/support/terminal'
12
12
 
@@ -17,18 +17,14 @@ module Vedeu
17
17
  include Vedeu::Queue
18
18
  include Virtus.model
19
19
 
20
- attribute :name, String
21
- attribute :lines, LineCollection
22
- attribute :colour, Colour, default: Colour.new
23
- attribute :style, Style, default: ''
24
- attribute :y, Integer, default: 1
25
- attribute :x, Integer, default: 1
26
- attribute :width, Integer, default: Terminal.width
27
- attribute :height, Integer, default: Terminal.height
28
- attribute :current, String, default: ''
29
- attribute :cursor, Boolean, default: true
30
- attribute :centred, Boolean, default: false
31
- attribute :delay, Float, default: 0
20
+ attribute :name, String
21
+ attribute :lines, LineCollection
22
+ attribute :colour, Colour, default: Colour.new
23
+ attribute :style, Style, default: ''
24
+ attribute :geometry, Geometry, default: Geometry.new
25
+ attribute :current, String, default: ''
26
+ attribute :cursor, Boolean, default: true
27
+ attribute :delay, Float, default: 0
32
28
 
33
29
  def initialize(attributes = {})
34
30
  super
@@ -46,14 +42,6 @@ module Vedeu
46
42
  super(self.to_s)
47
43
  end
48
44
 
49
- def geometry
50
- @_geometry ||= Geometry.new(attributes)
51
- end
52
-
53
- def origin(index = 0)
54
- geometry.origin(index)
55
- end
56
-
57
45
  def refresh
58
46
  if enqueued?
59
47
  self.current = dequeue
@@ -7,12 +7,24 @@ module Vedeu
7
7
  class Stream
8
8
  include Virtus.model
9
9
 
10
- attribute :colour, Colour, default: Colour.new
11
- attribute :style, Style, default: ''
12
- attribute :text, String, default: ''
10
+ attribute :colour, Colour, default: Colour.new
11
+ attribute :style, Style, default: ''
12
+ attribute :text, String, default: ''
13
+ attribute :width, Integer
14
+ attribute :align, Symbol, default: :left # :centre, :right
13
15
 
14
16
  def to_s(options = {})
15
- [colour, style, text].join
17
+ if width
18
+ aligned = case align
19
+ when :left then text.ljust(width, ' ')
20
+ when :right then text.rjust(width, ' ')
21
+ when :centre then text.center(width, ' ')
22
+ end
23
+
24
+ [colour, style, aligned].join
25
+ else
26
+ [colour, style, text].join
27
+ end
16
28
  end
17
29
  end
18
30
  end
@@ -10,9 +10,9 @@ module Vedeu
10
10
 
11
11
  def clear
12
12
  interface_lines.inject([colours]) do |line, index|
13
- line << interface.origin(index)
14
- line << ' ' * interface.width
15
- line << interface.origin(index)
13
+ line << interface.geometry.origin(index)
14
+ line << ' ' * interface.geometry.width
15
+ line << interface.geometry.origin(index)
16
16
  end.join
17
17
  end
18
18
 
@@ -25,7 +25,7 @@ module Vedeu
25
25
  end
26
26
 
27
27
  def interface_lines
28
- interface.height.times
28
+ interface.geometry.height.times
29
29
  end
30
30
  end
31
31
  end
@@ -1,5 +1,5 @@
1
1
  module Vedeu
2
- class Translator
2
+ class ColourTranslator
3
3
  def self.translate(html_colour = '')
4
4
  new(html_colour).translate
5
5
  end
@@ -12,6 +12,7 @@ module Vedeu
12
12
 
13
13
  def initialize(object)
14
14
  @object = object
15
+ @output = ''
15
16
  end
16
17
 
17
18
  def parse
@@ -29,6 +30,16 @@ module Vedeu
29
30
 
30
31
  attr_reader :object
31
32
 
33
+ def capture(&block)
34
+ erbout = eval('_erbout', block.binding)
35
+ erbout_length = erbout.length
36
+ block.call
37
+ erbout_addition = erbout[erbout_length..-1]
38
+ erbout[erbout_length..-1] = ''
39
+ erbout_addition = erbout_addition.join if erbout_addition.is_a? Array
40
+ erbout_addition
41
+ end
42
+
32
43
  def erb_output
33
44
  ERB.new(template, nil, '-').result(get_binding)
34
45
  end
@@ -22,11 +22,19 @@ module Vedeu
22
22
  stringified_keys.map do |name, content|
23
23
  {
24
24
  name: name,
25
- lines: TextAdaptor.adapt(content)
25
+ lines: lines(content)
26
26
  }
27
27
  end
28
28
  end
29
29
 
30
+ def lines(content)
31
+ if content.is_a?(Array) && content.first.is_a?(Hash)
32
+ content
33
+ else
34
+ TextAdaptor.adapt(content)
35
+ end
36
+ end
37
+
30
38
  def stringified_keys
31
39
  attributes.inject({}) { |a, (k, v)| a[k.to_s] = v; a }
32
40
  end
@@ -12,7 +12,7 @@ module Vedeu
12
12
  out = [interface.clear]
13
13
  processed_lines.each_with_index do |line, index|
14
14
  if index + 1 <= height
15
- out << interface.origin(index)
15
+ out << interface.geometry.origin(index)
16
16
  out << line.to_s
17
17
  end
18
18
  end
@@ -61,11 +61,11 @@ module Vedeu
61
61
  end
62
62
 
63
63
  def height
64
- interface.height
64
+ interface.geometry.height
65
65
  end
66
66
 
67
67
  def width
68
- interface.width
68
+ interface.geometry.width
69
69
  end
70
70
  end
71
71
  end
@@ -1,17 +1,17 @@
1
- require 'vedeu/support/translator'
1
+ require 'vedeu/output/colour_translator'
2
2
 
3
3
  module Vedeu
4
4
  module Esc
5
5
  extend self
6
6
 
7
- def background_colour(value = '#000000')
8
- return '' if value.empty?
7
+ def background_colour(value = '')
8
+ return '' if value.nil? || value.empty?
9
9
 
10
10
  ["\e[48;5;", colour_translator(value), 'm'].join
11
11
  end
12
12
 
13
- def foreground_colour(value = '#ffffff')
14
- return '' if value.empty?
13
+ def foreground_colour(value = '')
14
+ return '' if value.nil? || value.empty?
15
15
 
16
16
  ["\e[38;5;", colour_translator(value), 'm'].join
17
17
  end
@@ -25,12 +25,14 @@ module Vedeu
25
25
 
26
26
  def string(value = '')
27
27
  case value
28
+ when 'bg_reset' then "\e[48;2;49m"
28
29
  when 'blink' then "\e[5m"
29
30
  when 'blink_off' then "\e[25m"
30
31
  when 'bold' then "\e[1m"
31
32
  when 'bold_off' then "\e[21m"
32
33
  when 'clear' then "\e[2J"
33
34
  when 'colour_reset' then "\e[38;2;39m\e[48;2;49m"
35
+ when 'fg_reset' then "\e[38;2;39m"
34
36
  when 'hide_cursor' then "\e[?25l"
35
37
  when 'negative' then "\e[7m"
36
38
  when 'positive' then "\e[27m"
@@ -48,7 +50,7 @@ module Vedeu
48
50
  private
49
51
 
50
52
  def colour_translator(value)
51
- Translator.translate(value)
53
+ ColourTranslator.translate(value)
52
54
  end
53
55
  end
54
56
  end