vedeu 0.4.15 → 0.4.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/examples/borders_app.rb +0 -2
  4. data/examples/colours_app.rb +0 -2
  5. data/examples/cursor_app.rb +0 -2
  6. data/examples/drb_app.rb +0 -2
  7. data/examples/focus_app.rb +0 -2
  8. data/examples/geometry_app.rb +0 -2
  9. data/examples/hello_world.rb +0 -2
  10. data/examples/lines_app.rb +0 -2
  11. data/examples/material_colours_app.rb +0 -2
  12. data/lib/vedeu/bindings.rb +2 -1
  13. data/lib/vedeu/buffers/buffer.rb +18 -10
  14. data/lib/vedeu/debug.rb +2 -1
  15. data/lib/vedeu/distributed/server.rb +14 -8
  16. data/lib/vedeu/dsl/composition.rb +3 -10
  17. data/lib/vedeu/dsl/line.rb +14 -11
  18. data/lib/vedeu/dsl/shared/colour.rb +2 -3
  19. data/lib/vedeu/geometry/coordinate.rb +0 -4
  20. data/lib/vedeu/geometry/position.rb +2 -1
  21. data/lib/vedeu/main_loop.rb +1 -1
  22. data/lib/vedeu/models/all.rb +2 -0
  23. data/lib/vedeu/models/char.rb +4 -6
  24. data/lib/vedeu/models/composition.rb +4 -2
  25. data/lib/vedeu/models/interface.rb +4 -18
  26. data/lib/vedeu/models/line.rb +4 -3
  27. data/lib/vedeu/models/null_interface.rb +15 -0
  28. data/lib/vedeu/models/stream.rb +4 -3
  29. data/lib/vedeu/output/border.rb +9 -12
  30. data/lib/vedeu/output/clear.rb +2 -2
  31. data/lib/vedeu/output/colour.rb +30 -8
  32. data/lib/vedeu/output/esc.rb +2 -1
  33. data/lib/vedeu/output/presentation.rb +37 -20
  34. data/lib/vedeu/output/renderers/all.rb +1 -0
  35. data/lib/vedeu/output/renderers/escape_sequence_renderer.rb +40 -0
  36. data/lib/vedeu/output/renderers/file_renderer.rb +9 -5
  37. data/lib/vedeu/output/renderers/html_renderer.rb +1 -1
  38. data/lib/vedeu/output/text.rb +1 -15
  39. data/lib/vedeu/output/viewport.rb +1 -1
  40. data/lib/vedeu/repositories/repositories/borders.rb +11 -11
  41. data/lib/vedeu/repositories/repositories/buffers.rb +11 -11
  42. data/lib/vedeu/repositories/repositories/cursors.rb +15 -15
  43. data/lib/vedeu/repositories/repositories/events_repository.rb +11 -11
  44. data/lib/vedeu/repositories/repositories/geometries.rb +11 -11
  45. data/lib/vedeu/repositories/repositories/groups.rb +11 -11
  46. data/lib/vedeu/repositories/repositories/interfaces_repository.rb +23 -10
  47. data/lib/vedeu/repositories/repositories/keymaps.rb +11 -11
  48. data/lib/vedeu/repositories/repositories/menus.rb +11 -11
  49. data/test/lib/vedeu/buffers/buffer_test.rb +4 -6
  50. data/test/lib/vedeu/distributed/server_test.rb +101 -3
  51. data/test/lib/vedeu/dsl/view_test.rb +6 -0
  52. data/test/lib/vedeu/input/input_test.rb +1 -1
  53. data/test/lib/vedeu/models/char_test.rb +18 -2
  54. data/test/lib/vedeu/models/composition_test.rb +0 -2
  55. data/test/lib/vedeu/models/interface_test.rb +12 -17
  56. data/test/lib/vedeu/models/line_test.rb +0 -2
  57. data/test/lib/vedeu/models/null_interface_test.rb +9 -0
  58. data/test/lib/vedeu/models/stream_test.rb +0 -2
  59. data/test/lib/vedeu/output/border_test.rb +2 -4
  60. data/test/lib/vedeu/output/clear_test.rb +17 -0
  61. data/test/lib/vedeu/output/colour_test.rb +139 -0
  62. data/test/lib/vedeu/output/output_test.rb +15 -13
  63. data/test/lib/vedeu/output/renderers/escape_sequence_renderer_test.rb +46 -0
  64. data/test/lib/vedeu/output/renderers/file_renderer_test.rb +27 -4
  65. data/test/lib/vedeu/output/renderers/html_renderer_test.rb +14 -3
  66. data/test/lib/vedeu/repositories/repositories/interfaces_repository_test.rb +8 -0
  67. data/test/test_helper.rb +3 -2
  68. data/vedeu.gemspec +4 -4
  69. metadata +18 -10
