dev_suite 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/dev_suite/directory_tree/renderer/simple.rb +45 -29
- data/lib/dev_suite/performance/reportor/simple.rb +0 -1
- data/lib/dev_suite/utils/color/colorizer.rb +25 -0
- data/lib/dev_suite/utils/color/config.rb +40 -0
- data/lib/dev_suite/utils/color/palette/base.rb +32 -0
- data/lib/dev_suite/utils/color/palette/default.rb +22 -0
- data/lib/dev_suite/utils/color/palette.rb +23 -0
- data/lib/dev_suite/utils/color/strategy/base.rb +15 -0
- data/lib/dev_suite/utils/color/strategy/basic.rb +25 -0
- data/lib/dev_suite/utils/color/strategy/rgb.rb +27 -0
- data/lib/dev_suite/utils/color/strategy/theme.rb +36 -0
- data/lib/dev_suite/utils/color/strategy.rb +31 -0
- data/lib/dev_suite/utils/color.rb +12 -0
- data/lib/dev_suite/utils/table/column.rb +6 -2
- data/lib/dev_suite/utils/table/config.rb +26 -2
- data/lib/dev_suite/utils/table/formatter.rb +12 -0
- data/lib/dev_suite/utils/table/renderer/simple.rb +1 -6
- data/lib/dev_suite/utils/table/row.rb +6 -2
- data/lib/dev_suite/utils/table/table.rb +0 -5
- data/lib/dev_suite/utils/table.rb +14 -0
- data/lib/dev_suite/utils.rb +2 -3
- data/lib/dev_suite/version.rb +1 -1
- data/lib/dev_suite.rb +1 -0
- metadata +14 -4
- data/lib/dev_suite/utils/table/column/column.rb +0 -15
- data/lib/dev_suite/utils/table/formatter/colorizer.rb +0 -33
- data/lib/dev_suite/utils/table/row/row.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92f5e3450bc8b204f0be7e25db8a863ebd49d4d5a6990cfad7c6d336ccaf7e5e
|
4
|
+
data.tar.gz: 368e6bd01867d4fc92856b8bc4825e1e5bdc2b3b978e3afa0966139f59216f28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 973f1f20d18eab20229c5df12a304c1370ccbfc56175795c9e55fc6bc2680c0a3a3adae63472bcd3dc15ed964ba4413a5847a55d8fefc28312a119af9b0b91d5
|
7
|
+
data.tar.gz: f31d767559b8cd4fbfa961cafef17a5cbbcda42a78ee5e012147a96a2652fd8b3417e1184a1e5a60925032aa21b6d256902753c799c322aa48e5240016b6f901
|
data/Gemfile.lock
CHANGED
@@ -10,51 +10,67 @@ module DevSuite
|
|
10
10
|
private
|
11
11
|
|
12
12
|
def build_tree(path)
|
13
|
-
return
|
13
|
+
return permission_denied_node(path) unless path.readable?
|
14
14
|
|
15
|
-
|
16
|
-
dir = Node::Directory.new(path.basename.to_s)
|
17
|
-
children = path.children.sort_by { |child| child.basename.to_s.downcase }
|
18
|
-
children.each do |child|
|
19
|
-
dir.add_child(build_tree(child))
|
20
|
-
end
|
21
|
-
dir
|
22
|
-
else
|
23
|
-
Node::File.new(path.basename.to_s)
|
24
|
-
end
|
15
|
+
path.directory? ? directory_node(path) : file_node(path)
|
25
16
|
rescue Errno::EACCES
|
26
|
-
|
17
|
+
permission_denied_node(path)
|
27
18
|
end
|
28
19
|
|
29
20
|
def render_node(node, prefix = "", is_last = true)
|
30
|
-
# Determine if this is the root node based on the prefix content
|
31
21
|
is_root = prefix.empty?
|
22
|
+
connector = determine_connector(is_root, is_last)
|
23
|
+
new_prefix = update_prefix(prefix, is_last)
|
32
24
|
|
33
|
-
|
34
|
-
|
35
|
-
""
|
36
|
-
else
|
37
|
-
(is_last ? "└── " : "├── ")
|
38
|
-
end
|
25
|
+
output = construct_output(node, prefix, connector)
|
26
|
+
output += node_suffix(node)
|
39
27
|
|
40
|
-
# Compute the new prefix for children
|
41
|
-
new_prefix = "#{prefix}#{is_last ? " " : "| "}"
|
42
|
-
|
43
|
-
# Construct the output for the current node, avoiding the connector for the root
|
44
|
-
output = "#{prefix}#{connector}#{node.name}"
|
45
|
-
output += "/\n" if node.directory?
|
46
|
-
|
47
|
-
# Recursively render children if it's a directory
|
48
28
|
if node.directory? && node.children.any?
|
49
29
|
node.children.each_with_index do |child, index|
|
50
30
|
output += render_node(child, new_prefix, index == node.children.size - 1)
|
51
31
|
end
|
52
|
-
elsif !node.directory?
|
53
|
-
output += "\n"
|
54
32
|
end
|
55
33
|
|
56
34
|
output
|
57
35
|
end
|
36
|
+
|
37
|
+
def determine_connector(is_root, is_last)
|
38
|
+
return "" if is_root
|
39
|
+
|
40
|
+
is_last ? "└── " : "├── "
|
41
|
+
end
|
42
|
+
|
43
|
+
def update_prefix(prefix, is_last)
|
44
|
+
"#{prefix}#{is_last ? " " : "| "}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def construct_output(node, prefix, connector)
|
48
|
+
"#{prefix}#{connector}#{node.name}"
|
49
|
+
end
|
50
|
+
|
51
|
+
def node_suffix(node)
|
52
|
+
node.directory? ? "/\n" : "\n"
|
53
|
+
end
|
54
|
+
|
55
|
+
def directory_node(path)
|
56
|
+
dir = Node::Directory.new(path.basename.to_s)
|
57
|
+
sorted_children(path).each do |child|
|
58
|
+
dir.add_child(build_tree(child))
|
59
|
+
end
|
60
|
+
dir
|
61
|
+
end
|
62
|
+
|
63
|
+
def file_node(path)
|
64
|
+
Node::File.new(path.basename.to_s)
|
65
|
+
end
|
66
|
+
|
67
|
+
def permission_denied_node(path)
|
68
|
+
Node::PermissionDenied.new(path.basename.to_s, path.directory?)
|
69
|
+
end
|
70
|
+
|
71
|
+
def sorted_children(path)
|
72
|
+
path.children.sort_by { |child| child.basename.to_s.downcase }
|
73
|
+
end
|
58
74
|
end
|
59
75
|
end
|
60
76
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module Utils
|
5
|
+
module Color
|
6
|
+
class << self
|
7
|
+
def colorize(text, **kargs)
|
8
|
+
Colorizer.new(Config.configuration).colorize(text, **kargs)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Colorizer
|
13
|
+
attr_reader :config
|
14
|
+
|
15
|
+
def initialize(config = Config.configuration)
|
16
|
+
@config = config
|
17
|
+
end
|
18
|
+
|
19
|
+
def colorize(text, **kargs)
|
20
|
+
puts @config.strategy.colorize(text, **kargs)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module Utils
|
5
|
+
module Color
|
6
|
+
class Config
|
7
|
+
attr_accessor :strategy, :palette
|
8
|
+
|
9
|
+
def initialize(strategy: :theme, palette: :default)
|
10
|
+
@palette = Palette.create(palette)
|
11
|
+
@strategy = Strategy.create(strategy, palette: @palette)
|
12
|
+
freeze # Make the instance of this class immutable as well
|
13
|
+
end
|
14
|
+
|
15
|
+
class << self
|
16
|
+
#
|
17
|
+
# Provide global access to a single instance of Config
|
18
|
+
#
|
19
|
+
def configuration
|
20
|
+
@configuration ||= new
|
21
|
+
end
|
22
|
+
|
23
|
+
# Allow block-based configuration
|
24
|
+
def configure
|
25
|
+
yield(configuration)
|
26
|
+
rescue StandardError => e
|
27
|
+
handle_configuration_error(e)
|
28
|
+
raise
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def handle_configuration_error(error)
|
34
|
+
puts "Configuration error: #{error.message}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module Utils
|
5
|
+
module Color
|
6
|
+
module Palette
|
7
|
+
class Base
|
8
|
+
# Define COLORS constant in subclass
|
9
|
+
# Example:
|
10
|
+
# COLORS = {
|
11
|
+
# red: 31,
|
12
|
+
# green: 32,
|
13
|
+
# yellow: 33,
|
14
|
+
# blue: 34,
|
15
|
+
# pink: 35,
|
16
|
+
# light_blue: 36,
|
17
|
+
# white: 37
|
18
|
+
# }
|
19
|
+
#
|
20
|
+
|
21
|
+
def colors
|
22
|
+
unless self.class.const_defined?(:COLORS)
|
23
|
+
raise NotImplementedError, "#{self.class} must define COLORS constant"
|
24
|
+
end
|
25
|
+
|
26
|
+
self.class::COLORS
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module Utils
|
5
|
+
module Color
|
6
|
+
module Palette
|
7
|
+
class Default < Base
|
8
|
+
COLORS = {
|
9
|
+
red: 31,
|
10
|
+
green: 32,
|
11
|
+
yellow: 33,
|
12
|
+
blue: 34,
|
13
|
+
magenta: 35,
|
14
|
+
cyan: 36,
|
15
|
+
white: 37,
|
16
|
+
default: 39,
|
17
|
+
}.freeze
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module Utils
|
5
|
+
module Color
|
6
|
+
module Palette
|
7
|
+
require_relative "palette/base"
|
8
|
+
require_relative "palette/default"
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def create(type)
|
12
|
+
case type
|
13
|
+
when :default
|
14
|
+
Default.new
|
15
|
+
else
|
16
|
+
raise ArgumentError, "Unknown palette type: #{type}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module Utils
|
5
|
+
module Color
|
6
|
+
module Strategy
|
7
|
+
class Basic < Base
|
8
|
+
def colorize(text, color: :default)
|
9
|
+
unless valid_color_code?(color)
|
10
|
+
raise ArgumentError, "Invalid color code"
|
11
|
+
end
|
12
|
+
|
13
|
+
"\e[#{color}m#{text}\e[0m"
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def valid_color_code?(color_code)
|
19
|
+
color_code.is_a?(Integer) && color_code.between?(0, 255)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module Utils
|
5
|
+
module Color
|
6
|
+
module Strategy
|
7
|
+
class Rgb < Base
|
8
|
+
def colorize(text, **kwargs)
|
9
|
+
r, g, b = kwargs.values_at(:r, :g, :b)
|
10
|
+
|
11
|
+
unless valid_rgb?(r, g, b)
|
12
|
+
raise ArgumentError, "RGB values must be integers between 0 and 255"
|
13
|
+
end
|
14
|
+
|
15
|
+
"\e[38;2;#{r};#{g};#{b}m#{text}\e[0m"
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def valid_rgb?(r, g, b)
|
21
|
+
[r, g, b].all? { |value| value.is_a?(Integer) && value.between?(0, 255) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module Utils
|
5
|
+
module Color
|
6
|
+
module Strategy
|
7
|
+
class Theme < Base
|
8
|
+
def initialize(palette)
|
9
|
+
super()
|
10
|
+
@palette = palette
|
11
|
+
end
|
12
|
+
|
13
|
+
def colorize(text, color: :default)
|
14
|
+
unless @palette.colors.key?(color)
|
15
|
+
raise ArgumentError, "Invalid color key"
|
16
|
+
end
|
17
|
+
|
18
|
+
color_code = @palette.colors[color]
|
19
|
+
|
20
|
+
unless valid_color_code?(color_code)
|
21
|
+
raise ArgumentError, "Invalid color code"
|
22
|
+
end
|
23
|
+
|
24
|
+
"\e[#{color_code}m#{text}\e[0m"
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def valid_color_code?(color_code)
|
30
|
+
color_code.is_a?(Integer) && color_code.between?(0, 255)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module Utils
|
5
|
+
module Color
|
6
|
+
module Strategy
|
7
|
+
require_relative "strategy/base"
|
8
|
+
require_relative "strategy/basic"
|
9
|
+
require_relative "strategy/rgb"
|
10
|
+
require_relative "strategy/theme"
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def create(type, palette: nil)
|
14
|
+
case type
|
15
|
+
when :basic
|
16
|
+
Basic.new
|
17
|
+
when :rgb
|
18
|
+
Rgb.new
|
19
|
+
when :theme
|
20
|
+
raise ArgumentError, "Palette is required for theme strategy" unless palette
|
21
|
+
|
22
|
+
Theme.new(palette)
|
23
|
+
else
|
24
|
+
raise ArgumentError, "Unknown strategy type: #{type}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -17,8 +17,32 @@ module DevSuite
|
|
17
17
|
},
|
18
18
|
}.freeze
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
attr_reader :settings
|
21
|
+
|
22
|
+
def initialize(settings = {})
|
23
|
+
@settings = deep_merge(DEFAULTS, settings)
|
24
|
+
end
|
25
|
+
|
26
|
+
class << self
|
27
|
+
#
|
28
|
+
# Provide global access to a single instance of Config
|
29
|
+
#
|
30
|
+
def configuration
|
31
|
+
@configuration ||= new
|
32
|
+
end
|
33
|
+
|
34
|
+
# Allow block-based configuration
|
35
|
+
def configure
|
36
|
+
yield(configuration)
|
37
|
+
rescue StandardError => e
|
38
|
+
handle_configuration_error(e)
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def handle_configuration_error(error)
|
44
|
+
puts "Configuration error: #{error.message}"
|
45
|
+
end
|
22
46
|
end
|
23
47
|
|
24
48
|
def color_for(key)
|
@@ -1,10 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "base"
|
4
|
-
require_relative "../formatter/text_aligner"
|
5
|
-
require_relative "../formatter/column_width_calculator"
|
6
|
-
require_relative "../formatter/colorizer"
|
7
|
-
|
8
3
|
module DevSuite
|
9
4
|
module Utils
|
10
5
|
module Table
|
@@ -35,7 +30,7 @@ module DevSuite
|
|
35
30
|
# Colorizes the given string with the specified color
|
36
31
|
#
|
37
32
|
def colorize(str, color)
|
38
|
-
|
33
|
+
Utils::Color.colorize(str, color: color)
|
39
34
|
end
|
40
35
|
|
41
36
|
#
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DevSuite
|
4
|
+
module Utils
|
5
|
+
module Table
|
6
|
+
require_relative "table/table"
|
7
|
+
require_relative "table/column"
|
8
|
+
require_relative "table/row"
|
9
|
+
require_relative "table/config"
|
10
|
+
require_relative "table/formatter"
|
11
|
+
require_relative "table/renderer"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/dev_suite/utils.rb
CHANGED
data/lib/dev_suite/version.rb
CHANGED
data/lib/dev_suite.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dev_suite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Huy Nguyen
|
@@ -83,17 +83,27 @@ files:
|
|
83
83
|
- lib/dev_suite/performance/reportor/base.rb
|
84
84
|
- lib/dev_suite/performance/reportor/simple.rb
|
85
85
|
- lib/dev_suite/utils.rb
|
86
|
+
- lib/dev_suite/utils/color.rb
|
87
|
+
- lib/dev_suite/utils/color/colorizer.rb
|
88
|
+
- lib/dev_suite/utils/color/config.rb
|
89
|
+
- lib/dev_suite/utils/color/palette.rb
|
90
|
+
- lib/dev_suite/utils/color/palette/base.rb
|
91
|
+
- lib/dev_suite/utils/color/palette/default.rb
|
92
|
+
- lib/dev_suite/utils/color/strategy.rb
|
93
|
+
- lib/dev_suite/utils/color/strategy/base.rb
|
94
|
+
- lib/dev_suite/utils/color/strategy/basic.rb
|
95
|
+
- lib/dev_suite/utils/color/strategy/rgb.rb
|
96
|
+
- lib/dev_suite/utils/color/strategy/theme.rb
|
97
|
+
- lib/dev_suite/utils/table.rb
|
86
98
|
- lib/dev_suite/utils/table/column.rb
|
87
|
-
- lib/dev_suite/utils/table/column/column.rb
|
88
99
|
- lib/dev_suite/utils/table/config.rb
|
89
|
-
- lib/dev_suite/utils/table/formatter
|
100
|
+
- lib/dev_suite/utils/table/formatter.rb
|
90
101
|
- lib/dev_suite/utils/table/formatter/column_width_calculator.rb
|
91
102
|
- lib/dev_suite/utils/table/formatter/text_aligner.rb
|
92
103
|
- lib/dev_suite/utils/table/renderer.rb
|
93
104
|
- lib/dev_suite/utils/table/renderer/base.rb
|
94
105
|
- lib/dev_suite/utils/table/renderer/simple.rb
|
95
106
|
- lib/dev_suite/utils/table/row.rb
|
96
|
-
- lib/dev_suite/utils/table/row/row.rb
|
97
107
|
- lib/dev_suite/utils/table/table.rb
|
98
108
|
- lib/dev_suite/version.rb
|
99
109
|
homepage: https://patrick204nqh.github.io
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module DevSuite
|
4
|
-
module Utils
|
5
|
-
module Table
|
6
|
-
module Formatter
|
7
|
-
class Colorizer
|
8
|
-
COLORS = {
|
9
|
-
red: 31,
|
10
|
-
green: 32,
|
11
|
-
yellow: 33,
|
12
|
-
blue: 34,
|
13
|
-
magenta: 35,
|
14
|
-
cyan: 36,
|
15
|
-
white: 37,
|
16
|
-
default: 39,
|
17
|
-
}.freeze
|
18
|
-
|
19
|
-
class << self
|
20
|
-
def code_for(color)
|
21
|
-
COLORS[color] || COLORS[:default]
|
22
|
-
end
|
23
|
-
|
24
|
-
def colorize(text, color = :default)
|
25
|
-
color_code = code_for(color)
|
26
|
-
"\e[#{color_code}m#{text}\e[0m"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|