vedeu 0.4.29 → 0.4.30

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +57 -38
  3. data/README.md +10 -110
  4. data/docs/getting_started.md +9 -0
  5. data/lib/vedeu/all.rb +1 -1
  6. data/lib/vedeu/api.rb +6 -5
  7. data/lib/vedeu/buffers/display_buffer.rb +1 -1
  8. data/lib/vedeu/configuration/api.rb +1 -1
  9. data/lib/vedeu/cursor/move.rb +2 -2
  10. data/lib/vedeu/debug.rb +3 -1
  11. data/lib/vedeu/dsl/all.rb +15 -9
  12. data/lib/vedeu/dsl/{components/border.rb → border.rb} +0 -3
  13. data/lib/vedeu/dsl/composition.rb +33 -0
  14. data/lib/vedeu/dsl/{components/geometry.rb → geometry.rb} +18 -0
  15. data/lib/vedeu/dsl/interface.rb +2 -2
  16. data/lib/vedeu/dsl/{components/keymap.rb → keymap.rb} +2 -4
  17. data/lib/vedeu/dsl/{components/menu.rb → menu.rb} +0 -0
  18. data/lib/vedeu/dsl/{shared/presentation.rb → presentation.rb} +0 -0
  19. data/lib/vedeu/dsl/{shared/text.rb → text.rb} +0 -0
  20. data/lib/vedeu/dsl/{shared/use.rb → use.rb} +0 -0
  21. data/lib/vedeu/events/event.rb +11 -53
  22. data/lib/vedeu/geometry/area.rb +1 -2
  23. data/lib/vedeu/geometry/coordinate.rb +1 -1
  24. data/lib/vedeu/geometry/geometry.rb +0 -12
  25. data/lib/vedeu/geometry/position_validator.rb +1 -1
  26. data/lib/vedeu/input/keymap.rb +1 -1
  27. data/lib/vedeu/models/interface.rb +1 -0
  28. data/lib/vedeu/models/panel.rb +2 -0
  29. data/lib/vedeu/null/geometry.rb +3 -2
  30. data/lib/vedeu/output/border.rb +6 -6
  31. data/lib/vedeu/output/clear.rb +4 -4
  32. data/lib/vedeu/output/compressor.rb +10 -4
  33. data/lib/vedeu/output/html_char.rb +4 -4
  34. data/lib/vedeu/output/refresh.rb +3 -3
  35. data/lib/vedeu/output/renderers/file.rb +1 -1
  36. data/lib/vedeu/output/renderers/terminal.rb +2 -2
  37. data/lib/vedeu/output/renderers/text.rb +1 -1
  38. data/lib/vedeu/output/style.rb +1 -1
  39. data/lib/vedeu/output/translator.rb +0 -8
  40. data/lib/vedeu/output/viewport.rb +1 -1
  41. data/lib/vedeu/repositories/all.rb +1 -1
  42. data/lib/vedeu/repositories/repository.rb +1 -1
  43. data/lib/vedeu/support/common.rb +1 -1
  44. data/lib/vedeu/support/template.rb +1 -1
  45. data/lib/vedeu/support/timer.rb +11 -14
  46. data/lib/vedeu/templating/all.rb +9 -0
  47. data/lib/vedeu/templating/helpers.rb +9 -3
  48. data/lib/vedeu/templating/preprocessor.rb +4 -1
  49. data/lib/vedeu/version.rb +3 -0
  50. data/test/lib/vedeu/api_test.rb +38 -297
  51. data/test/lib/vedeu/buffers/display_buffer_test.rb +1 -0
  52. data/test/lib/vedeu/dsl/{components/border_test.rb → border_test.rb} +0 -0
  53. data/test/lib/vedeu/dsl/{components/geometry_test.rb → geometry_test.rb} +0 -0
  54. data/test/lib/vedeu/dsl/{components/keymap_test.rb → keymap_test.rb} +0 -0
  55. data/test/lib/vedeu/dsl/{components/menu_test.rb → menu_test.rb} +0 -0
  56. data/test/lib/vedeu/dsl/{shared/presentation_test.rb → presentation_test.rb} +0 -0
  57. data/test/lib/vedeu/dsl/{shared/text_test.rb → text_test.rb} +0 -0
  58. data/test/lib/vedeu/dsl/{shared/use_test.rb → use_test.rb} +0 -0
  59. data/test/lib/vedeu/dsl/view_test.rb +2 -0
  60. data/test/lib/vedeu/main_loop_test.rb +0 -3
  61. data/test/lib/vedeu/output/background_test.rb +18 -22
  62. data/test/lib/vedeu/output/compressor_test.rb +4 -0
  63. data/test/lib/vedeu/output/foreground_test.rb +13 -17
  64. data/test/lib/vedeu/repositories/repositories/borders_test.rb +2 -1
  65. data/test/lib/vedeu/repositories/repositories/buffers_test.rb +5 -1
  66. data/test/lib/vedeu/repositories/repositories/geometries_test.rb +2 -0
  67. data/test/lib/vedeu/support/common_test.rb +2 -2
  68. data/test/lib/vedeu/support/timer_test.rb +4 -6
  69. data/test/test_helper.rb +22 -0
  70. data/vedeu.gemspec +3 -1
  71. metadata +24 -25
  72. data/lib/vedeu/dsl/components/all.rb +0 -4
  73. data/lib/vedeu/dsl/shared/all.rb +0 -3