@@ -22,9 +22,12 @@ module Vedeu
22
22
  # @!attribute [rw] streams
23
23
  # @return [Streams]
24
24
  attr_accessor :streams
25
-
26
25
  alias_method :value, :streams
27
26
 
27
+ # @!attribute [r] attributes
28
+ # @return [Hash]
29
+ attr_reader :attributes
30
+
28
31
  # Returns a new instance of Vedeu::Line.
29
32
  #
30
33
  # @param attributes [Hash]
@@ -35,10 +38,8 @@ module Vedeu
35
38
  # @return [Vedeu::Line]
36
39
  def initialize(attributes = {})
37
40
  @attributes = defaults.merge!(attributes)
38
- @colour = @attributes[:colour]
39
41
  @parent = @attributes[:parent]
40
42
  @streams = @attributes[:streams]
41
- @style = @attributes[:style]
42
43
  end
43
44
 
44
45
  # @param child []
@@ -0,0 +1,15 @@
1
+ module Vedeu
2
+
3
+ class NullInterface
4
+
5
+ # @!attribute [r] attributes
6
+ # @return [Hash]
7
+ attr_reader :attributes
8
+
9
+ def initialize(attributes = {})
10
+ @attributes = attributes
11
+ end
12
+
13
+ end # NullInterface
14
+
15
+ end # Vedeu
@@ -22,11 +22,14 @@ module Vedeu
22
22
  # @!attribute [rw] value
23
23
  # @return [String]
24
24
  attr_accessor :value
25
-
26
25
  alias_method :content, :value
27
26
  alias_method :data, :value
28
27
  alias_method :text, :value
29
28
 
29
+ # @!attribute [r] attributes
30
+ # @return [Hash]
31
+ attr_reader :attributes
32
+
30
33
  # Returns a new instance of Vedeu::Stream.
31
34
  #
32
35
  # @param attributes [Hash]
@@ -37,9 +40,7 @@ module Vedeu
37
40
  # @return [Vedeu::Stream]
38
41
  def initialize(attributes = {})
39
42
  @attributes = defaults.merge!(attributes)
40
- @colour = @attributes[:colour]
41
43
  @parent = @attributes[:parent]
42
- @style = @attributes[:style]
43
44
  @value = @attributes[:value]
44
45
  end
45
46
 
@@ -82,19 +82,11 @@ module Vedeu
82
82
  # @return [String]
83
83
  attr_reader :name
84
84
 
85
- # @!attribute [r] colour
86
- # @return [Vedeu::Colour]
87
- attr_reader :colour
88
-
89
85
  # @!attribute [r] enabled
90
86
  # @return [Boolean]
91
87
  attr_reader :enabled
92
88
  alias_method :enabled?, :enabled
93
89
 
94
- # @!attribute [r] style
95
- # @return [Style]
96
- attr_reader :style
97
-
98
90
  # Returns a new instance of Vedeu::Border.
99
91
  #
100
92
  # @param attributes [Hash]
@@ -138,8 +130,6 @@ module Vedeu
138
130
  @vertical = @attributes[:vertical]
139
131
  @name = @attributes[:name]
140
132
  @repository = Vedeu.borders
