vedeu 0.5.8 → 0.5.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Dockerfile +3 -1
- data/docs/getting_started.md +6 -3
- data/lib/vedeu/all.rb +6 -3
- data/lib/vedeu/borders/border.rb +7 -10
- data/lib/vedeu/cli/generator/application.rb +19 -34
- data/lib/vedeu/cli/generator/helpers.rb +58 -4
- data/lib/vedeu/colours/colour_translator.rb +2 -6
- data/lib/vedeu/esc/actions.rb +52 -0
- data/lib/vedeu/esc/borders.rb +70 -0
- data/lib/vedeu/esc/colours.rb +104 -0
- data/lib/vedeu/{output → esc}/esc.rb +3 -1
- data/lib/vedeu/models/cell.rb +1 -2
- data/lib/vedeu/{null.rb → null/null.rb} +0 -0
- data/lib/vedeu/output/html_char.rb +12 -10
- data/lib/vedeu/templating/view_template.rb +15 -0
- data/lib/vedeu/version.rb +1 -1
- data/test/lib/vedeu/cli/generator/helpers_test.rb +51 -8
- data/test/lib/vedeu/esc/actions_test.rb +39 -0
- data/test/lib/vedeu/esc/borders_test.rb +37 -0
- data/test/lib/vedeu/esc/colours_test.rb +80 -0
- data/test/lib/vedeu/models/cell_test.rb +2 -2
- data/test/test_helper.rb +1 -0
- data/vedeu.gemspec +2 -2
- metadata +17 -11
- data/lib/vedeu/colours/escape_sequences.rb +0 -125
- data/test/lib/vedeu/colours/escape_sequences_test.rb +0 -100
@@ -0,0 +1,104 @@
|
|
1
|
+
module Vedeu
|
2
|
+
|
3
|
+
# Provides escape sequence strings.
|
4
|
+
#
|
5
|
+
module EscapeSequences
|
6
|
+
|
7
|
+
# Provides colour related escape sequences.
|
8
|
+
#
|
9
|
+
module Colours
|
10
|
+
|
11
|
+
extend self
|
12
|
+
|
13
|
+
# Produces the background named colour escape sequence hash from the
|
14
|
+
# foreground escape sequence hash.
|
15
|
+
#
|
16
|
+
# @return [Hash<Symbol => Fixnum>]
|
17
|
+
def background_codes
|
18
|
+
hash = {}
|
19
|
+
foreground_codes.inject(hash) do |h, (k, v)|
|
20
|
+
h.merge!(k => v + 10)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Produces the foreground named colour escape sequence hash. The
|
25
|
+
# background escape sequences are also generated from this by adding 10 to
|
26
|
+
# the values.
|
27
|
+
# This hash gives rise to methods you can call directly on `Esc` to
|
28
|
+
# produce the desired colours:
|
29
|
+
#
|
30
|
+
# @example
|
31
|
+
# Esc.red # => "\e[31m"
|
32
|
+
#
|
33
|
+
# Esc.red { 'some text' } # => "\e[31msome text\e[39m"
|
34
|
+
#
|
35
|
+
# Esc.on_blue # => "\e[44m"
|
36
|
+
#
|
37
|
+
# Esc.on_blue { 'some text' } # => "\e[44msome text\e[49m"
|
38
|
+
#
|
39
|
+
# # Valid names:
|
40
|
+
# :black, :red, :green, :yellow, :blue, :magenta, :cyan, :light_grey,
|
41
|
+
# :default, :dark_grey, :light_red, :light_green, :light_yellow,
|
42
|
+
# :light_blue, :light_magenta, :light_cyan, :white
|
43
|
+
#
|
44
|
+
# @return [Hash<Symbol => Fixnum>]
|
45
|
+
def foreground_codes
|
46
|
+
{
|
47
|
+
black: 30,
|
48
|
+
red: 31,
|
49
|
+
green: 32,
|
50
|
+
yellow: 33,
|
51
|
+
blue: 34,
|
52
|
+
magenta: 35,
|
53
|
+
cyan: 36,
|
54
|
+
light_grey: 37,
|
55
|
+
default: 39,
|
56
|
+
dark_grey: 90,
|
57
|
+
light_red: 91,
|
58
|
+
light_green: 92,
|
59
|
+
light_yellow: 93,
|
60
|
+
light_blue: 94,
|
61
|
+
light_magenta: 95,
|
62
|
+
light_cyan: 96,
|
63
|
+
white: 97,
|
64
|
+
}
|
65
|
+
end
|
66
|
+
alias_method :codes, :foreground_codes
|
67
|
+
|
68
|
+
# @return [void]
|
69
|
+
def setup!
|
70
|
+
define_backgrounds!
|
71
|
+
define_foregrounds!
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
# @return [void]
|
77
|
+
def define_backgrounds!
|
78
|
+
background_codes.each do |key, code|
|
79
|
+
define_method('on_' + key.to_s) do |&blk|
|
80
|
+
"\e[#{code}m" + (blk ? blk.call + "\e[49m" : '')
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Dynamically creates methods for each terminal named colour. When a block
|
86
|
+
# is given, then the colour is reset to 'default' once the block is
|
87
|
+
# called.
|
88
|
+
#
|
89
|
+
# @return [void]
|
90
|
+
def define_foregrounds!
|
91
|
+
foreground_codes.each do |key, code|
|
92
|
+
define_method(key) do |&blk|
|
93
|
+
"\e[#{code}m" + (blk ? blk.call + "\e[39m" : '')
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end # Colours
|
99
|
+
|
100
|
+
end # EscapeSequences
|
101
|
+
|
102
|
+
Vedeu::EscapeSequences::Colours.setup!
|
103
|
+
|
104
|
+
end # Vedeu
|
@@ -5,7 +5,9 @@ module Vedeu
|
|
5
5
|
#
|
6
6
|
module Esc
|
7
7
|
|
8
|
-
include Vedeu::EscapeSequences
|
8
|
+
include Vedeu::EscapeSequences::Actions
|
9
|
+
include Vedeu::EscapeSequences::Borders
|
10
|
+
include Vedeu::EscapeSequences::Colours
|
9
11
|
extend self
|
10
12
|
|
11
13
|
# Return the stream with the escape sequences escaped so that they can be
|
data/lib/vedeu/models/cell.rb
CHANGED
@@ -45,8 +45,7 @@ module Vedeu
|
|
45
45
|
# @param other [Vedeu::Cell]
|
46
46
|
# @return [Boolean]
|
47
47
|
def eql?(other)
|
48
|
-
self.class == other.class &&
|
49
|
-
style == other.style && value == other.value && x == other.x &&
|
48
|
+
self.class == other.class && value == other.value && x == other.x &&
|
50
49
|
y == other.y
|
51
50
|
end
|
52
51
|
alias_method :==, :eql?
|
File without changes
|
@@ -46,18 +46,20 @@ module Vedeu
|
|
46
46
|
return '' unless border || present?(value)
|
47
47
|
|
48
48
|
out = " style='"
|
49
|
+
out << tag_style_background unless char.background.empty?
|
50
|
+
out << tag_style_foreground unless char.foreground.empty?
|
51
|
+
out << "'"
|
52
|
+
end
|
49
53
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
unless char.foreground.empty?
|
56
|
-
out << "color:#{char.foreground.to_html};"
|
57
|
-
out << "#{border_style}"
|
58
|
-
end
|
54
|
+
# @return [String]
|
55
|
+
def tag_style_background
|
56
|
+
"border:1px #{char.background.to_html} solid;" \
|
57
|
+
"background:#{char.background.to_html};"
|
58
|
+
end
|
59
59
|
|
60
|
-
|
60
|
+
# @return [String]
|
61
|
+
def tag_style_foreground
|
62
|
+
"color:#{char.foreground.to_html};#{border_style}"
|
61
63
|
end
|
62
64
|
|
63
65
|
# @return [String]
|
@@ -48,6 +48,9 @@ module Vedeu
|
|
48
48
|
|
49
49
|
private
|
50
50
|
|
51
|
+
# Return the interface colours if a name option is set, otherwise use the
|
52
|
+
# default colours.
|
53
|
+
#
|
51
54
|
# @return [Vedeu::Colour|Hash<Symbol => Symbol>]
|
52
55
|
def default_colour
|
53
56
|
if options[:name]
|
@@ -62,6 +65,9 @@ module Vedeu
|
|
62
65
|
end
|
63
66
|
end
|
64
67
|
|
68
|
+
# Return the interface style(s) if a name option is set, otherwise use the
|
69
|
+
# default style.
|
70
|
+
#
|
65
71
|
# @return [Symbol]
|
66
72
|
def default_style
|
67
73
|
if options[:name]
|
@@ -73,23 +79,32 @@ module Vedeu
|
|
73
79
|
end
|
74
80
|
end
|
75
81
|
|
82
|
+
# Fetch the interface by name.
|
83
|
+
#
|
76
84
|
# @return [Vedeu::Interface]
|
77
85
|
def interface
|
78
86
|
Vedeu.interfaces.by_name(options[:name])
|
79
87
|
end
|
80
88
|
alias_method :interface?, :interface
|
81
89
|
|
90
|
+
# Returns the stream directives for the line.
|
91
|
+
#
|
82
92
|
# @param line [String]
|
83
93
|
# @return [Array<String>]
|
84
94
|
def streams_for(line)
|
85
95
|
line.split(/({{\s*[^}]+\s*}})/)
|
86
96
|
end
|
87
97
|
|
98
|
+
# Convert the content into an array of strings without the line ending
|
99
|
+
# character.
|
100
|
+
#
|
88
101
|
# @return [Array<String>]
|
89
102
|
def lines
|
90
103
|
content.lines.map(&:chomp)
|
91
104
|
end
|
92
105
|
|
106
|
+
# Return a string representing the template processed with ERB.
|
107
|
+
#
|
93
108
|
# @return [String]
|
94
109
|
def content
|
95
110
|
ERB.new(load, nil, '-').result(binding)
|
data/lib/vedeu/version.rb
CHANGED
@@ -45,26 +45,69 @@ module Vedeu
|
|
45
45
|
let(:source) {}
|
46
46
|
let(:destination) {}
|
47
47
|
|
48
|
-
before {
|
48
|
+
before {
|
49
|
+
File.stubs(:exist?).returns(false)
|
50
|
+
Vedeu.stubs(:log_stdout)
|
51
|
+
}
|
49
52
|
|
50
53
|
subject { instance.copy_file(source, destination) }
|
51
54
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
55
|
+
context 'when the file exists' do
|
56
|
+
before { File.stubs(:exist?).returns(true) }
|
57
|
+
|
58
|
+
it {
|
59
|
+
Vedeu.expects(:log_stdout)
|
60
|
+
subject
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'when the file does not exist' do
|
65
|
+
it {
|
66
|
+
FileUtils.expects(:cp).with(source, destination)
|
67
|
+
subject
|
68
|
+
}
|
69
|
+
end
|
56
70
|
end
|
57
71
|
|
58
72
|
describe '#make_file' do
|
59
73
|
let(:source) {}
|
60
74
|
let(:destination) {}
|
61
75
|
|
62
|
-
before {
|
76
|
+
before {
|
77
|
+
File.stubs(:exist?).returns(false)
|
78
|
+
Vedeu.stubs(:log_stdout)
|
79
|
+
}
|
63
80
|
|
64
81
|
subject { instance.make_file(source, destination) }
|
65
82
|
|
66
|
-
|
67
|
-
|
83
|
+
context 'when the file exists' do
|
84
|
+
before { File.stubs(:exist?).returns(true) }
|
85
|
+
|
86
|
+
it {
|
87
|
+
Vedeu.expects(:log_stdout)
|
88
|
+
subject
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'when the file does not exist' do
|
93
|
+
# @todo Add more tests.
|
94
|
+
# it { skip }
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe '#skipped_file' do
|
99
|
+
let(:destination) { 'some_file.txt' }
|
100
|
+
|
101
|
+
before { Vedeu.stubs(:log_stdout) }
|
102
|
+
|
103
|
+
subject { instance.skipped_file(destination) }
|
104
|
+
|
105
|
+
it {
|
106
|
+
Vedeu.expects(:log_stdout).
|
107
|
+
with(type: :create,
|
108
|
+
message: "some_file.txt \e[31malready exists, skipped.\e[39m")
|
109
|
+
subject
|
110
|
+
}
|
68
111
|
end
|
69
112
|
|
70
113
|
describe '#touch_file' do
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Vedeu
|
4
|
+
|
5
|
+
module EscapeSequences
|
6
|
+
|
7
|
+
describe Actions do
|
8
|
+
|
9
|
+
let(:described) { Vedeu::EscapeSequences::Actions }
|
10
|
+
|
11
|
+
before { Vedeu::Terminal.stubs(:size).returns([80, 25]) }
|
12
|
+
|
13
|
+
describe 'action methods' do
|
14
|
+
it { described.hide_cursor.must_equal("\e[?25l") }
|
15
|
+
it { described.show_cursor.must_equal("\e[?25h") }
|
16
|
+
it { described.cursor_position.must_equal("\e[6n") }
|
17
|
+
it { described.bg_reset.must_equal("\e[49m") }
|
18
|
+
it { described.blink.must_equal("\e[5m") }
|
19
|
+
it { described.blink_off.must_equal("\e[25m") }
|
20
|
+
it { described.bold.must_equal("\e[1m") }
|
21
|
+
it { described.bold_off.must_equal("\e[22m") }
|
22
|
+
it { described.dim.must_equal("\e[2m") }
|
23
|
+
it { described.fg_reset.must_equal("\e[39m") }
|
24
|
+
it { described.negative.must_equal("\e[7m") }
|
25
|
+
it { described.positive.must_equal("\e[27m") }
|
26
|
+
it { described.reset.must_equal("\e[0m") }
|
27
|
+
it { described.underline.must_equal("\e[4m") }
|
28
|
+
it { described.underline_off.must_equal("\e[24m") }
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '.characters' do
|
32
|
+
it { described.characters.must_be_instance_of(Hash) }
|
33
|
+
end
|
34
|
+
|
35
|
+
end # Actions
|
36
|
+
|
37
|
+
end # EscapeSequences
|
38
|
+
|
39
|
+
end # Vedeu
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Vedeu
|
4
|
+
|
5
|
+
module EscapeSequences
|
6
|
+
|
7
|
+
describe Borders do
|
8
|
+
|
9
|
+
let(:described) { Vedeu::EscapeSequences::Borders }
|
10
|
+
|
11
|
+
before { Vedeu::Terminal.stubs(:size).returns([80, 25]) }
|
12
|
+
|
13
|
+
describe 'border methods' do
|
14
|
+
it { described.border_on.must_equal("\e(0") }
|
15
|
+
it { described.border_off.must_equal("\e(B") }
|
16
|
+
|
17
|
+
it { described.bottom_right.must_equal("\x6A") }
|
18
|
+
it { described.top_right.must_equal("\x6B") }
|
19
|
+
it { described.top_left.must_equal("\x6C") }
|
20
|
+
it { described.bottom_left.must_equal("\x6D") }
|
21
|
+
it { described.horizontal.must_equal("\x71") }
|
22
|
+
it { described.vertical_left.must_equal("\x74") }
|
23
|
+
it { described.vertical_right.must_equal("\x75") }
|
24
|
+
it { described.horizontal_bottom.must_equal("\x76") }
|
25
|
+
it { described.horizontal_top.must_equal("\x77") }
|
26
|
+
it { described.vertical.must_equal("\x78") }
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '.characters' do
|
30
|
+
it { described.characters.must_be_instance_of(Hash) }
|
31
|
+
end
|
32
|
+
|
33
|
+
end # Borders
|
34
|
+
|
35
|
+
end # EscapeSequences
|
36
|
+
|
37
|
+
end # Vedeu
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Vedeu
|
4
|
+
|
5
|
+
module EscapeSequences
|
6
|
+
|
7
|
+
describe Colours do
|
8
|
+
|
9
|
+
let(:described) { Vedeu::EscapeSequences::Colours }
|
10
|
+
|
11
|
+
before { Vedeu::Terminal.stubs(:size).returns([80, 25]) }
|
12
|
+
|
13
|
+
describe 'foreground colour methods' do
|
14
|
+
it { described.black.must_equal("\e[30m") }
|
15
|
+
it { described.red.must_equal("\e[31m") }
|
16
|
+
it { described.green.must_equal("\e[32m") }
|
17
|
+
it { described.yellow.must_equal("\e[33m") }
|
18
|
+
it { described.blue.must_equal("\e[34m") }
|
19
|
+
it { described.magenta.must_equal("\e[35m") }
|
20
|
+
it { described.cyan.must_equal("\e[36m") }
|
21
|
+
it { described.light_grey.must_equal("\e[37m") }
|
22
|
+
it { described.default.must_equal("\e[39m") }
|
23
|
+
it { described.dark_grey.must_equal("\e[90m") }
|
24
|
+
it { described.light_red.must_equal("\e[91m") }
|
25
|
+
it { described.light_green.must_equal("\e[92m") }
|
26
|
+
it { described.light_yellow.must_equal("\e[93m") }
|
27
|
+
it { described.light_blue.must_equal("\e[94m") }
|
28
|
+
it { described.light_magenta.must_equal("\e[95m") }
|
29
|
+
it { described.light_cyan.must_equal("\e[96m") }
|
30
|
+
it { described.white.must_equal("\e[97m") }
|
31
|
+
|
32
|
+
it 'returns an escape sequence for the foreground colour and resets ' \
|
33
|
+
'after calling the block' do
|
34
|
+
described.cyan do
|
35
|
+
'ununpentium'
|
36
|
+
end.must_equal("\e[36mununpentium\e[39m")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '.codes' do
|
41
|
+
it { described.codes.must_be_instance_of(Hash) }
|
42
|
+
it { described.must_respond_to(:foreground_codes) }
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '.background_codes' do
|
46
|
+
it { described.background_codes.must_be_instance_of(Hash) }
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'background colour methods' do
|
50
|
+
it { described.on_black.must_equal("\e[40m") }
|
51
|
+
it { described.on_red.must_equal("\e[41m") }
|
52
|
+
it { described.on_green.must_equal("\e[42m") }
|
53
|
+
it { described.on_yellow.must_equal("\e[43m") }
|
54
|
+
it { described.on_blue.must_equal("\e[44m") }
|
55
|
+
it { described.on_magenta.must_equal("\e[45m") }
|
56
|
+
it { described.on_cyan.must_equal("\e[46m") }
|
57
|
+
it { described.on_light_grey.must_equal("\e[47m") }
|
58
|
+
it { described.on_default.must_equal("\e[49m") }
|
59
|
+
it { described.on_dark_grey.must_equal("\e[100m") }
|
60
|
+
it { described.on_light_red.must_equal("\e[101m") }
|
61
|
+
it { described.on_light_green.must_equal("\e[102m") }
|
62
|
+
it { described.on_light_yellow.must_equal("\e[103m") }
|
63
|
+
it { described.on_light_blue.must_equal("\e[104m") }
|
64
|
+
it { described.on_light_magenta.must_equal("\e[105m") }
|
65
|
+
it { described.on_light_cyan.must_equal("\e[106m") }
|
66
|
+
it { described.on_white.must_equal("\e[107m") }
|
67
|
+
|
68
|
+
it 'returns an escape sequence for the background colour and resets ' \
|
69
|
+
'after calling the block' do
|
70
|
+
described.on_red do
|
71
|
+
'livermorium'
|
72
|
+
end.must_equal("\e[41mlivermorium\e[49m")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end # Colours
|
77
|
+
|
78
|
+
end # EscapeSequences
|
79
|
+
|
80
|
+
end # Vedeu
|