GithubHelp home page GithubHelp logo

colorify's People

Contributors

mainak90 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

mofesola alankis

colorify's Issues

A note on the lib design

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 :)

Allow the user to choose when the color is enable/disable or auto

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:

  1. Coloring will be enable/disable automatically based on the isatty() function (which is the default)
  2. Enable coloring
  3. Disable coloring

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.

Add CI

GH actions pipeline to be added into the project.
Pipeline to run before merge to main branch.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.