Skip to content

Commit

Permalink
Upgrade documentations
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcioFPaludo committed Oct 21, 2024
1 parent ca2fb6b commit ff67ce4
Show file tree
Hide file tree
Showing 15 changed files with 228 additions and 208 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@
AllCops:
TargetRubyVersion: 2.6

Layout/TrailingWhitespace
Enabled: false
Metrics/BlockLength:
Enabled: false
16 changes: 15 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
{
"simplecov-vscode.enabled": true
"simplecov-vscode.enabled": true,
"[ruby]": {
"editor.defaultFormatter": "Shopify.ruby-lsp",
"editor.semanticHighlighting.enabled": true,
"files.trimTrailingWhitespace": false,
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"editor.insertSpaces": true,
"editor.tabSize": 2,
"editor.rulers": [
120
],
},
}
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ group :development do
gem 'redcarpet'
gem 'rubocop'
gem 'solargraph'
# Yard dependencies
gem 'webrick'
gem 'yard'
end
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ message = Message.new('example/message', replaces: custom_replaces)
puts message.to_s
```
Output:
![Code Output](./.resources/images/foreground_colored_example.png)
![Code Output](./images/foreground_colored_example.png)

For more information about colors, backgrounds, and effects, consult the [documentation of ANSIStyleManager](https://marciofpaludo.github.io/ruby-mp-utils/ANSIStyleManager.html).

Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ namespace :doc do
desc 'Generate all needed documentation'
task :generate do
system('yard doc')
source_dir = '.resources/images'
destination_dir = 'doc/.resources/images'
source_dir = 'images'
destination_dir = 'doc/images'
FileUtils.mkdir_p(destination_dir)
Dir.glob("#{source_dir}/*.{png,jpg,jpeg,gif}").each do |image|
FileUtils.cp(image, destination_dir)
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
48 changes: 24 additions & 24 deletions lib/utils/ansi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

require_relative 'constants'

# The ANSI class is responsible for generating ANSI codes for text styling in terminals.
# It allows the combination of multiple style and color codes.
# The ANSI class is responsible for generating ANSI codes for text styling in terminals.
# It allows the combination of multiple style and color codes.
#
# @example
# ansi = ANSI.new(:bold)
# puts ansi.to_s # => "\e[1m"
# @example
# ansi = ANSI.new(:bold)
# puts ansi.to_s # => "\e[1m"
#
# @example
# ansi = ANSI.new([:bold, :red])
# puts ansi.to_s # => "\e[1;31m"
# @example
# ansi = ANSI.new([:bold, :red])
# puts ansi.to_s # => "\e[1;31m"
class ANSI
# Hash that maps style and color names to their respective ANSI codes.
# Hash that maps style and color names to their respective ANSI codes.
CODES_HASH = {
reset_all: 0,

Expand Down Expand Up @@ -66,12 +66,12 @@ class ANSI
reset_background: 49
}.freeze

# @return [Array<Integer>] the ANSI codes stored in the instance.
# @return [Array<Integer>] the ANSI codes stored in the instance.
attr_reader :codes

# Initializes a new instance of the ANSI class.
# Initializes a new instance of the ANSI class.
#
# @param code [Array<Symbol>, Symbol, String] One or more ANSI codes represented as symbols, integers, or strings.
# @param code [Array<Symbol>, Symbol, String] One or more ANSI codes represented as symbols, integers, or strings.
def initialize(code)
@codes = if code.is_a?(Array)
ANSI.normalize_array_codes(code)
Expand All @@ -82,36 +82,36 @@ def initialize(code)
end
end

# Adds ANSI codes from another instance of the ANSI class.
# Adds ANSI codes from another instance of the ANSI class.
#
# @param ansi [ANSI] The instance of the ANSI class whose codes will be added.
# @return [ANSI] A new instance of the ANSI class with the combined codes.
# @raise [RuntimeError] If the argument is not an instance of the ANSI class.
# @param ansi [ANSI] The instance of the ANSI class whose codes will be added.
# @return [ANSI] A new instance of the ANSI class with the combined codes.
# @raise [RuntimeError] If the argument is not an instance of the ANSI class.
def append(ansi)
raise 'Needs be an instance of ANSI' unless ansi.is_a?(ANSI)

ANSI.new(@codes.union(ansi.codes))
end

# Adds ANSI codes from another instance of the ANSI class and updates the current instance.
# Adds ANSI codes from another instance of the ANSI class and updates the current instance.
#
# @param ansi [ANSI] The instance of the ANSI class whose codes will be added.
# @return [void]
# @param ansi [ANSI] The instance of the ANSI class whose codes will be added.
# @return [void]
def append!(ansi)
@codes = append(ansi).codes
end

# Converts the ANSI codes stored in the instance to a formatted string.
# Converts the ANSI codes stored in the instance to a formatted string.
#
# @return [String] The formatted string with the ANSI codes.
# @return [String] The formatted string with the ANSI codes.
def to_s
"\e[#{@codes.flatten.join(';')}m"
end

# Normalizes an array of codes, converting symbols and strings to their respective ANSI codes.
# Normalizes an array of codes, converting symbols and strings to their respective ANSI codes.
#
# @param array [Array<Symbol, String, Integer>] An array of codes to be normalized.
# @return [Array<Integer>] The normalized array of ANSI codes.
# @param array [Array<Symbol, String, Integer>] An array of codes to be normalized.
# @return [Array<Integer>] The normalized array of ANSI codes.
def self.normalize_array_codes(array)
array.map do |value|
next normalize_array_codes(value) if value.is_a?(Array)
Expand Down
Loading

0 comments on commit ff67ce4

Please sign in to comment.