141
- @colour = @attributes[:colour]
142
- @style = @attributes[:style]
143
133
  end
144
134
 
145
135
  # @return [Fixnum]
@@ -231,6 +221,13 @@ module Vedeu
231
221
  top_or_bottom('top')
232
222
  end
233
223
 
224
+ # The parent of a border is always an interface.
225
+ #
226
+ # @return [Vedeu::Interface]
227
+ def parent
228
+ interface
229
+ end
230
+
234
231
  private
235
232
 
236
233
  # @param prefix [String]
@@ -361,7 +358,7 @@ module Vedeu
361
358
  bottom_left: "\x6D", # └ # \u2514
362
359
  bottom_right: "\x6A", # ┘ # \u2518
363
360
  client: nil,
364
- colour: {},
361
+ colour: nil,
365
362
  enabled: false,
366
363
  horizontal: "\x71", # ─ # \u2500
367
364
  name: '',
@@ -369,7 +366,7 @@ module Vedeu
369
366
  show_left: true,
370
367
  show_right: true,
371
368
  show_top: true,
372
- style: [],
369
+ style: nil,
373
370
  title: '',
374
371
  top_left: "\x6C", # ┌ # \u250C
375
372
  top_right: "\x6B", # ┐ # \u2510
@@ -122,8 +122,8 @@ module Vedeu
122
122
  # @return [Hash<Symbol => Boolean>]
123
123
  def defaults
124
124
  {
125
- clear_border: true,
126
- use_terminal_colours: true,
125
+ clear_border: false,
126
+ use_terminal_colours: false,
127
127
  }
128
128
  end
129
129
 
@@ -6,7 +6,8 @@ module Vedeu
6
6
  #
7
7
  # Vedeu uses HTML/CSS style notation (i.e. '#aadd00'), they can be used at the
8
8
  # stream level, the line level or for the whole interface. Terminals generally
9
- # support either 8, 16 or 256 colours, with few supporting full 24-bit colour.
9
+ # support either 8, 16 or 256 colours, with few supporting full 24-bit colour
10
+ # (see notes below).
10
11
  #
11
12
  # Vedeu attempts to detect the colour depth using the `$TERM` environment
12
13
  # variable.
@@ -17,6 +18,19 @@ module Vedeu
17
18
  # echo "export TERM=xterm-256color" >> ~/.bashrc
18
19
  # ```
19
20
  #
21
+ # Notes:
22
+ # Terminals which support the 24-bit colour mode include (but are not limited
23
+ # to): iTerm2 (OSX), Gnome Terminal (Linux).
24
+ #
25
+ # Setting your `$TERM` environment variable as above gets you up to 256
26
+ # colours, but if you then add the `colour_mode 16_777_216` configuration to
27
+ # your client application, it's really a hit and miss affair. iTerm2 renders
28
+ # all the colours correctly as does Gnome Terminal. Terminator (Linux) goes
29
+ # crazy though and defaults to 16 colours despite the `$TERM` setting. This
30
+ # area needs more work in Vedeu.
31
+ #
32
+ # @todo Fix colours in all terminals. (GL: 2015-04-13)
33
+ #
20
34
  class Colour
21
35
 
22
36
  # @!attribute [r] attributes
@@ -26,21 +40,27 @@ module Vedeu
26
40
  # @param value []
27
41
  # @return [Object]
28
42
  def self.coerce(value)
29
- if value.is_a?(self)
30
- value
43
+ return value if value.is_a?(self)
44
+ return new unless value.is_a?(Hash)
45
+ return new unless value[:colour] ||
46
+ value[:background] ||
47
+ value[:foreground]
31
48
 
32
- elsif value.is_a?(Hash)
33
- if value.key?(:colour) && value[:colour].is_a?(self)
34
- value
49
+ if value[:colour]
50
+ return value[:colour] if value[:colour].is_a?(self)
35
51
 