@@ -117,7 +117,7 @@ module Vedeu
117
117
 
118
118
  private
119
119
 
120
- # @return (see Vedeu::Borders#by_name)
120
+ # @see Vedeu::Borders#by_name
121
121
  def border
122
122
  @border ||= Vedeu.borders.by_name(name)
123
123
  end
@@ -9,18 +9,6 @@ module Vedeu
9
9
  # Calculates and provides interface geometry determined by both the client's
10
10
  # requirements and the terminal's current viewing area.
11
11
  #
12
- # Geometry for Vedeu, as the same for ANSI terminals, has the origin at
13
- # top-left, y = 1, x = 1. The 'y' coordinate is deliberately first.
14
- #
15
- # x north xn # north: y - 1
16
- # y +--------------+ # top: y
17
- # | top | # west: x - 1
18
- # | | # left: x
19
- # west | left right | east # right: xn
20
- # | | # east: xn + 1
21
- # | bottom | # bottom: yn
22
- # yn +--------------+ # south: yn + 1
23
- # south
24
12
  class Geometry
25
13
 
26
14
  extend Forwardable
@@ -58,7 +58,7 @@ module Vedeu
58
58
 
59
59
  private
60
60
 
61
- # @return (see Vedeu::Borders#by_name)
61
+ # @see Vedeu::Borders#by_name
62
62
  def border
63
63
  @border ||= Vedeu.borders.by_name(name)
64
64
  end
@@ -1,4 +1,4 @@
1
- require 'vedeu/dsl/components/keymap'
1
+ require 'vedeu/dsl/keymap'
2
2
 
3
3
  module Vedeu
4
4
 
@@ -141,6 +141,7 @@ module Vedeu
141
141
 
142
142
  private
143
143
 
144
+ # @see Vedeu::Cursors#by_name
144
145
  def cursor
145
146
  @cursor ||= Vedeu.cursors.by_name(name)
146
147
  end
@@ -1,7 +1,9 @@
1
1
  module Vedeu
2
2
 
3
+ # Abstract interface class without the baggage.
3
4
  class Panel
4
5
 
6
+ # @return [Vedeu::Panel]
5
7
  def initialize
6
8
  end
7
9
 
@@ -23,7 +23,7 @@ module Vedeu
23
23
  :height,
24
24
  :width
25
25
 
