GithubHelp home page GithubHelp logo

bunt's Introduction

Bunt

Enables 256 color ANSI coloring in the terminal and gives you the ability to alias colors to more semantic and application-specfic names.

Installation

It's available via Hex:

  1. Add bunt to your list of dependencies in mix.exs:

    def deps do [{:bunt, "~> 1.0"}] end

  2. Ensure bunt is started before your application:

    def application do [extra_applications: [:bunt]] end

Usage

256 colors

Colors

IO.ANSI provides an interface to write text to the terminal in eight different colors like this:

["Hello, ", :red, :bright, "world!"]
|> IO.ANSI.format
|> IO.puts

This will put the word "world!" in bright red.

To cause as little friction as possible, the interface of Bunt.ANSI is 100% adapted from IO.ANSI.

We can use Bunt in the same way:

["Hello, ", :color202, :bright, "world!"]
|> Bunt.ANSI.format
|> IO.puts

which puts a bright orange-red "world!" on the screen.

Bunt also provides a shortcut so we can skip the format call.

["Hello, ", :color202, :bright, "world!"]
|> Bunt.puts

and since nobody can remember that :color202 is basically :orangered, you can use :orangered directly.

Named colors

The following colors were given names, so you can use them in style:

[:gold, "Look, it's really gold text!"]
|> Bunt.puts

Replace :gold with any of these values:

darkblue      mediumblue    darkgreen     darkslategray darkcyan
deepskyblue   springgreen   aqua          dimgray       steelblue
darkred       darkmagenta   olive         chartreuse    aquamarine
greenyellow   chocolate     goldenrod     lightgray     beige
lightcyan     fuchsia       orangered     hotpink       darkorange
coral         orange        gold          khaki         moccasin
mistyrose     lightyellow

You can see all supported colors by cloning the repo and running:

$ mix run script/colors.exs

User-defined color aliases

But since all these colors are hard to remember, you can alias them in your config.exs:

# I tend to start the names of my color aliases with an underscore
# but this is, naturally, not a must.

config :bunt, color_aliases: [_cupcake: :color205]

Then you can use these keys instead of the standard colors in your code:

[:_cupcake, "Hello World!"]
|> Bunt.puts

Use this to give your colors semantics. They get easier to change later that way. (A colleague of mine shouted "It's CSS for console applications!" when he saw this and although that is ... well, not true, I really like the sentiment! 👍)

Contributing

  1. Fork it!
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Author

René Föhring (@rrrene)

License

Bunt is released under the MIT License. See the LICENSE file for further details.

"Elixir" and the Elixir logo are copyright (c) 2012 Plataformatec.

Elixir source code is released under Apache 2 License.

Check NOTICE, ELIXIR-LICENSE and LICENSE files for more information.

bunt's People

Contributors

craigp avatar mad42 avatar mitchellhenke avatar raphexion avatar rrrene avatar vitortrin avatar zeroasterisk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bunt's Issues

This doesn't work when building the escript.

I tried using this in a script compiled through escript.build, and the colors weren't printing out. I've had more troubles with the IO Device in general with the escript, something about it not running in the right shell... Anyway, just thought I'd let you know, you may want to close this as a won't fix.

Is this package compatible with windows ?

Hi,

At work, we are currently on windows (7 & 10). This package outputs weird symbols and no colors.

Is it possible to make it work through a compatibility config ?

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.