Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
ANSI colors and syntactic color highlightening
Provides a module with functions to create ANSI color codes. The module can be included into String for convenience.
It also provides a parser that changes color instruction inside a string to according ANSI codes, and a command line tool that does this for input.
The behavior and use of this gem is documented here by means of speculations
Given the L43::Color module
let(:color) { L43::Color }
Then we can ask for ANSI codes
expect(L43::Color.ansi_code("yellow")).to eq("\e[33m")
expect(L43::Color.ansi_code("bg_black")).to eq("\e[40m")
expect(L43::Color.ansi_code("reset")).to eq("\e[0m")
expect(L43::Color.ansi_code("dim")).to eq("\e[2m")
And if we try a nonexisting color we get an error
expect { L43::Color.ansi_code("no_color") }.to raise_error(IndexError, "key not found: :no_color")
Given the inclusion of the string inject module
require 'l43/color/string_methods'
Then we can make colored strings as follows
expect("red".red).to eq("\e[31mred")
Given the following
require 'l43/color/methods'
Then we can get the ANSI codes as functions
expect(L43::Color::Methods.cyan).to eq("\x1b[36m")
And to get rid of the long name this module can be included
c = Class.new do
include L43::Color::Methods
end
expect(c.new.blue).to eq("\e[34m")
Or extended
m = Module.new do
extend L43::Color::Methods
end
expect(m.magenta).to eq("\e[35m")
They allow to alternate strings (to be printed verbatim) and symbols that will output ANSI codes
Given they are included
require 'l43/color/output'
include L43::Color::Output
Then we can use them to output to stdout
expected = "\e[31mhello\e[0mworld\n"
expect { putcol([:red, "hello", :reset, "world"]) }
.to output(expected).to_stdout_from_any_process
expect { putcol([:red, "hello", :reset, "world"], to: :stdout) }
.to output(expected).to_stdout_from_any_process
Or we can use them to output to stderr
expected = "\e[41mhello\e[4mworld\n"
expect { putcol([:bg_red, "hello", :ul, "world"], to: :stderr) }
.to output(expected).to_stderr_from_any_process
expect { putcol([:bg_red, "hello", :ul, "world"], to: $stderr) }
.to output(expected).to_stderr_from_any_process
Copyright © 2024 Robert Dober robert.dober@gmail.com
GNU AFFERO GENERAL PUBLIC LICENSE, Version 3, 19 November 2007. Please refer to LICENSE for details.
FAQs
Unknown package
We found that l43_color demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.