26
- # @!attribute [rw] maximise
26
+ # @!attribute [rw] maximised
27
27
  # @return [Boolean]
28
28
  attr_accessor :maximised
29
29
 
@@ -36,7 +36,8 @@ module Vedeu
36
36
  # @param name [String|NilClass]
37
37
  # @return [Vedeu::Null::Geometry]
38
38
  def initialize(name = nil)
39
- @name = name
39
+ @name = name
40
+ @maximised = false
40
41
  end
41
42
 
42
43
  # @return [FalseClass]
@@ -120,22 +120,22 @@ module Vedeu
120
120
 
121
121
  # @return [Fixnum]
122
122
  def bx
123
- (enabled? && left?) ? x + 1 : x
123
+ @bx ||= (enabled? && left?) ? x + 1 : x
124
124
  end
125
125
 
126
126
  # @return [Fixnum]
127
127
  def bxn
128
- (enabled? && right?) ? xn - 1 : xn
128
+ @bxn ||= (enabled? && right?) ? xn - 1 : xn
129
129
  end
130
130
 
131
131
  # @return [Fixnum]
132
132
  def by
133
- (enabled? && top?) ? y + 1 : y
133
+ @by ||= (enabled? && top?) ? y + 1 : y
134
134
  end
135
135
 
136
136
  # @return [Fixnum]
137
137
  def byn
138
- (enabled? && bottom?) ? yn - 1 : yn
138
+ @byn ||= (enabled? && bottom?) ? yn - 1 : yn
139
139
  end
140
140
 
141
141
  # Returns the width of the interface determined by whether a left, right,
@@ -159,7 +159,7 @@ module Vedeu
159
159
  return [] unless visible?
160
160
  return [] unless enabled?
161
161
 
162
- Vedeu::Timer.for(:timer, "Rendering border: #{name}") do
162
+ Vedeu.timer("Rendering border: #{name}") do
163
163
  out = [top, bottom]
164
164
 
165
165
  height.times do |y|
@@ -300,7 +300,7 @@ module Vedeu
300
300
  #
301
301
  # @return [Boolean]
302
302
  def title?
303
- defined_value?(title)
303
+ present?(title)
304
304
  end
305
305
 
306
306
  # @param value [String]
@@ -76,7 +76,7 @@ module Vedeu
76
76
  # @return [Array<Array<Vedeu::Char>>]
77
77
  def clear
78
78
  if visible?
79
- Vedeu::Timer.for(:timer, "Clearing: #{name}") do
79
+ Vedeu.timer("Clearing: #{name}") do
80
80
  y, x = *position
81
81
 
82
82
  @clear ||= Array.new(height) do |iy|
@@ -84,7 +84,7 @@ module Vedeu
84
84
  Vedeu::Char.new(value: ' ',
85
85
  colour: clear_colour,
86
86
  style: style,
87
- position: [y + iy, x + ix])
87
+ position: Vedeu::Position[y + iy, x + ix])
88
88
  end
89
89
  end
90
90
  end
@@ -111,7 +111,7 @@ module Vedeu
111
111
 
112
112
  private
113
113
 
114
- # @return (see Vedeu::Borders#by_name)
114
+ # @see Vedeu::Borders#by_name
115
115
  def border
116
116
  @border ||= Vedeu.borders.by_name(name)
117
117
  end
@@ -143,7 +143,7 @@ module Vedeu
143
143
  }
144
144
  end
145
145
 
146
- # @return (see Vedeu::Geometries#by_name)
146
+ # @see Vedeu::Geometries#by_name
147
147
  def geometry
148
148
  @geometry ||= Vedeu.geometries.by_name(name)
149
149
  end
@@ -5,6 +5,12 @@ module Vedeu
5
5
  # sequence, resulting in a smaller payload being sent to the renderer.
6
6
  class Compressor
7
7
 