36
- elsif value.key?(:background) || value.key?(:foreground)
37
- new(value)
52
+ if value[:colour].is_a?(Hash) && (value[:colour][:background] ||
53
+ value[:colour][:foreground])
54
+ new(value[:colour])
38
55
 
39
56
  else
40
57
  new
41
58
 
42
59
  end
43
60
 
61
+ elsif value[:background] || value[:foreground]
62
+ new(value)
63
+
44
64
  else
45
65
  new
46
66
 
@@ -69,6 +89,7 @@ module Vedeu
69
89
  # @param value [String]
70
90
  # @return [String]
71
91
  def background=(value)
92
+ @attributes[:background] = value
72
93
  @background = Vedeu::Background.coerce(value)
73
94
  end
74
95
 
@@ -92,6 +113,7 @@ module Vedeu
92
113
  # @param value [String]
93
114
  # @return [String]
94
115
  def foreground=(value)
116
+ @attributes[:foreground] = value
95
117
  @foreground = Vedeu::Foreground.coerce(value)
96
118
  end
97
119
 
@@ -116,8 +116,9 @@ module Vedeu
116
116
 
117
117
  # Return the escape sequence to render a border character.
118
118
  #
119
- # @param block [Proc]
120
119
  # @return [String]
120
+ # @yieldreturn [void] The border character to wrap with border on and off
121
+ # escape sequences.
121
122
  def border
122
123
  return '' unless block_given?
123
124
 
@@ -16,22 +16,20 @@ module Vedeu
16
16
  end
17
17
  end
18
18
 
19
+ # @return [Vedeu::Background]
20
+ def background=(value)
21
+ attributes[:background] = value
22
+ colour.background = value
23
+ end
24
+
19
25
  # @return [Vedeu::Colour]
20
26
  def colour
21
- if @colour
22
- @colour ||= Vedeu::Colour.coerce(@colour)
23
-
24
- elsif parent && parent.colour
25
- @colour ||= Vedeu::Colour.coerce(parent.colour)
26
-
27
- else
28
- Vedeu::Colour.coerce(nil)
29
-
30
- end
27
+ @colour ||= Vedeu::Colour.coerce(_colour)
31
28
  end
32
29
 
33
30
  # @return [Vedeu::Colour]
34
31
  def colour=(value)
32
+ attributes[:colour] = value
35
33
  @colour = Vedeu::Colour.coerce(value)
36
34
  end
37
35
 
@@ -46,6 +44,12 @@ module Vedeu
46
44
  end
47
45
  end
48
46
 
47
+ # @return [Vedeu::Foreground]
48
+ def foreground=(value)
49
+ attributes[:foreground] = value
50
+ colour.foreground = value
51
+ end
52
+
49
53
  # @return [Vedeu::Background]
50
54
  def parent_background
51
55
  if parent_colour
@@ -80,16 +84,7 @@ module Vedeu
80
84
 
81
85
  # @return [Vedeu::Style]
82
86
  def style
83
- if @style
84
- @style ||= Vedeu::Style.coerce(@style)
85
-
86
- elsif parent && parent.style
87
- @style ||= Vedeu::Style.coerce(parent.style)
88
-
89
- else
90
- Vedeu::Style.coerce(nil)
91
-
92
- end
87
+ @style ||= Vedeu::Style.coerce(_style)
93
88
  end
94
89
 
95
90
  # @return [Vedeu::Style]
@@ -108,6 +103,17 @@ module Vedeu
108
103
 
109
104
  private
110
105
 
106
+ # @return [void]
107
+ def _colour
108
+ if attributes[:colour]
109
+ attributes[:colour]
110
+
111
+ elsif parent_colour
112
+ parent_colour
113
+
114
+ end
115
+ end
116
+
111
117
  # Renders the colour attributes of the receiver and yields (to then render
112
118
  # the styles).
113
119
  #
@@ -135,6 +141,17 @@ module Vedeu
135
141
  [style, yield].join
136
142
  end
137
143
 
144
+ # @return [void]
145
+ def _style
146
+ if attributes[:style]
147
+ attributes[:style]
148
+
149
+ elsif parent_style
150
+ parent_style
151
+
152
+ end
153
+ end
154
+
138
155
  end # Presentation
