vedeu 0.1.12 → 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -0
- data/lib/vedeu.rb +12 -12
- data/lib/vedeu/api/api.rb +23 -18
- data/lib/vedeu/api/events.rb +1 -1
- data/lib/vedeu/api/interface.rb +29 -19
- data/lib/vedeu/api/line.rb +1 -34
- data/lib/vedeu/api/stream.rb +1 -34
- data/lib/vedeu/models/attributes/attributes.rb +7 -7
- data/lib/vedeu/models/attributes/colour_translator.rb +45 -7
- data/lib/vedeu/models/colour.rb +4 -2
- data/lib/vedeu/models/composition.rb +9 -9
- data/lib/vedeu/models/interface.rb +1 -1
- data/lib/vedeu/models/line.rb +17 -3
- data/lib/vedeu/{api → models}/store.rb +0 -2
- data/lib/vedeu/models/stream.rb +17 -3
- data/lib/vedeu/output/buffers.rb +14 -8
- data/lib/vedeu/output/view.rb +7 -3
- data/lib/vedeu/support/esc.rb +1 -14
- data/lib/vedeu/support/position.rb +31 -0
- data/lib/vedeu/support/terminal.rb +4 -0
- data/test/lib/vedeu/api/api_test.rb +21 -0
- data/test/lib/vedeu/api/interface_test.rb +765 -51
- data/test/lib/vedeu/configuration_test.rb +5 -0
- data/test/lib/vedeu/models/composition_test.rb +1 -1
- data/test/lib/vedeu/models/interface_test.rb +59 -17
- data/test/lib/vedeu/{api → models}/store_test.rb +12 -3
- data/test/lib/vedeu/output/clear_test.rb +1 -1
- data/test/lib/vedeu/output/render_test.rb +1 -1
- data/test/lib/vedeu/output/view_test.rb +17 -0
- data/test/lib/vedeu/support/esc_test.rb +0 -10
- data/test/lib/vedeu/support/position_test.rb +19 -0
- data/test/support/colour_test.sh +100 -0
- data/test/{stats.sh → support/stats.sh} +0 -0
- data/vedeu.gemspec +1 -1
- metadata +16 -10
- data/lib/vedeu/api/view.rb +0 -45
- data/test/lib/vedeu/api/view_test.rb +0 -565
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5bc23985fc8270da6cebe20612c4aaa02967a07f
|
4
|
+
data.tar.gz: bf6587149152e3111183fe10abe958376a024872
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd0458ce9a0b1e2b93788a4adef0439e7946db8a5e4e508ce68a662d885dd726b900692af0b8dfd385f24ddb78be19a0ddf5ce628c165243de0672a499a82cc8
|
7
|
+
data.tar.gz: 6a56e31aba151c295f6989e43947a1e0e6b7571cd5c65d8b17077abf3c15eee7d3fa558559f9e72db63421e1afedb5aeba46eb7b5052b937a49efe5191cb78c0
|
data/README.md
CHANGED
@@ -6,6 +6,13 @@
|
|
6
6
|
Vedeu is my attempt at creating a terminal based application framework without the need for Ncurses. I've tried to make Vedeu as simple and flexible as possible.
|
7
7
|
|
8
8
|
|
9
|
+
## Requirements
|
10
|
+
|
11
|
+
Vedeu has been built on MacOSX 10.9 (Mavericks) with Ruby v2.1.2.
|
12
|
+
|
13
|
+
Note: You may have trouble running Vedeu with Windows installations.
|
14
|
+
|
15
|
+
|
9
16
|
## Installation
|
10
17
|
|
11
18
|
Add this line to your application's Gemfile:
|
data/lib/vedeu.rb
CHANGED
@@ -13,6 +13,17 @@ require 'io/console'
|
|
13
13
|
require 'logger'
|
14
14
|
require 'optparse'
|
15
15
|
|
16
|
+
require 'vedeu/models/attributes/attributes'
|
17
|
+
require 'vedeu/models/attributes/colour_translator'
|
18
|
+
require 'vedeu/models/composition'
|
19
|
+
require 'vedeu/support/terminal'
|
20
|
+
require 'vedeu/models/geometry'
|
21
|
+
require 'vedeu/models/colour'
|
22
|
+
require 'vedeu/models/interface'
|
23
|
+
require 'vedeu/models/line'
|
24
|
+
require 'vedeu/models/store'
|
25
|
+
require 'vedeu/models/stream'
|
26
|
+
|
16
27
|
require 'vedeu/api/api'
|
17
28
|
require 'vedeu/api/events'
|
18
29
|
require 'vedeu/api/grid'
|
@@ -20,29 +31,18 @@ require 'vedeu/api/helpers'
|
|
20
31
|
require 'vedeu/api/interface'
|
21
32
|
require 'vedeu/api/line'
|
22
33
|
require 'vedeu/api/log'
|
23
|
-
require 'vedeu/api/store'
|
24
34
|
require 'vedeu/api/stream'
|
25
|
-
require 'vedeu/api/view'
|
26
35
|
|
27
36
|
require 'vedeu/application'
|
28
37
|
require 'vedeu/configuration'
|
29
38
|
require 'vedeu/launcher'
|
30
39
|
|
31
|
-
require 'vedeu/models/attributes/attributes'
|
32
|
-
require 'vedeu/models/attributes/colour_translator'
|
33
|
-
require 'vedeu/models/composition'
|
34
|
-
require 'vedeu/support/terminal'
|
35
|
-
require 'vedeu/models/geometry'
|
36
|
-
require 'vedeu/models/colour'
|
37
|
-
require 'vedeu/models/interface'
|
38
|
-
require 'vedeu/models/line'
|
39
|
-
require 'vedeu/models/stream'
|
40
|
-
|
41
40
|
require 'vedeu/output/buffers'
|
42
41
|
require 'vedeu/output/clear'
|
43
42
|
require 'vedeu/output/render'
|
44
43
|
require 'vedeu/output/view'
|
45
44
|
|
45
|
+
require 'vedeu/support/position'
|
46
46
|
require 'vedeu/support/esc'
|
47
47
|
require 'vedeu/support/input'
|
48
48
|
require 'vedeu/support/menu'
|
data/lib/vedeu/api/api.rb
CHANGED
@@ -6,42 +6,47 @@ module Vedeu
|
|
6
6
|
|
7
7
|
def events
|
8
8
|
@events ||= API::Events.new do
|
9
|
-
event(:
|
10
|
-
event(:
|
11
|
-
event(:_mode_switch_) { fail ModeSwitch
|
12
|
-
event(:_clear_) { Terminal.
|
13
|
-
event(:_refresh_) { Buffers.refresh_all
|
14
|
-
|
15
|
-
event(:_keypress_) do |key|
|
16
|
-
trigger(:key, key)
|
17
|
-
trigger(:_log_, (' ' * 42) + "key: #{key}")
|
18
|
-
trigger(:_mode_switch_) if key == :escape
|
19
|
-
end
|
9
|
+
event(:_log_) { |msg| Vedeu.log(msg) }
|
10
|
+
event(:_exit_) { fail StopIteration }
|
11
|
+
event(:_mode_switch_) { fail ModeSwitch }
|
12
|
+
event(:_clear_) { Terminal.clear_screen }
|
13
|
+
event(:_refresh_) { Buffers.refresh_all }
|
14
|
+
event(:_keypress_) { |key| Vedeu.keypress(key) }
|
20
15
|
end
|
21
16
|
end
|
22
17
|
|
18
|
+
def height
|
19
|
+
Terminal.height
|
20
|
+
end
|
21
|
+
|
23
22
|
def interface(name, &block)
|
24
|
-
API::Interface.
|
23
|
+
API::Interface.define({ name: name }, &block)
|
24
|
+
end
|
25
|
+
|
26
|
+
def keypress(key)
|
27
|
+
trigger(:key, key)
|
28
|
+
trigger(:_log_, (' ' * 42) + "key: #{key}")
|
29
|
+
trigger(:_mode_switch_) if key == :escape
|
25
30
|
end
|
26
31
|
|
27
32
|
def log(message)
|
28
33
|
API::Log.logger.debug(message)
|
29
34
|
end
|
30
35
|
|
31
|
-
# def render(object = nil)
|
32
|
-
# Vedeu::View.render(object)
|
33
|
-
# end
|
34
|
-
|
35
36
|
def trigger(name, *args)
|
36
37
|
Vedeu.events.trigger(name, *args)
|
37
38
|
end
|
38
39
|
|
39
40
|
def use(name)
|
40
|
-
Vedeu::Interface.new(Store.query(name))
|
41
|
+
Vedeu::Interface.new(Vedeu::Store.query(name))
|
41
42
|
end
|
42
43
|
|
43
44
|
def view(name, &block)
|
44
|
-
API::
|
45
|
+
API::Interface.build({ name: name }, &block)
|
46
|
+
end
|
47
|
+
|
48
|
+
def width
|
49
|
+
Terminal.width
|
45
50
|
end
|
46
51
|
end
|
47
52
|
|
data/lib/vedeu/api/events.rb
CHANGED
data/lib/vedeu/api/interface.rb
CHANGED
@@ -5,35 +5,45 @@ module Vedeu
|
|
5
5
|
YOutOfBounds = Class.new(StandardError)
|
6
6
|
|
7
7
|
module API
|
8
|
-
class Interface
|
9
|
-
def self.
|
10
|
-
new(
|
8
|
+
class Interface < Vedeu::Interface
|
9
|
+
def self.build(attributes = {}, &block)
|
10
|
+
new(attributes, &block).attributes
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
|
13
|
+
def self.define(attributes = {}, &block)
|
14
|
+
new(attributes).define(&block)
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
|
17
|
+
def initialize(attributes = {}, &block)
|
18
|
+
@attributes = attributes
|
19
19
|
|
20
|
-
|
20
|
+
if block_given?
|
21
|
+
@self_before_instance_eval = eval('self', block.binding)
|
21
22
|
|
22
|
-
|
23
|
+
instance_eval(&block)
|
24
|
+
end
|
25
|
+
end
|
23
26
|
|
27
|
+
def define(&block)
|
28
|
+
instance_eval(&block) if block_given?
|
29
|
+
stored_attributes = Vedeu::Store.create(attributes)
|
30
|
+
interface = Vedeu::Interface.new(stored_attributes)
|
24
31
|
Vedeu::Buffers.create(interface)
|
25
|
-
|
26
32
|
interface
|
27
33
|
end
|
28
34
|
|
29
|
-
|
30
|
-
|
31
|
-
|
35
|
+
def line(&block)
|
36
|
+
attributes[:lines] << Line.build(&block)
|
37
|
+
end
|
32
38
|
|
33
39
|
def use(value)
|
34
40
|
Vedeu.use(value)
|
35
41
|
end
|
36
42
|
|
43
|
+
def colour(value)
|
44
|
+
attributes[:colour] = value
|
45
|
+
end
|
46
|
+
|
37
47
|
def cursor(value)
|
38
48
|
attributes[:cursor] = value
|
39
49
|
end
|
@@ -74,6 +84,10 @@ module Vedeu
|
|
74
84
|
attributes[:geometry][:centred] = value
|
75
85
|
end
|
76
86
|
|
87
|
+
def style(value)
|
88
|
+
attributes[:style] = value
|
89
|
+
end
|
90
|
+
|
77
91
|
def y_out_of_bounds?(value)
|
78
92
|
value < 1 || value > Terminal.height
|
79
93
|
end
|
@@ -82,12 +96,8 @@ module Vedeu
|
|
82
96
|
value < 1 || value > Terminal.width
|
83
97
|
end
|
84
98
|
|
85
|
-
def method_missing(
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
def attributes
|
90
|
-
@attributes ||= { name: name, geometry: {} }
|
99
|
+
def method_missing(method, *args, &block)
|
100
|
+
@self_before_instance_eval.send(method, *args, &block)
|
91
101
|
end
|
92
102
|
end
|
93
103
|
end
|
data/lib/vedeu/api/line.rb
CHANGED
@@ -1,23 +1,8 @@
|
|
1
1
|
module Vedeu
|
2
2
|
module API
|
3
|
-
class Line
|
3
|
+
class Line < Vedeu::Line
|
4
4
|
include Helpers
|
5
5
|
|
6
|
-
def self.build(attributes = {}, &block)
|
7
|
-
new(attributes, &block).build
|
8
|
-
end
|
9
|
-
|
10
|
-
def initialize(attributes = {}, &block)
|
11
|
-
@attributes = attributes
|
12
|
-
@self_before_instance_eval = eval('self', block.binding)
|
13
|
-
|
14
|
-
instance_eval(&block)
|
15
|
-
end
|
16
|
-
|
17
|
-
def build
|
18
|
-
attributes
|
19
|
-
end
|
20
|
-
|
21
6
|
def stream(&block)
|
22
7
|
attributes[:streams] << API::Stream.build(&block)
|
23
8
|
end
|
@@ -37,24 +22,6 @@ module Vedeu
|
|
37
22
|
colour: { background: value }
|
38
23
|
}, &block)
|
39
24
|
end
|
40
|
-
|
41
|
-
def attributes
|
42
|
-
@_attributes ||= defaults.merge!(@attributes)
|
43
|
-
end
|
44
|
-
|
45
|
-
def defaults
|
46
|
-
{
|
47
|
-
colour: {},
|
48
|
-
style: [],
|
49
|
-
streams: []
|
50
|
-
}
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
|
55
|
-
def method_missing(method, *args, &block)
|
56
|
-
@self_before_instance_eval.send method, *args, &block
|
57
|
-
end
|
58
25
|
end
|
59
26
|
end
|
60
27
|
end
|
data/lib/vedeu/api/stream.rb
CHANGED
@@ -1,23 +1,8 @@
|
|
1
1
|
module Vedeu
|
2
2
|
module API
|
3
|
-
class Stream
|
3
|
+
class Stream < Vedeu::Stream
|
4
4
|
include Helpers
|
5
5
|
|
6
|
-
def self.build(attributes = {}, &block)
|
7
|
-
new(attributes, &block).build
|
8
|
-
end
|
9
|
-
|
10
|
-
def initialize(attributes = {}, &block)
|
11
|
-
@attributes = attributes
|
12
|
-
@self_before_instance_eval = eval('self', block.binding)
|
13
|
-
|
14
|
-
instance_eval(&block)
|
15
|
-
end
|
16
|
-
|
17
|
-
def build
|
18
|
-
attributes
|
19
|
-
end
|
20
|
-
|
21
6
|
def align(value)
|
22
7
|
attributes[:align] = value
|
23
8
|
end
|
@@ -29,24 +14,6 @@ module Vedeu
|
|
29
14
|
def width(value)
|
30
15
|
attributes[:width] = value
|
31
16
|
end
|
32
|
-
|
33
|
-
def attributes
|
34
|
-
@_attributes ||= defaults.merge!(@attributes)
|
35
|
-
end
|
36
|
-
|
37
|
-
def defaults
|
38
|
-
{
|
39
|
-
colour: {},
|
40
|
-
style: [],
|
41
|
-
text: ''
|
42
|
-
}
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def method_missing(method, *args, &block)
|
48
|
-
@self_before_instance_eval.send method, *args, &block
|
49
|
-
end
|
50
17
|
end
|
51
18
|
end
|
52
19
|
end
|
@@ -2,15 +2,15 @@ module Vedeu
|
|
2
2
|
module Attributes
|
3
3
|
extend self
|
4
4
|
|
5
|
-
def coercer(
|
6
|
-
return [] if
|
5
|
+
def coercer(values, model, key)
|
6
|
+
return [] if values.nil? || values.empty?
|
7
7
|
|
8
|
-
[
|
9
|
-
if
|
10
|
-
|
8
|
+
[values].flatten.map do |value|
|
9
|
+
if value.is_a?(model)
|
10
|
+
value
|
11
11
|
|
12
12
|
else
|
13
|
-
model.new(
|
13
|
+
model.new(value)
|
14
14
|
|
15
15
|
end
|
16
16
|
end
|
@@ -19,7 +19,7 @@ module Vedeu
|
|
19
19
|
def coerce_styles(values)
|
20
20
|
return '' if values.nil? || values.empty?
|
21
21
|
|
22
|
-
Array(values).flatten.map { |
|
22
|
+
Array(values).flatten.map { |value| Esc.string(value) }.join
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -1,19 +1,34 @@
|
|
1
1
|
module Vedeu
|
2
2
|
class ColourTranslator
|
3
|
-
def initialize(html_colour = '')
|
3
|
+
def initialize(html_colour = '', options = {})
|
4
4
|
@html_colour = html_colour
|
5
|
+
@options = options
|
5
6
|
end
|
6
7
|
|
7
8
|
def background
|
8
9
|
return '' unless valid?
|
9
10
|
|
10
|
-
|
11
|
+
if truecolor?
|
12
|
+
r, g, b = translate
|
13
|
+
["\e[48;2;", r, ';', g, ';', b, 'm'].join
|
14
|
+
|
15
|
+
else
|
16
|
+
["\e[48;5;", translate, 'm'].join
|
17
|
+
|
18
|
+
end
|
11
19
|
end
|
12
20
|
|
13
21
|
def foreground
|
14
22
|
return '' unless valid?
|
15
23
|
|
16
|
-
|
24
|
+
if truecolor?
|
25
|
+
r, g, b = translate
|
26
|
+
["\e[38;2;", r, ';', g, ';', b, 'm'].join
|
27
|
+
|
28
|
+
else
|
29
|
+
["\e[38;5;", translate, 'm'].join
|
30
|
+
|
31
|
+
end
|
17
32
|
end
|
18
33
|
|
19
34
|
private
|
@@ -21,19 +36,28 @@ module Vedeu
|
|
21
36
|
attr_reader :html_colour
|
22
37
|
|
23
38
|
def translate
|
24
|
-
|
39
|
+
if truecolor?
|
40
|
+
[red, green, blue]
|
41
|
+
else
|
42
|
+
[
|
43
|
+
16,
|
44
|
+
((red / 51) * 36),
|
45
|
+
((green / 51) * 6),
|
46
|
+
((blue / 51) * 1)
|
47
|
+
].inject(:+)
|
48
|
+
end
|
25
49
|
end
|
26
50
|
|
27
51
|
def red
|
28
|
-
|
52
|
+
html_colour[1..2].to_i(16)
|
29
53
|
end
|
30
54
|
|
31
55
|
def green
|
32
|
-
|
56
|
+
html_colour[3..4].to_i(16)
|
33
57
|
end
|
34
58
|
|
35
59
|
def blue
|
36
|
-
|
60
|
+
html_colour[5..6].to_i(16)
|
37
61
|
end
|
38
62
|
|
39
63
|
def valid?
|
@@ -53,5 +77,19 @@ module Vedeu
|
|
53
77
|
def valid_format?
|
54
78
|
html_colour =~ /^#([A-Fa-f0-9]{6})$/
|
55
79
|
end
|
80
|
+
|
81
|
+
def truecolor?
|
82
|
+
options.fetch(:truecolor)
|
83
|
+
end
|
84
|
+
|
85
|
+
def options
|
86
|
+
defaults.merge!(@options)
|
87
|
+
end
|
88
|
+
|
89
|
+
def defaults
|
90
|
+
{
|
91
|
+
truecolor: false
|
92
|
+
}
|
93
|
+
end
|
56
94
|
end
|
57
95
|
end
|