8
+ # @param output [Array<Array<Vedeu::Char>>]
9
+ # @return [String]
10
+ def self.render(output)
11
+ new(output).render
12
+ end
13
+
8
14
  # @param output [Array<Array<Vedeu::Char>>]
9
15
  # @return [Vedeu::Compressor]
10
16
  def initialize(output)
@@ -16,14 +22,14 @@ module Vedeu
16
22
  # @note Takes approximately ~70ms for 2100 chars. (2015-05-24)
17
23
  # @return [String]
18
24
  def render
19
- Array(output).flatten.map do |char|
20
- out = ''
25
+ out = ''
26
+ Array(output).flatten.each do |char|
21
27
  out << char.position.to_s
22
28
  out << colour_for(char)
23
29
  out << style_for(char)
24
30
  out << char.value
25
- out
26
- end.join
31
+ end
32
+ out
27
33
  end
28
34
 
29
35
  protected
@@ -36,7 +36,7 @@ module Vedeu
36
36
 
37
37
  # @return [String]
38
38
  def td_style
39
- return '' unless border || defined_value?(value)
39
+ return '' unless border || present?(value)
40
40
 
41
41
  " style='" \
42
42
  "background:#{bg};" \
@@ -47,7 +47,7 @@ module Vedeu
47
47
 
48
48
  # @return [String]
49
49
  def td_value
50
- return '&nbsp;' if border || !defined_value?(value)
50
+ return '&nbsp;' if border || !present?(value)
51
51
 
52
52
  value
53
53
  end
@@ -102,10 +102,10 @@ module Vedeu
102
102
  type_to_html = char.send(type).send(:to_html)
103
103
  parent_type_to_html = char.send(parent_type).send(:to_html)
104
104
 
105
- if defined_value?(type_to_html)
105
+ if present?(type_to_html)
106
106
  type_to_html
107
107
 
108
- elsif defined_value?(parent_type_to_html)
108
+ elsif present?(parent_type_to_html)
109
109
  parent_type_to_html
110
110
 
111
111
  else
@@ -12,7 +12,7 @@ module Vedeu
12
12
  def all
13
13
  message = 'Refreshing all interfaces'
14
14
 
15
- Vedeu::Timer.for(:timer, message) do
15
+ Vedeu.timer(message) do
16
16
  Vedeu.interfaces.zindexed.each { |model| by_name(model.name) }
17
17
  end
18
18
  end
@@ -32,7 +32,7 @@ module Vedeu
32
32
  def by_group(group_name)
33
33
  message = "Refreshing group: '#{group_name}'"
34
34
 
35
- Vedeu::Timer.for(:timer, message) do
35
+ Vedeu.timer(message) do
36
36
  Vedeu.groups.find!(group_name).members.each { |name|
37
37
  Vedeu.interfaces.by_name(name)
38
38
  }.sort { |a, b| a.zindex <=> b.zindex }.each { |name| by_name(name) }
@@ -47,7 +47,7 @@ module Vedeu
47
47
  def by_name(name)
48
48
  message = "Refreshing interface: '#{name}'"
49
49
 
50
- Vedeu::Timer.for(:timer, message) { Vedeu.buffers.by_name(name).render }
50
+ Vedeu.timer(message) { Vedeu.buffers.by_name(name).render }
51
51
  end
52
52
 
53
53
  end # Refresh
@@ -57,7 +57,7 @@ module Vedeu
57
57
 
58
58
  # @return [String]
59
59
  def parsed
60
- @parsed ||= Vedeu::Compressor.new(output).render
60
+ @parsed ||= Vedeu::Compressor.render(output)
61
61
  end
62
62
 
63
63
  # @return [Float]
@@ -35,8 +35,8 @@ module Vedeu
35
35
 
36
36
  # @return [String]
37
37
  def parsed
38
- Vedeu::Timer.for(:timer, 'Compression') do
39
- Vedeu::Compressor.new(output).render
38
+ Vedeu.timer('Compression') do
39
+ Vedeu::Compressor.render(output)
40
40
  end
