mainak90 / colorify Goto Github PK
View Code? Open in Web Editor NEWGolang library for colorful terminal output
License: MIT License
Golang library for colorful terminal output
License: MIT License
First of all, nice lib!
The idea of:
// Start the init function
redPrint := red.New()
yellowPrint := yellow.New()
yellowPrint.Println("This is yellow regular!!!")
or, representing each color as object is an interesting idea. However, if a cli program wants to have 4 or more colors in its output, like a column-based colorizer which is usually done for coloring logs, this could lead to a lot of go objects that needs to be instantiated. Thus, maybe representing a simple or static function that you call directly, for example:
colorify.Yellow("This line is yellow: %s", yellowWord)
colorify.Red("This line is red: %s", redWord)
without requiring an object to be new()
might make the library caller a bit simpler to deal with it. Alternatively, you could have one single initialization of the object, the colorify
object as then use for the other colors:
color = colorify.New(....)
color.Yellowf("This line is yellow: %s", yellowWord)
color.Redf("This line is red: %s", redWord)
Isn't too bad to make new()
all variable, but; it make simpler to use if such or similar facilities are available. And, we the lib could simply allow both way and the caller decide which one to pick for its program :)
The func (c *Colorify) New() *Colorify, function uses the isatty()
to decide when to enable/disable the color based on whether the stdout
or /fd/1
points to terminal-like file description. This is very nice way to make the coloring disable automatically when no-terminal is presented. The code will, also; disable coloring when a stdout redirection, such as |
; is made on the program. For instance, something like:
log-colorizer file.log | grep -i PCI
will automatically disable the coloring of my program when use colorify
library. As developer, I might to carry over the coloring when a non-terminal like file description is presented. For instance, the user might not want to loose the colors if when using a paginator such as less
or more
.
Therefore, I think it will be nice idea to allow the caller of the library to decide whether:
isatty()
function (which is the default)which is usually expose in the form an command-line option (i.e: --color=auto|true|false
,) for the cli program. Then, allowing the user to disable/enable at will and leaving the default behavior to automatically decide -- which is the current code.
One implementation will be to teach the New()
function a new option that will have three-state variable: auto
, true
or false
, given the developer and, potentially; the user to actually decide when color should be present or not.
GH actions pipeline to be added into the project.
Pipeline to run before merge to main branch.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.