139
156
 
140
157
  end # Vedeu
@@ -1,3 +1,4 @@
1
+ require_relative 'escape_sequence_renderer'
1
2
  require_relative 'file_renderer'
2
3
  require_relative 'html_renderer'
3
4
  require_relative 'json_renderer'
@@ -0,0 +1,40 @@
1
+ module Vedeu
2
+
3
+ # A renderer which returns the escape sequence for each character.
4
+ #
5
+ class EscapeSequenceRenderer
6
+
7
+ # @param output [Array<Array<Vedeu::Char>>]
8
+ # @return [String]
9
+ def self.render(output)
10
+ new(output).render
11
+ end
12
+
13
+ # @param output [Array<Array<Vedeu::Char>>]
14
+ def initialize(output)
15
+ @output = output
16
+ end
17
+
18
+ # @return [String]
19
+ def render
20
+ Vedeu.log(type: :debug,
21
+ message: "Vedeu::EscapeSequenceRenderer:\n#{parsed}")
22
+
23
+ parsed
24
+ end
25
+
26
+ private
27
+
28
+ # @!attribute [r] output
29
+ # @return [Array<Array<Vedeu::Char>>]
30
+ attr_reader :output
31
+
32
+ def parsed
33
+ @parsed ||= Array(output).flatten.map do |char|
34
+ Esc.escape(char.to_s) + "\n"
35
+ end.join
36
+ end
37
+
38
+ end # EscapeSequenceRenderer
39
+
40
+ end # Vedeu
@@ -7,23 +7,27 @@ module Vedeu
7
7
  class FileRenderer
8
8
 
9
9
  # @param output [Array<Array<Vedeu::Char>>]
10
+ # @param options [Hash]
10
11
  # @return [String]
11
- def self.render(*output)
12
- new(*output).render
12
+ def self.render(output, options = {})
13
+ new(output, options).render
13
14
  end
14
15
 
15
16
  # Returns a new instance of Vedeu::FileRenderer.
16
17
  #
17
18
  # @param output [Array<Array<Vedeu::Char>>]
19
+ # @param options [Hash]
18
20
  # @return [Vedeu::FileRenderer]
19
- def initialize(*output)
21
+ def initialize(output, options = {})
20
22
  @output = output
21
- @options = {}
23
+ @options = options
22
24
  end
23
25
 
24
26
  # @return [String]
25
27
  def render
26
28
  File.open("/tmp/#{filename}", 'w') { |f| f.write(parsed) }
29
+
30
+ parsed
27
31
  end
28
32
 
29
33
  private
@@ -45,7 +49,7 @@ module Vedeu
45
49
 
46
50
  # @return [String]
47
51
  def parsed
48
- Vedeu::Compressor.new(output).render
52
+ @parsed ||= Vedeu::Compressor.new(output).render
49
53
  end
50
54
 
51
55
  # @return [Float]
@@ -38,7 +38,7 @@ module Vedeu
38
38
  def to_file(path = file_path)
39
39
  content = render
40
40
 
41
- File.open(path, 'w', 0644) { |file| file.write(content) }
41
+ File.open(path, 'w') { |file| file.write(content) }
42
42
 
43
43
  content
44
44
  end
@@ -83,21 +83,7 @@ module Vedeu
83
83
  # @return [void]
84
84
  def colour
85
85
  if options[:colour] || options[:background] || options[:foreground]
86
- attrs = if options[:colour] && options[:colour].is_a?(Hash)
87
- options[:colour]
88
-
89
- elsif options[:background] || options[:foreground]
90
- {
91
- background: options[:background],
92
- foreground: options[:foreground],
93
- }
94
-
95
- else
96
- {}
97
-
98
- end
99
-
100
- Vedeu::Colour.coerce(attrs)
86
+ Vedeu::Colour.coerce(options)
101
87
 
102
88
  else
103
89
  model.colour