41
41
  end
42
42
 
@@ -35,7 +35,7 @@ module Vedeu
35
35
 
36
36
  # @return [String]
37
37
  def parsed
38
- Vedeu::Compressor.new(output).render
38
+ Vedeu::Compressor.render(output)
39
39
  end
40
40
 
41
41
  end # Text
@@ -66,7 +66,7 @@ module Vedeu
66
66
  #
67
67
  # @return [String]
68
68
  def to_s
69
- return '' unless defined_value?(value)
69
+ return '' unless present?(value)
70
70
 
71
71
  @sequences ||= Array(value).flatten.map { |v| Vedeu::Esc.string(v) }.join
72
72
  end
@@ -44,14 +44,6 @@ module Vedeu
44
44
  end
45
45
  end
46
46
 
47
- # Convert a CSS/HTML colour string into a terminal escape sequence.
48
- #
49
- # @param colour [Fixnum|String|Symbol]
50
- # @return [String]
51
- def self.escape_sequence(colour = '')
52
- new(colour).escape_sequence
53
- end
54
-
55
47
  # Return a new instance of Vedeu::Translator.
56
48
  #
57
49
  # @param colour [Fixnum|String|Symbol]
@@ -52,7 +52,7 @@ module Vedeu
52
52
  def render
53
53
  return [] unless visible?
54
54
 
55
- Vedeu::Timer.for(:timer, "Rendering: #{name}") do
55
+ Vedeu.timer("Rendering: #{name}") do
56
56
  out = []
57
57
 
58
58
  show.each_with_index do |line, iy|
@@ -30,7 +30,7 @@ module Vedeu
30
30
  @storage ||= Set.new
31
31
  end
32
32
 
33
- end
33
+ end # Repositories
34
34
 
35
35
  end # Vedeu
36
36
 
@@ -156,7 +156,7 @@ module Vedeu
156
156
  # @return [void] The model instance which was stored.
157
157
  def store(model)
158
158
  fail MissingRequired, "Cannot store model '#{model.class}' without a " \
159
- 'name attribute.' unless defined_value?(model.name)
159
+ 'name attribute.' unless present?(model.name)
160
160
 
161
161
  log_store(model)
162
162
 
@@ -8,7 +8,7 @@ module Vedeu
8
8
  #
9
9
  # @param variable [String|Symbol|Array|Fixnum] The variable to check.
10
10
  # @return [Boolean]
11
- def defined_value?(variable)
11
+ def present?(variable)
12
12
  return true if variable.is_a?(Fixnum)
13
13
  return true unless variable.nil? || variable.empty?
14
14
 
@@ -3,7 +3,7 @@ module Vedeu
3
3
  # Generic class to loading a template and parsing it via ERb.
4
4
  class Template
5
5
 
6
- # @param see Vedeu::Template#new
6
+ # @param (see Vedeu::Template#new)
7
7
  # @return [void]
8
8
  def self.parse(object, path, options = {})
9
9
  new(object, path, options).parse
@@ -3,19 +3,20 @@ module Vedeu
3
3
  # Measure the duration. Used for debugging.
4
4
  class Timer
5
5
 
6
- # @param type [Symbol]
7
- # @param message [String]
8
- # @param block [Proc]
9
- # @return [void]
10
- def self.for(type = :debug, message = '', &block)
11
- new(type, message).measure(&block)
6
+ class << self
7
+
8
+ # @param message [String]
9
+ # @param block [Proc]
10
+ # @return [void]
11
+ def timer(message = '', &block)
12
+ new(message).measure(&block)
13
+ end
14
+
12
15
  end
13
16
 
14
- # @param type [Symbol]
15
17
  # @param message [String]
16
18
  # @return [Vedeu::Timer]
17
- def initialize(type = :debug, message = '')
18
- @type = type
19
+ def initialize(message = '')
19
20
  @message = message
