vedeu 0.0.25 → 0.0.26
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -9
- data/Rakefile +0 -10
- data/bin/composition +1 -1
- data/examples/single_interface_app.rb +7 -4
- data/lib/vedeu.rb +19 -48
- data/lib/vedeu/application.rb +8 -7
- data/lib/vedeu/configuration.rb +4 -4
- data/lib/vedeu/input/input.rb +3 -0
- data/lib/vedeu/launcher.rb +3 -0
- data/lib/vedeu/models/background.rb +13 -0
- data/lib/vedeu/models/coercions.rb +21 -0
- data/lib/vedeu/models/colour.rb +22 -0
- data/lib/vedeu/{repository → models}/command.rb +2 -0
- data/lib/vedeu/models/composition.rb +30 -0
- data/lib/vedeu/models/foreground.rb +13 -0
- data/lib/vedeu/models/interface.rb +62 -0
- data/lib/vedeu/models/interface_collection.rb +24 -0
- data/lib/vedeu/models/line.rb +22 -0
- data/lib/vedeu/models/line_collection.rb +27 -0
- data/lib/vedeu/models/presentation.rb +13 -0
- data/lib/vedeu/models/stream.rb +21 -0
- data/lib/vedeu/models/stream_collection.rb +27 -0
- data/lib/vedeu/models/style_collection.rb +23 -0
- data/lib/vedeu/output/interface_renderer.rb +62 -0
- data/lib/vedeu/output/output.rb +6 -5
- data/lib/vedeu/process/process.rb +15 -31
- data/lib/vedeu/repository/command_repository.rb +13 -14
- data/lib/vedeu/repository/interface_repository.rb +12 -13
- data/lib/vedeu/repository/repository.rb +2 -0
- data/lib/vedeu/{output → support}/cursor.rb +2 -0
- data/lib/vedeu/support/esc.rb +112 -0
- data/lib/vedeu/support/events.rb +21 -0
- data/lib/vedeu/support/geometry.rb +66 -0
- data/lib/vedeu/support/parser.rb +27 -0
- data/lib/vedeu/support/terminal.rb +31 -134
- data/lib/vedeu/{output → support}/translator.rb +12 -8
- data/lib/vedeu/{output → support}/wordwrap.rb +2 -4
- data/lib/vedeu/version.rb +1 -1
- data/test/lib/vedeu/application_test.rb +7 -2
- data/test/lib/vedeu/configuration_test.rb +13 -8
- data/test/lib/vedeu/input/input_test.rb +2 -1
- data/test/lib/vedeu/launcher_test.rb +7 -2
- data/test/lib/vedeu/models/background_test.rb +35 -0
- data/test/lib/vedeu/models/colour_test.rb +71 -0
- data/test/lib/vedeu/models/command_test.rb +109 -0
- data/test/lib/vedeu/models/composition_test.rb +187 -0
- data/test/lib/vedeu/models/foreground_test.rb +35 -0
- data/test/lib/vedeu/models/interface_collection_test.rb +57 -0
- data/test/lib/vedeu/models/interface_test.rb +220 -0
- data/test/lib/vedeu/models/line_collection_test.rb +69 -0
- data/test/lib/vedeu/models/line_test.rb +76 -0
- data/test/lib/vedeu/models/presentation_test.rb +8 -0
- data/test/lib/vedeu/models/stream_collection_test.rb +57 -0
- data/test/lib/vedeu/models/stream_test.rb +76 -0
- data/test/lib/vedeu/models/style_collection_test.rb +22 -0
- data/test/lib/vedeu/output/interface_renderer_test.rb +12 -0
- data/test/lib/vedeu/output/output_test.rb +15 -30
- data/test/lib/vedeu/process/process_test.rb +22 -44
- data/test/lib/vedeu/repository/command_repository_test.rb +22 -16
- data/test/lib/vedeu/repository/interface_repository_test.rb +62 -14
- data/test/lib/vedeu/repository/repository_test.rb +1 -0
- data/test/lib/vedeu/repository/storage_test.rb +13 -6
- data/test/lib/vedeu/{output → support}/cursor_test.rb +1 -0
- data/test/lib/vedeu/support/esc_test.rb +348 -0
- data/test/lib/vedeu/support/events_test.rb +37 -0
- data/test/lib/vedeu/support/exit_test.rb +1 -0
- data/test/lib/vedeu/support/geometry_test.rb +131 -0
- data/test/lib/vedeu/support/parser_test.rb +56 -0
- data/test/lib/vedeu/support/queue_test.rb +1 -0
- data/test/lib/vedeu/support/terminal_test.rb +1 -119
- data/test/lib/vedeu/{output → support}/translator_test.rb +17 -12
- data/test/lib/vedeu/{output → support}/wordwrap_test.rb +1 -0
- data/test/lib/vedeu/version_test.rb +1 -0
- data/test/lib/vedeu_test.rb +1 -0
- data/{lib/vedeu/repository → test/support}/dummy_command.rb +0 -0
- data/{lib/vedeu/repository → test/support}/dummy_interface.rb +0 -0
- data/test/support/json/int1_lin1_str1.json +10 -0
- data/test/support/json/int1_lin1_str3.json +18 -0
- data/test/support/json/int1_lin2_str1.json +17 -0
- data/test/support/json/int1_lin2_str3.json +33 -0
- data/test/support/json/int1_lin2_str3_styles.json +43 -0
- data/test/support/json/int2_lin1_str1.json +20 -0
- data/test/support/json/int2_lin1_str3.json +36 -0
- data/test/support/json/int2_lin2_str1.json +34 -0
- data/test/support/json/int2_lin2_str3.json +66 -0
- data/test/support/json/int2_lin2_str3_styles.json +158 -0
- data/test/support/output_1.json +9 -0
- data/test/support/output_1.rb +14 -0
- data/test/support/output_2.json +1 -0
- data/test/support/output_2.rb +19 -0
- data/test/test_helper.rb +0 -2
- data/vedeu.gemspec +0 -3
- metadata +98 -150
- data/config/cucumber.yml +0 -8
- data/documentation/composition.ebnf +0 -7
- data/documentation/diagram/ColourDirective.png +0 -0
- data/documentation/diagram/Directive.png +0 -0
- data/documentation/diagram/Interface.png +0 -0
- data/documentation/diagram/Output.png +0 -0
- data/documentation/diagram/PositionDirective.png +0 -0
- data/documentation/diagram/Stream.png +0 -0
- data/documentation/diagram/StyleDirective.png +0 -0
- data/documentation/diagram/rr-1.35.837.png +0 -0
- data/documentation/index.html +0 -325
- data/features/getting_started.feature +0 -10
- data/features/step_definitions/vedeu_steps.rb +0 -11
- data/features/support/env.rb +0 -12
- data/lib/vedeu/output/background.rb +0 -27
- data/lib/vedeu/output/base.rb +0 -57
- data/lib/vedeu/output/buffer/composition.rb +0 -24
- data/lib/vedeu/output/buffer/formatting.rb +0 -25
- data/lib/vedeu/output/buffer/interface.rb +0 -14
- data/lib/vedeu/output/buffer/line.rb +0 -14
- data/lib/vedeu/output/buffer/stream.rb +0 -14
- data/lib/vedeu/output/buffer/style.rb +0 -11
- data/lib/vedeu/output/colour.rb +0 -39
- data/lib/vedeu/output/compositor.rb +0 -72
- data/lib/vedeu/output/directive.rb +0 -63
- data/lib/vedeu/output/esc.rb +0 -61
- data/lib/vedeu/output/foreground.rb +0 -27
- data/lib/vedeu/output/geometry.rb +0 -71
- data/lib/vedeu/output/layer.rb +0 -9
- data/lib/vedeu/output/menu.rb +0 -26
- data/lib/vedeu/output/position.rb +0 -35
- data/lib/vedeu/output/style.rb +0 -38
- data/lib/vedeu/repository/interface.rb +0 -62
- data/lib/vedeu/support/json_parser.rb +0 -25
- data/lib/vedeu/support/options.rb +0 -4
- data/test/lib/vedeu/output/background_test.rb +0 -67
- data/test/lib/vedeu/output/base_test.rb +0 -8
- data/test/lib/vedeu/output/buffer/composition_test.rb +0 -57
- data/test/lib/vedeu/output/buffer/formatting_test.rb +0 -9
- data/test/lib/vedeu/output/buffer/interface_test.rb +0 -38
- data/test/lib/vedeu/output/buffer/line_test.rb +0 -64
- data/test/lib/vedeu/output/buffer/stream_test.rb +0 -61
- data/test/lib/vedeu/output/buffer/style_test.rb +0 -8
- data/test/lib/vedeu/output/colour_test.rb +0 -104
- data/test/lib/vedeu/output/compositor_test.rb +0 -247
- data/test/lib/vedeu/output/directive_test.rb +0 -82
- data/test/lib/vedeu/output/esc_test.rb +0 -175
- data/test/lib/vedeu/output/foreground_test.rb +0 -67
- data/test/lib/vedeu/output/geometry_test.rb +0 -190
- data/test/lib/vedeu/output/layer_test.rb +0 -35
- data/test/lib/vedeu/output/menu_test.rb +0 -13
- data/test/lib/vedeu/output/position_test.rb +0 -48
- data/test/lib/vedeu/output/style_test.rb +0 -132
- data/test/lib/vedeu/repository/command_test.rb +0 -73
- data/test/lib/vedeu/repository/dummy_command_test.rb +0 -27
- data/test/lib/vedeu/repository/dummy_interface_test.rb +0 -7
- data/test/lib/vedeu/repository/interface_test.rb +0 -79
- data/test/lib/vedeu/support/json_parser_test.rb +0 -45
- data/test/support/composition.json +0 -47
- data/test/support/composition.rb +0 -5
- data/test/support/composition.xml +0 -36
- data/test/support/multi_interface.json +0 -34
- data/test/support/single_interface.json +0 -19
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'virtus'
|
2
|
+
|
3
|
+
require_relative '../repository/interface_repository'
|
4
|
+
require_relative 'coercions'
|
5
|
+
|
6
|
+
module Vedeu
|
7
|
+
class InterfaceCollection < Virtus::Attribute
|
8
|
+
include Coercions
|
9
|
+
|
10
|
+
def coerce(values)
|
11
|
+
return [] if empty?(values)
|
12
|
+
|
13
|
+
if multiple?(values)
|
14
|
+
values.map do |value|
|
15
|
+
InterfaceRepository.update(value[:name], value)
|
16
|
+
end
|
17
|
+
|
18
|
+
elsif single?(values)
|
19
|
+
[InterfaceRepository.update(values[:name], values)]
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'oj'
|
2
|
+
require 'virtus'
|
3
|
+
|
4
|
+
require_relative 'presentation'
|
5
|
+
require_relative 'stream_collection'
|
6
|
+
|
7
|
+
module Vedeu
|
8
|
+
class Line
|
9
|
+
include Virtus.model
|
10
|
+
include Presentation
|
11
|
+
|
12
|
+
attribute :streams, StreamCollection
|
13
|
+
|
14
|
+
def to_json
|
15
|
+
Oj.dump(attributes, mode: :compat)
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
[colour, style, streams].join
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'virtus'
|
2
|
+
|
3
|
+
require_relative 'line'
|
4
|
+
require_relative 'coercions'
|
5
|
+
|
6
|
+
module Vedeu
|
7
|
+
class InvalidLine < StandardError; end
|
8
|
+
|
9
|
+
class LineCollection < Virtus::Attribute
|
10
|
+
include Coercions
|
11
|
+
|
12
|
+
def coerce(values)
|
13
|
+
return [] if empty?(values)
|
14
|
+
|
15
|
+
if multiple?(values)
|
16
|
+
values.map { |v| Line.new(v) }
|
17
|
+
|
18
|
+
elsif single?(values)
|
19
|
+
[Line.new(values)]
|
20
|
+
|
21
|
+
elsif just_text?(values)
|
22
|
+
[Line.new({ streams: values })]
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'virtus'
|
2
|
+
|
3
|
+
require_relative 'presentation'
|
4
|
+
require_relative '../support/terminal'
|
5
|
+
|
6
|
+
module Vedeu
|
7
|
+
class Stream
|
8
|
+
include Virtus.model
|
9
|
+
include Presentation
|
10
|
+
|
11
|
+
attribute :text, String, default: ''
|
12
|
+
|
13
|
+
def to_json
|
14
|
+
Oj.dump(attributes, mode: :compat)
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s(options = {})
|
18
|
+
[colour, style, text].join
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'virtus'
|
2
|
+
|
3
|
+
require_relative 'stream'
|
4
|
+
require_relative 'coercions'
|
5
|
+
|
6
|
+
module Vedeu
|
7
|
+
class InvalidStream < StandardError; end
|
8
|
+
|
9
|
+
class StreamCollection < Virtus::Attribute
|
10
|
+
include Coercions
|
11
|
+
|
12
|
+
def coerce(values)
|
13
|
+
return [] if empty?(values)
|
14
|
+
|
15
|
+
if multiple?(values)
|
16
|
+
values.map { |v| Stream.new(v) }
|
17
|
+
|
18
|
+
elsif single?(values)
|
19
|
+
[Stream.new(values)]
|
20
|
+
|
21
|
+
elsif values.is_a?(String)
|
22
|
+
[Stream.new({ text: values })]
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'virtus'
|
2
|
+
|
3
|
+
require_relative '../support/cursor'
|
4
|
+
require_relative '../support/esc'
|
5
|
+
require_relative 'coercions'
|
6
|
+
|
7
|
+
module Vedeu
|
8
|
+
class StyleCollection < Virtus::Attribute
|
9
|
+
include Coercions
|
10
|
+
|
11
|
+
def coerce(values)
|
12
|
+
return '' if empty?(values)
|
13
|
+
|
14
|
+
if multiple?(values)
|
15
|
+
values.map { |value| Esc.stylize(value) }.join
|
16
|
+
|
17
|
+
elsif just_text?(values)
|
18
|
+
Esc.stylize(values)
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require_relative '../support/geometry'
|
2
|
+
|
3
|
+
module Vedeu
|
4
|
+
class InterfaceRenderer
|
5
|
+
def self.clear(interface)
|
6
|
+
new(interface).clear
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.render(interface)
|
10
|
+
new(interface).render
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(interface)
|
14
|
+
@interface = interface
|
15
|
+
end
|
16
|
+
|
17
|
+
def clear
|
18
|
+
set_colour + clear_lines
|
19
|
+
end
|
20
|
+
|
21
|
+
def render
|
22
|
+
out = []
|
23
|
+
content_lines.each_with_index do |line, index|
|
24
|
+
out << origin(index)
|
25
|
+
out << line.to_s
|
26
|
+
end
|
27
|
+
out.join
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
attr_reader :interface
|
33
|
+
|
34
|
+
def content_lines
|
35
|
+
interface.lines
|
36
|
+
end
|
37
|
+
|
38
|
+
def set_colour
|
39
|
+
interface.colour.to_s
|
40
|
+
end
|
41
|
+
|
42
|
+
def clear_lines
|
43
|
+
height.times.inject([]) { |line, index| line << clear_line(index) }.join
|
44
|
+
end
|
45
|
+
|
46
|
+
def clear_line(index)
|
47
|
+
origin(index) + (' ' * width) + origin(index)
|
48
|
+
end
|
49
|
+
|
50
|
+
def origin(index)
|
51
|
+
Geometry.origin(interface, index)
|
52
|
+
end
|
53
|
+
|
54
|
+
def height
|
55
|
+
interface.height
|
56
|
+
end
|
57
|
+
|
58
|
+
def width
|
59
|
+
interface.width
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/vedeu/output/output.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
|
+
require_relative '../repository/interface_repository'
|
2
|
+
require_relative '../support/terminal'
|
3
|
+
|
1
4
|
module Vedeu
|
2
5
|
class Output
|
3
|
-
|
4
|
-
|
5
|
-
new.render
|
6
|
-
end
|
6
|
+
def self.render
|
7
|
+
new.render
|
7
8
|
end
|
8
9
|
|
9
10
|
def initialize; end
|
10
11
|
|
11
12
|
def render
|
12
13
|
InterfaceRepository.refresh.each do |interface|
|
13
|
-
|
14
|
+
Terminal.output(interface)
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
@@ -1,51 +1,35 @@
|
|
1
|
+
require_relative '../repository/command_repository'
|
2
|
+
require_relative '../support/queue'
|
3
|
+
require_relative '../support/parser'
|
4
|
+
|
1
5
|
module Vedeu
|
2
6
|
class Process
|
3
|
-
|
4
|
-
|
5
|
-
new.evaluate
|
6
|
-
end
|
7
|
+
def self.evaluate
|
8
|
+
new.evaluate
|
7
9
|
end
|
8
10
|
|
9
11
|
def initialize; end
|
10
12
|
|
11
13
|
def evaluate
|
12
|
-
fail StopIteration if
|
14
|
+
fail StopIteration if no_result?
|
15
|
+
|
16
|
+
json = Parser.parse(result)
|
13
17
|
|
14
|
-
|
18
|
+
Composition.enqueue(json)
|
15
19
|
end
|
16
20
|
|
17
21
|
private
|
18
22
|
|
19
|
-
def result
|
20
|
-
@result ||= command.execute(*args) if command
|
21
|
-
end
|
22
|
-
|
23
23
|
def no_result?
|
24
|
-
result.nil? || result.empty?
|
25
|
-
end
|
26
|
-
|
27
|
-
def command
|
28
|
-
@command ||= find_by_keypress || find_by_keyword
|
24
|
+
result.nil? || result.empty? || result == :stop
|
29
25
|
end
|
30
26
|
|
31
|
-
def
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
def find_by_keyword
|
36
|
-
CommandRepository.by_keyword(input) if keyword?
|
37
|
-
end
|
38
|
-
|
39
|
-
def keypress?
|
40
|
-
input? && input.size == 1
|
41
|
-
end
|
42
|
-
|
43
|
-
def keyword?
|
44
|
-
input? && input.size > 1
|
27
|
+
def result
|
28
|
+
@result ||= command.execute(*args) if command
|
45
29
|
end
|
46
30
|
|
47
|
-
def
|
48
|
-
|
31
|
+
def command
|
32
|
+
@command ||= CommandRepository.by_input(input)
|
49
33
|
end
|
50
34
|
|
51
35
|
def input
|
@@ -1,14 +1,15 @@
|
|
1
|
+
require_relative '../models/command'
|
2
|
+
require_relative 'repository'
|
3
|
+
|
1
4
|
module Vedeu
|
2
5
|
module CommandRepository
|
3
6
|
extend Repository
|
4
7
|
extend self
|
5
8
|
|
6
|
-
def
|
7
|
-
|
8
|
-
end
|
9
|
+
def by_input(input)
|
10
|
+
return nil unless input
|
9
11
|
|
10
|
-
|
11
|
-
query(entity, :keyword, input)
|
12
|
+
by_keypress(input) || by_keyword(input)
|
12
13
|
end
|
13
14
|
|
14
15
|
def create(attributes)
|
@@ -18,17 +19,15 @@ module Vedeu
|
|
18
19
|
def entity
|
19
20
|
Command
|
20
21
|
end
|
21
|
-
end
|
22
22
|
|
23
|
-
|
24
|
-
module ClassMethods
|
25
|
-
def command(name, options = {})
|
26
|
-
command_name = name.is_a?(Symbol) ? name.to_s : name
|
23
|
+
private
|
27
24
|
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
def by_keypress(input)
|
26
|
+
query(entity, :keypress, input)
|
27
|
+
end
|
28
|
+
|
29
|
+
def by_keyword(input)
|
30
|
+
query(entity, :keyword, input)
|
31
31
|
end
|
32
32
|
end
|
33
|
-
# :nocov:
|
34
33
|
end
|
@@ -1,3 +1,6 @@
|
|
1
|
+
require_relative '../models/interface'
|
2
|
+
require_relative 'repository'
|
3
|
+
|
1
4
|
module Vedeu
|
2
5
|
class UndefinedInterface < StandardError; end
|
3
6
|
|
@@ -15,28 +18,24 @@ module Vedeu
|
|
15
18
|
result
|
16
19
|
end
|
17
20
|
|
21
|
+
def update(name, attributes = {})
|
22
|
+
interface = find(name)
|
23
|
+
interface.attributes = attributes
|
24
|
+
interface
|
25
|
+
rescue UndefinedInterface
|
26
|
+
create(attributes)
|
27
|
+
end
|
28
|
+
|
18
29
|
def refresh
|
19
30
|
by_layer.map { |interface| interface.refresh }.compact
|
20
31
|
end
|
21
32
|
|
22
33
|
def by_layer
|
23
|
-
all.sort_by { |interface| interface.
|
34
|
+
all.sort_by { |interface| interface.z }
|
24
35
|
end
|
25
36
|
|
26
37
|
def entity
|
27
38
|
Interface
|
28
39
|
end
|
29
40
|
end
|
30
|
-
|
31
|
-
# :nocov:
|
32
|
-
module ClassMethods
|
33
|
-
def interface(name, options = {})
|
34
|
-
interface_name = name.is_a?(Symbol) ? name.to_s : name
|
35
|
-
|
36
|
-
InterfaceRepository.create({
|
37
|
-
name: interface_name
|
38
|
-
}.merge!(options))
|
39
|
-
end
|
40
|
-
end
|
41
|
-
# :nocov:
|
42
41
|
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require_relative 'cursor'
|
2
|
+
require_relative 'terminal'
|
3
|
+
require_relative 'translator'
|
4
|
+
|
5
|
+
module Vedeu
|
6
|
+
module Esc
|
7
|
+
extend self
|
8
|
+
|
9
|
+
def background_colour(value = '#000000')
|
10
|
+
[esc, '48;5;', colour_translator(value), 'm'].join
|
11
|
+
end
|
12
|
+
|
13
|
+
def blink
|
14
|
+
[esc, '5m'].join
|
15
|
+
end
|
16
|
+
|
17
|
+
def blink_off
|
18
|
+
[esc, '25m'].join
|
19
|
+
end
|
20
|
+
|
21
|
+
def bold
|
22
|
+
[esc, '1m'].join
|
23
|
+
end
|
24
|
+
|
25
|
+
def bold_off
|
26
|
+
[esc, '21m'].join
|
27
|
+
end
|
28
|
+
|
29
|
+
def clear
|
30
|
+
[esc, '2J'].join
|
31
|
+
end
|
32
|
+
|
33
|
+
def clear_line
|
34
|
+
[esc, '2K'].join
|
35
|
+
end
|
36
|
+
|
37
|
+
def clear_last_line()
|
38
|
+
set_position((Terminal.height - 1), 1) + clear_line
|
39
|
+
end
|
40
|
+
|
41
|
+
# def cursor(value)
|
42
|
+
# Cursor.
|
43
|
+
# end
|
44
|
+
|
45
|
+
def esc
|
46
|
+
[27.chr, '['].join
|
47
|
+
end
|
48
|
+
|
49
|
+
def foreground_colour(value = '#ffffff')
|
50
|
+
[esc, '38;5;', colour_translator(value), 'm'].join
|
51
|
+
end
|
52
|
+
#
|
53
|
+
def negative
|
54
|
+
[esc, '7m'].join
|
55
|
+
end
|
56
|
+
|
57
|
+
def positive
|
58
|
+
[esc, '27m'].join
|
59
|
+
end
|
60
|
+
|
61
|
+
def normal
|
62
|
+
[underline_off, bold_off, positive].join
|
63
|
+
end
|
64
|
+
|
65
|
+
def dim
|
66
|
+
[esc, '2m'].join
|
67
|
+
end
|
68
|
+
|
69
|
+
def reset
|
70
|
+
[esc, '0m'].join
|
71
|
+
end
|
72
|
+
|
73
|
+
def set_position(y = 1, x = 1)
|
74
|
+
[esc, ((y == 0 || y == nil) ? 1 : y), ';', ((x == 0 || x == nil) ? 1 : x), 'H'].join
|
75
|
+
end
|
76
|
+
|
77
|
+
def stylize(value = 'normal')
|
78
|
+
case value
|
79
|
+
when 'blink' then blink
|
80
|
+
when 'blink_off' then blink_off
|
81
|
+
when 'bold' then bold
|
82
|
+
when 'bold_off' then bold_off
|
83
|
+
when 'clear' then clear
|
84
|
+
when 'hide_cursor' then Cursor.hide
|
85
|
+
when 'negative' then negative
|
86
|
+
when 'positive' then positive
|
87
|
+
when 'reset' then reset
|
88
|
+
when 'normal' then normal
|
89
|
+
when 'dim' then dim
|
90
|
+
when 'show_cursor' then Cursor.show
|
91
|
+
when 'underline' then underline
|
92
|
+
when 'underline_off' then underline_off
|
93
|
+
else
|
94
|
+
''
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def underline
|
99
|
+
[esc, '4m'].join
|
100
|
+
end
|
101
|
+
|
102
|
+
def underline_off
|
103
|
+
[esc, '24m'].join
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def colour_translator(value)
|
109
|
+
Translator.translate(value)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|