vedeu 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +3 -0
- data/Rakefile +16 -7
- data/examples/borders_app.rb +58 -55
- data/lib/vedeu/api.rb +1 -1
- data/lib/vedeu/application.rb +25 -25
- data/lib/vedeu/bindings.rb +5 -7
- data/lib/vedeu/configuration/api.rb +0 -2
- data/lib/vedeu/configuration/cli.rb +0 -2
- data/lib/vedeu/configuration/configuration.rb +0 -2
- data/lib/vedeu/cursor/cursor.rb +0 -2
- data/lib/vedeu/debug.rb +2 -2
- data/lib/vedeu/distributed/server.rb +0 -2
- data/lib/vedeu/dsl/components/border.rb +15 -19
- data/lib/vedeu/dsl/components/geometry.rb +14 -18
- data/lib/vedeu/dsl/components/keymap.rb +28 -32
- data/lib/vedeu/dsl/composition.rb +27 -9
- data/lib/vedeu/events/all.rb +1 -0
- data/lib/vedeu/events/event.rb +6 -8
- data/lib/vedeu/events/events.rb +10 -0
- data/lib/vedeu/events/trigger.rb +6 -12
- data/lib/vedeu/geometry/grid.rb +0 -2
- data/lib/vedeu/geometry/position.rb +0 -2
- data/lib/vedeu/geometry/position_validator.rb +0 -14
- data/lib/vedeu/input/input.rb +0 -2
- data/lib/vedeu/models/collection.rb +0 -2
- data/lib/vedeu/models/focus.rb +0 -1
- data/lib/vedeu/models/geometry.rb +7 -3
- data/lib/vedeu/models/group.rb +0 -2
- data/lib/vedeu/models/menu.rb +23 -29
- data/lib/vedeu/models/model.rb +0 -2
- data/lib/vedeu/models/view/char.rb +14 -10
- data/lib/vedeu/models/view/composition.rb +7 -9
- data/lib/vedeu/models/view/interface.rb +0 -1
- data/lib/vedeu/models/view/line.rb +2 -3
- data/lib/vedeu/models/view/stream.rb +0 -3
- data/lib/vedeu/output/all.rb +1 -0
- data/lib/vedeu/output/background.rb +0 -2
- data/lib/vedeu/output/colour.rb +0 -2
- data/lib/vedeu/output/compositor.rb +0 -2
- data/lib/vedeu/output/foreground.rb +0 -2
- data/lib/vedeu/output/html_renderer.rb +6 -0
- data/lib/vedeu/output/index_position.rb +35 -0
- data/lib/vedeu/output/output.rb +3 -1
- data/lib/vedeu/output/position_index.rb +2 -2
- data/lib/vedeu/output/presentation.rb +0 -2
- data/lib/vedeu/output/style.rb +0 -1
- data/lib/vedeu/output/translator.rb +18 -20
- data/lib/vedeu/output/viewport.rb +76 -51
- data/lib/vedeu/output/virtual_terminal.rb +2 -1
- data/lib/vedeu/repositories/all.rb +4 -4
- data/lib/vedeu/repositories/repository.rb +0 -2
- data/lib/vedeu/support/coercions.rb +0 -2
- data/lib/vedeu/support/common.rb +0 -2
- data/lib/vedeu/support/esc.rb +0 -2
- data/lib/vedeu/support/log.rb +86 -3
- data/lib/vedeu/support/refresh.rb +0 -2
- data/lib/vedeu/support/sentence.rb +5 -9
- data/lib/vedeu/support/terminal.rb +0 -2
- data/lib/vedeu/support/trace.rb +0 -2
- data/lib/vedeu/support/visible.rb +1 -1
- data/test/lib/vedeu/configuration/api_test.rb +14 -0
- data/test/lib/vedeu/configuration/configuration_test.rb +10 -0
- data/test/lib/vedeu/distributed/server_test.rb +5 -0
- data/test/lib/vedeu/dsl/components/border_test.rb +7 -0
- data/test/lib/vedeu/dsl/components/geometry_test.rb +8 -3
- data/test/lib/vedeu/dsl/interface_test.rb +5 -0
- data/test/lib/vedeu/dsl/line_test.rb +4 -0
- data/test/lib/vedeu/dsl/shared/colour_test.rb +7 -7
- data/test/lib/vedeu/dsl/shared/style_test.rb +5 -2
- data/test/lib/vedeu/dsl/stream_test.rb +4 -1
- data/test/lib/vedeu/events/event_test.rb +6 -0
- data/test/lib/vedeu/geometry/bounding_area_test.rb +30 -30
- data/test/lib/vedeu/geometry/position_test.rb +5 -0
- data/test/lib/vedeu/models/view/char_test.rb +1 -14
- data/test/lib/vedeu/output/index_position_test.rb +64 -0
- data/test/lib/vedeu/output/style_test.rb +4 -0
- data/test/lib/vedeu/output/translator_test.rb +4 -0
- data/test/lib/vedeu/output/virtual_terminal_test.rb +2 -0
- data/test/lib/vedeu/output/wordwrap_test.rb +5 -0
- data/test/lib/vedeu/repositories/all_test.rb +3 -3
- data/test/lib/vedeu/repositories/repository_test.rb +8 -0
- data/test/lib/vedeu/support/console_test.rb +14 -0
- data/test/lib/vedeu/support/esc_test.rb +6 -0
- data/test/lib/vedeu/support/terminal_test.rb +13 -0
- data/vedeu.gemspec +4 -4
- metadata +12 -24
- data/test/integration/distributed_test.rb +0 -16
- data/test/integration/dsl/compositions_test.rb +0 -19
- data/test/integration/dsl/interfaces_test.rb +0 -193
- data/test/integration/dsl/keymaps_test.rb +0 -30
- data/test/integration/dsl/lines_test.rb +0 -104
- data/test/integration/dsl/menus_test.rb +0 -59
- data/test/integration/dsl/streams_test.rb +0 -103
- data/test/integration/dsl/views_test.rb +0 -45
data/lib/vedeu/models/group.rb
CHANGED
data/lib/vedeu/models/menu.rb
CHANGED
@@ -5,8 +5,6 @@ module Vedeu
|
|
5
5
|
# Converts the collection passed into a list of menu items which can be
|
6
6
|
# navigated using the instance methods or events provided.
|
7
7
|
#
|
8
|
-
# @api private
|
9
|
-
#
|
10
8
|
class Menu
|
11
9
|
|
12
10
|
include Vedeu::Model
|
@@ -25,34 +23,30 @@ module Vedeu
|
|
25
23
|
# @return [Fixnum]
|
26
24
|
attr_accessor :selected
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
def menu(name = '', &block)
|
51
|
-
fail InvalidSyntax, 'block not given' unless block_given?
|
52
|
-
|
53
|
-
build({ name: name }, &block).store
|
54
|
-
end
|
26
|
+
# Register a menu by name which will display a collection of items for
|
27
|
+
# your users to select; and provide interactivity within your application.
|
28
|
+
#
|
29
|
+
# @param name [String] The name of the menu. Used to reference the
|
30
|
+
# menu throughout your application's execution lifetime.
|
31
|
+
# @param block [Proc] A set of attributes which define the features of the
|
32
|
+
# menu. See {Vedeu::DSL::Menu#items} and {Vedeu::DSL::Menu#name}.
|
33
|
+
#
|
34
|
+
# @example
|
35
|
+
# Vedeu.menu 'my_interface' do
|
36
|
+
# items [:item_1, :item_2, :item_3]
|
37
|
+
# ...
|
38
|
+
#
|
39
|
+
# Vedeu.menu do
|
40
|
+
# name 'menus_must_have_a_name'
|
41
|
+
# items Track.all_my_favourites
|
42
|
+
# ...
|
43
|
+
#
|
44
|
+
# @raise [InvalidSyntax] The required block was not given.
|
45
|
+
# @return [API::Menu]
|
46
|
+
def self.menu(name = '', &block)
|
47
|
+
fail InvalidSyntax, 'block not given' unless block_given?
|
55
48
|
|
49
|
+
build({ name: name }, &block).store
|
56
50
|
end
|
57
51
|
|
58
52
|
# Returns a new instance of Menu.
|
data/lib/vedeu/models/model.rb
CHANGED
@@ -9,15 +9,14 @@ module Vedeu
|
|
9
9
|
# Though a multi-character String can be passed as a value, only the first
|
10
10
|
# character is returned in the escape sequence.
|
11
11
|
#
|
12
|
-
# @api private
|
13
|
-
#
|
14
12
|
class Char
|
15
13
|
|
16
14
|
include Vedeu::Presentation
|
17
15
|
|
18
16
|
attr_accessor :border,
|
19
|
-
:parent
|
20
|
-
|
17
|
+
:parent
|
18
|
+
|
19
|
+
attr_reader :value
|
21
20
|
|
22
21
|
# Returns a new instance of Char.
|
23
22
|
#
|
@@ -35,7 +34,6 @@ module Vedeu
|
|
35
34
|
@border = @attributes[:border]
|
36
35
|
@colour = @attributes[:colour]
|
37
36
|
@parent = @attributes[:parent]
|
38
|
-
@position = Vedeu::Position.coerce(@attributes[:position])
|
39
37
|
@style = @attributes[:style]
|
40
38
|
@value = @attributes[:value]
|
41
39
|
end
|
@@ -52,11 +50,15 @@ module Vedeu
|
|
52
50
|
self.class == other.class && value == other.value
|
53
51
|
end
|
54
52
|
|
55
|
-
# @return [
|
56
|
-
def
|
57
|
-
|
53
|
+
# @return [Vedeu::Position]
|
54
|
+
def position
|
55
|
+
@position ||= Vedeu::Position.coerce(attributes[:position])
|
56
|
+
end
|
58
57
|
|
59
|
-
|
58
|
+
# @param value [Vedeu::Position]
|
59
|
+
# @return [Vedeu::Position]
|
60
|
+
def position=(value)
|
61
|
+
@position = Vedeu::Position.coerce(value)
|
60
62
|
end
|
61
63
|
|
62
64
|
# @return [Fixnum|NilClass]
|
@@ -76,6 +78,8 @@ module Vedeu
|
|
76
78
|
|
77
79
|
private
|
78
80
|
|
81
|
+
attr_reader :attributes
|
82
|
+
|
79
83
|
# The default values for a new instance of this class.
|
80
84
|
#
|
81
85
|
# @return [Hash]
|
@@ -86,7 +90,7 @@ module Vedeu
|
|
86
90
|
parent: nil,
|
87
91
|
position: nil,
|
88
92
|
style: nil,
|
89
|
-
value:
|
93
|
+
value: '',
|
90
94
|
}
|
91
95
|
end
|
92
96
|
|
@@ -10,30 +10,27 @@ module Vedeu
|
|
10
10
|
|
11
11
|
# A composition is a collection of interfaces.
|
12
12
|
#
|
13
|
-
# @api private
|
14
|
-
#
|
15
13
|
class Composition
|
16
14
|
|
17
|
-
include Vedeu::Presentation
|
18
15
|
include Vedeu::Model
|
16
|
+
include Vedeu::Presentation
|
19
17
|
|
20
18
|
collection Vedeu::Interfaces
|
21
19
|
member Vedeu::Interface
|
22
20
|
|
23
|
-
attr_reader :interfaces
|
24
|
-
alias_method :value, :interfaces
|
25
|
-
|
26
21
|
# Returns a new instance of Composition.
|
27
22
|
#
|
28
23
|
# @param attributes [Hash]
|
29
|
-
# @option attributes colour []
|
24
|
+
# @option attributes colour [Vedeu::Colour]
|
30
25
|
# @option attributes interfaces []
|
31
|
-
# @option attributes style []
|
26
|
+
# @option attributes style [Vedeu::Style]
|
32
27
|
# @return [Composition]
|
33
28
|
def initialize(attributes = {})
|
34
29
|
@attributes = defaults.merge!(attributes)
|
35
|
-
|
30
|
+
|
36
31
|
@colour = @attributes[:colour]
|
32
|
+
@interfaces = @attributes[:interfaces]
|
33
|
+
@repository = Vedeu.interfaces
|
37
34
|
@style = @attributes[:style]
|
38
35
|
end
|
39
36
|
|
@@ -47,6 +44,7 @@ module Vedeu
|
|
47
44
|
def interfaces
|
48
45
|
collection.coerce(@interfaces, self)
|
49
46
|
end
|
47
|
+
alias_method :value, :interfaces
|
50
48
|
|
51
49
|
private
|
52
50
|
|
@@ -8,8 +8,6 @@ module Vedeu
|
|
8
8
|
# {Vedeu::Stream} objects. A line's width is determined by the
|
9
9
|
# {Vedeu::Interface} it belongs to.
|
10
10
|
#
|
11
|
-
# @api private
|
12
|
-
#
|
13
11
|
class Line
|
14
12
|
|
15
13
|
include Vedeu::Model
|
@@ -25,11 +23,12 @@ module Vedeu
|
|
25
23
|
|
26
24
|
# Returns a new instance of Line.
|
27
25
|
#
|
26
|
+
# @param attributes [Hash]
|
28
27
|
# @option attributes streams [Vedeu::Streams]
|
29
28
|
# @option attributes parent [Vedeu::Interface]
|
30
29
|
# @option attributes colour [Vedeu::Colour]
|
31
30
|
# @option attributes style [Vedeu::Style]
|
32
|
-
# @return [Line]
|
31
|
+
# @return [Vedeu::Line]
|
33
32
|
def initialize(attributes = {})
|
34
33
|
@attributes = defaults.merge!(attributes)
|
35
34
|
@colour = @attributes[:colour]
|
@@ -7,8 +7,6 @@ module Vedeu
|
|
7
7
|
# {Vedeu::Line} which you wish to colour and style independently of the other
|
8
8
|
# characters in that line.
|
9
9
|
#
|
10
|
-
# @api private
|
11
|
-
#
|
12
10
|
class Stream
|
13
11
|
|
14
12
|
include Vedeu::Model
|
@@ -31,7 +29,6 @@ module Vedeu
|
|
31
29
|
# @option attributes parent [Vedeu::Line]
|
32
30
|
# @option attributes colour [Vedeu::Colour]
|
33
31
|
# @option attributes style [Vedeu::Style]
|
34
|
-
# @option attributes client [Object]
|
35
32
|
# @return [Vedeu::Stream]
|
36
33
|
def initialize(attributes = {})
|
37
34
|
@attributes = defaults.merge!(attributes)
|
data/lib/vedeu/output/all.rb
CHANGED
@@ -9,6 +9,7 @@ require 'vedeu/output/compositor'
|
|
9
9
|
require 'vedeu/output/presentation'
|
10
10
|
require 'vedeu/output/style'
|
11
11
|
require 'vedeu/output/position_index'
|
12
|
+
require 'vedeu/output/index_position'
|
12
13
|
require 'vedeu/output/virtual_buffer'
|
13
14
|
require 'vedeu/output/html_char'
|
14
15
|
require 'vedeu/output/html_renderer'
|
data/lib/vedeu/output/colour.rb
CHANGED
@@ -9,8 +9,6 @@ module Vedeu
|
|
9
9
|
# Combines stored interface layout/geometry with an interface view/buffer
|
10
10
|
# to create a single view to be sent to the terminal for output.
|
11
11
|
#
|
12
|
-
# @api private
|
13
|
-
#
|
14
12
|
class Compositor
|
15
13
|
|
16
14
|
# Convenience method to initialize a new Compositor and call its {#compose}
|
@@ -8,6 +8,12 @@ module Vedeu
|
|
8
8
|
new(output).render
|
9
9
|
end
|
10
10
|
|
11
|
+
# @param output [Array<Array<Vedeu::Char>>]
|
12
|
+
# @return [String]
|
13
|
+
def self.to_file(output)
|
14
|
+
new(output).to_file
|
15
|
+
end
|
16
|
+
|
11
17
|
# @param output [Array<Array<Vedeu::Char>>]
|
12
18
|
# @return [Vedeu::HTMLRenderer]
|
13
19
|
def initialize(output)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Vedeu
|
2
|
+
|
3
|
+
# Converts an index into a position for the terminal.
|
4
|
+
#
|
5
|
+
class IndexPosition
|
6
|
+
|
7
|
+
attr_reader :y,
|
8
|
+
:x
|
9
|
+
|
10
|
+
alias_method :first, :y
|
11
|
+
alias_method :last, :x
|
12
|
+
|
13
|
+
# @param y [Fixnum]
|
14
|
+
# @param x [Fixnum]
|
15
|
+
# @return [Array]
|
16
|
+
def self.[](y, x)
|
17
|
+
new(y, x).[]
|
18
|
+
end
|
19
|
+
|
20
|
+
# @param y [Fixnum]
|
21
|
+
# @param x [Fixnum]
|
22
|
+
# @return [Vedeu::IndexPosition]
|
23
|
+
def initialize(y, x)
|
24
|
+
@y = (y <= 0) ? 1 : (y + 1)
|
25
|
+
@x = (x <= 0) ? 1 : (x + 1)
|
26
|
+
end
|
27
|
+
|
28
|
+
# @return [Array]
|
29
|
+
def []
|
30
|
+
[y, x]
|
31
|
+
end
|
32
|
+
|
33
|
+
end # IndexPosition
|
34
|
+
|
35
|
+
end # Vedeu
|
data/lib/vedeu/output/output.rb
CHANGED
@@ -27,6 +27,8 @@ module Vedeu
|
|
27
27
|
def render
|
28
28
|
if Vedeu::Configuration.drb?
|
29
29
|
Vedeu.trigger(:_drb_store_output_, virtual_view)
|
30
|
+
|
31
|
+
HTMLRenderer.to_file(VirtualBuffer.retrieve)
|
30
32
|
end
|
31
33
|
|
32
34
|
Terminal.output(Renderer.render(virtual_view, interface.cursor))
|
@@ -73,7 +75,7 @@ module Vedeu
|
|
73
75
|
viewport.each_with_index do |line, iy|
|
74
76
|
row = []
|
75
77
|
line.each_with_index do |char, ix|
|
76
|
-
row << if char.is_a?(Vedeu::Char) && char.
|
78
|
+
row << if char.is_a?(Vedeu::Char) && (char.x != ix || char.y != iy)
|
77
79
|
char.position = origin(iy, ix)
|
78
80
|
char
|
79
81
|
|
data/lib/vedeu/output/style.rb
CHANGED
@@ -21,8 +21,6 @@ module Vedeu
|
|
21
21
|
# a 24-bit representation.
|
22
22
|
#
|
23
23
|
# @todo More documentation required (create a fancy chart!)
|
24
|
-
# @api private
|
25
|
-
#
|
26
24
|
class Translator
|
27
25
|
|
28
26
|
include Vedeu::Coercions
|
@@ -52,14 +50,14 @@ module Vedeu
|
|
52
50
|
if no_colour?
|
53
51
|
''
|
54
52
|
|
55
|
-
elsif
|
56
|
-
|
53
|
+
elsif rgb?
|
54
|
+
rgb
|
57
55
|
|
58
56
|
elsif numbered?
|
59
57
|
numbered
|
60
58
|
|
61
|
-
elsif
|
62
|
-
|
59
|
+
elsif named?
|
60
|
+
named
|
63
61
|
|
64
62
|
else
|
65
63
|
''
|
@@ -124,6 +122,20 @@ module Vedeu
|
|
124
122
|
[numbered_prefix, css_to_numbered, 'm'].join
|
125
123
|
end
|
126
124
|
|
125
|
+
# Returns a boolean indicated whether the colour is an HTML/CSS colour.
|
126
|
+
#
|
127
|
+
# @return [Boolean]
|
128
|
+
def rgb?
|
129
|
+
colour.is_a?(String) && valid_rgb?
|
130
|
+
end
|
131
|
+
|
132
|
+
# Returns a boolean indicated whether the colour is a valid HTML/CSS colour.
|
133
|
+
#
|
134
|
+
# @return [Boolean]
|
135
|
+
def valid_rgb?
|
136
|
+
!!(colour =~ /^#([A-Fa-f0-9]{6})$/)
|
137
|
+
end
|
138
|
+
|
127
139
|
# Returns an escape sequence.
|
128
140
|
#
|
129
141
|
# @return [String]
|
@@ -145,20 +157,6 @@ module Vedeu
|
|
145
157
|
colour >= 0 && colour <= 255
|
146
158
|
end
|
147
159
|
|
148
|
-
# Returns a boolean indicated whether the colour is an HTML/CSS colour.
|
149
|
-
#
|
150
|
-
# @return [Boolean]
|
151
|
-
def rgb?
|
152
|
-
colour.is_a?(String) && valid_rgb?
|
153
|
-
end
|
154
|
-
|
155
|
-
# Returns a boolean indicated whether the colour is a valid HTML/CSS colour.
|
156
|
-
#
|
157
|
-
# @return [Boolean]
|
158
|
-
def valid_rgb?
|
159
|
-
!!(colour =~ /^#([A-Fa-f0-9]{6})$/)
|
160
|
-
end
|
161
|
-
|
162
160
|
# Returns a collection of converted HTML/CSS octets as their decimal
|
163
161
|
# equivalents.
|
164
162
|
#
|