20
21
  @started = Time.now.to_f
21
22
  end
@@ -27,7 +28,7 @@ module Vedeu
27
28
 
28
29
  elapsed = ((Time.now.to_f - started) * 1000).to_i
29
30
 
30
- Vedeu.log(type: type, message: "#{message} took #{elapsed}ms.")
31
+ Vedeu.log(type: :timer, message: "#{message} took #{elapsed}ms.")
31
32
 
32
33
  work
33
34
  end
@@ -42,10 +43,6 @@ module Vedeu
42
43
  # @return [String]
43
44
  attr_reader :message
44
45
 
45
- # @!attribute [r] type
46
- # @return [Symbol]
47
- attr_reader :type
48
-
49
46
  end # Timer
50
47
 
51
48
  end # Vedeu
@@ -1,3 +1,12 @@
1
+ module Vedeu
2
+
3
+ # Provides means to use templates with Vedeu.
4
+ module Templating
5
+
6
+ end # Templating
7
+
8
+ end # Vedeu
9
+
1
10
  require_relative 'helpers'
2
11
  require_relative 'directive'
3
12
  require_relative 'preprocessor'
@@ -2,8 +2,14 @@ module Vedeu
2
2
 
3
3
  module Templating
4
4
 
5
+ # Provide helpers to be used with your Vedeu templates.
5
6
  module Helpers
6
7
 
8
+ # @example
9
+ # Roses are {{ background('#ff0000', 'red') }},
10
+ # violets are {{ bg('#0000ff', 'blue') }},
11
+ # {{ background('#00ff00'), 'The test suite is all green!' }}
12
+ #
7
13
  # @param value [String] The HTML/CSS colour.
8
14
  # @param block [Proc]
9
15
  # @return [Vedeu::Stream]
@@ -25,7 +31,7 @@ module Vedeu
25
31
 
26
32
  # @example
27
33
  # Roses are {{ foreground('#ff0000', 'red') }},
28
- # violets are {{ fg('#0000ff', 'blue') }}
34
+ # violets are {{ fg('#0000ff', 'blue') }},
29
35
  # {{ foreground('#00ff00'), 'The test suite is all green!' }}
30
36
  #
31
37
  # @param value [String] The HTML/CSS colour.
@@ -39,7 +45,7 @@ module Vedeu
39
45
 
40
46
  private
41
47
 
42
- # @param see Vedeu::Templating::Helpers#colours
48
+ # @see Vedeu::Templating::Helpers#colours
43
49
  def define_colour(attributes = {})
44
50
  attributes.delete_if do |k, v|
45
51
  [:background, :foreground].include?(k) == false || v.nil? || v.empty?
@@ -48,7 +54,7 @@ module Vedeu
48
54
  Vedeu::Colour.new(attributes)
49
55
  end
50
56
 
51
- # @param see Vedeu::Templating::Helpers#colours
57
+ # @see Vedeu::Templating::Helpers#colours
52
58
  def define_stream(attributes = {}, &block)
53
59
  fail InvalidSyntax, 'block not given' unless block_given?
54
60
 
@@ -11,7 +11,7 @@ module Vedeu
11
11
  #
12
12
  # process
13
13
  # converts JSON streams into line/stream objects with correct attributes
14
-
14
+ #
15
15
  # Pre-processes a template, to convert all lines and lines with directives
16
16
  # into Vedeu::Streams.
17
17
  class Preprocessor
@@ -52,6 +52,9 @@ module Vedeu
52
52
 
53
53
  # Return a pattern to remove directive markers and spaces.
54
54
  #
55
+ # @example
56
+ # line containing {{ or }}
57
+ #
55
58
  # @return [Regexp]
56
59
  def markers
57
60
  /({{\s*|\s*}})/
@@ -0,0 +1,3 @@
1
+ module Vedeu
2
+ VERSION = '0.4.30'
3
+ end