mp-utils 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/resources/path_helper.rb +6 -3
- data/lib/utils/ansi_style_manager.rb +74 -4
- data/lib/utils/key.rb +0 -3
- data/lib/utils/message.rb +8 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 472fb772fc669be45aee52e5f931823934e59cb5f36974536dbfea782024ac9d
|
4
|
+
data.tar.gz: 9c5079304a471c97261ec621457575b1b79c9454a8a60f7d19ee9b0a51a7c777
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79864c2f162bb4d136ae0762d4196c868e0ce4136a31bb873ce79289478734f442acfc18e882d942b53b15e26c570a8b4d18c144f88d1ceae4573c01121583d8
|
7
|
+
data.tar.gz: cd1ed6a8fdb3c724d1953c0df5107468936b5a4800b537097ca32d3f134123c93f39c45ee327a347037e6246fe23600030128fe12f7371034d11bca9fb347204
|
@@ -1,10 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# The Resources module manages and provides access to file system paths used by a script or application.
|
4
|
+
#
|
4
5
|
# It facilitates the definition and retrieval of a default library path, alongside a customizable path
|
5
|
-
# that can be set at runtime either programmatically using the {define} method or through the
|
6
|
-
# variable "SCRIPT_CUSTOM_RESOURCES".
|
7
|
-
#
|
6
|
+
# that can be set at runtime either programmatically using the {define} method or through the
|
7
|
+
# environment variable "SCRIPT_CUSTOM_RESOURCES".
|
8
|
+
#
|
9
|
+
# This flexibility allows applications to dynamically access resources stored in various locations,
|
10
|
+
# depending on execution environment or user-defined settings.
|
8
11
|
module Resources
|
9
12
|
# Retrieves the path to the directory containing this module, which serves as the default library path.
|
10
13
|
#
|
@@ -4,11 +4,81 @@ require_relative 'constants'
|
|
4
4
|
require_relative 'ansi'
|
5
5
|
|
6
6
|
# The ANSIStyleManager class is responsible for managing and applying ANSI styles to a given string.
|
7
|
-
# It can replace tokens in the string with corresponding ANSI codes for colors and effects.
|
8
7
|
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
8
|
+
# It can replace tokens in the string with corresponding ANSI codes for colors, backgrounds and effects.
|
9
|
+
#
|
10
|
+
# ## Effects
|
11
|
+
# Effects can be used by adding `<effect:effect_name>` at the beginning and `</effect>` at the end of
|
12
|
+
# the sequence of characters to which you want the effect to be applied.
|
13
|
+
#
|
14
|
+
# Example:
|
15
|
+
# ```ruby
|
16
|
+
# manager = ANSIStyleManager.new('The text <effect:bold>Potato</effect> will be bold.')
|
17
|
+
# puts manager
|
18
|
+
# ```
|
19
|
+
# Output:
|
20
|
+
#
|
21
|
+
# 
|
22
|
+
#
|
23
|
+
# Below is the table with all available effects:
|
24
|
+
#
|
25
|
+
# | Effect Name | Description |
|
26
|
+
# |---------------|----------------------------|
|
27
|
+
# | bold | set bold mode. |
|
28
|
+
# | faint | set dim/faint mode. |
|
29
|
+
# | italic | set italic mode. |
|
30
|
+
# | underline | set underline mode. |
|
31
|
+
# | blinking | set blinking mode. |
|
32
|
+
# | inverse | set inverse/reverse mode. |
|
33
|
+
# | hidden | set hidden/invisible mode. |
|
34
|
+
# | strike | set strikethrough mode. |
|
35
|
+
# | plain | set double underline mode. |
|
36
|
+
#
|
37
|
+
# > **Note:** Some terminals may not support some of the effects listed above.
|
38
|
+
#
|
39
|
+
# ## Colors
|
40
|
+
# The ANSIStyleManager supports 3 types of coloring: Named Colors, RGB Colors, or 256 Colors.
|
41
|
+
#
|
42
|
+
# The foreground color can be changed by adding `<color:color_type>` at the beginning and `</color>`
|
43
|
+
# at the end of the character sequence you want to color.
|
44
|
+
#
|
45
|
+
# Example:
|
46
|
+
# ```ruby
|
47
|
+
# text = 'A <color:green>colorful <color:red>world <color:yellow>is <color:blue>much '
|
48
|
+
# text += '</color>more </color>beautiful</color>!</color> ;)'
|
49
|
+
# manager = ANSIStyleManager.new(text)
|
50
|
+
# puts manager
|
51
|
+
# ```
|
52
|
+
# Output:
|
53
|
+
#
|
54
|
+
# 
|
55
|
+
#
|
56
|
+
# It is also possible to set the background color of a text.
|
57
|
+
#
|
58
|
+
# The background color can be changed by adding `<color:color_type:color_type>` at the
|
59
|
+
# beginning and `</color>` at the end of the character sequence you want to color.
|
60
|
+
#
|
61
|
+
# Example:
|
62
|
+
# ```ruby
|
63
|
+
# text = 'A <color:green:white>colorful <color:196>world <color:yellow:111>is <color:blue:255;255;255>much '
|
64
|
+
# text += '</color>more </color>beautiful</color>!</color> ;)'
|
65
|
+
# manager = ANSIStyleManager.new(text)
|
66
|
+
# puts manager
|
67
|
+
# ```
|
68
|
+
#
|
69
|
+
# Output:
|
70
|
+
#
|
71
|
+
# 
|
72
|
+
#
|
73
|
+
# Below is the table with all available color type patterns:
|
74
|
+
#
|
75
|
+
# |Color Type |Pattern |Description |
|
76
|
+
# |-------------|--------|---------------------------------------------------------------------------------------------|
|
77
|
+
# |Reset colors |reset |Resets to the terminal's default color. |
|
78
|
+
# |256 Colors |number |Accepts numbers between 0 and 255. |
|
79
|
+
# |RGB Colors |R;G;B |R, G, and B accept values between 0 and 255. |
|
80
|
+
# |Named Colors |name |Accepts the following color names: black, red, green, yellow, blue, magenta, cyan and white. |
|
81
|
+
#
|
12
82
|
class ANSIStyleManager
|
13
83
|
# @return [String] the string to which ANSI styles will be applied.
|
14
84
|
attr_reader :string
|
data/lib/utils/key.rb
CHANGED
data/lib/utils/message.rb
CHANGED
@@ -4,11 +4,15 @@ require_relative File.join('..', 'resources', 'path_helper')
|
|
4
4
|
require_relative 'key'
|
5
5
|
|
6
6
|
# The Message class represents a mechanism for dynamically handling and formatting messages.
|
7
|
+
#
|
7
8
|
# It supports the substitution of placeholders within a message template with actual data.
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
9
|
+
#
|
10
|
+
# The class leverages file-based message templates, allowing for easy localization or
|
11
|
+
# customization of messages.
|
12
|
+
#
|
13
|
+
# It integrates seamlessly with the Resources module to access these templates from
|
14
|
+
# a customizable path set via the "SCRIPT_CUSTOM_RESOURCES" environment variable or
|
15
|
+
# from a default library path.
|
12
16
|
#
|
13
17
|
# @example Creating a new Message instance and formatting it
|
14
18
|
# # Assuming "hellow_world" is a file that says "Hello, world!"
|
@@ -46,10 +50,7 @@ class Message
|
|
46
50
|
new_message = replace_message_keys(String.new(@message))
|
47
51
|
replace_all_to_replace_elements(new_message)
|
48
52
|
end
|
49
|
-
end
|
50
53
|
|
51
|
-
# Private Methods
|
52
|
-
class Message
|
53
54
|
private
|
54
55
|
|
55
56
|
# Determines the custom path for message files, if set through the "SCRIPT_CUSTOM_RESOURCES" environment variable.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mp-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcio F Paludo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
Helpers to facilitate scripts Writing.
|