• Stars
    star
    113
  • Rank 299,044 (Top 7 %)
  • Language
    Elixir
  • License
    MIT License
  • Created over 8 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

256 color ANSI coloring in Elixir CLIs

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.

More Repositories

1

credo

A static code analysis tool for the Elixir language with a focus on code consistency and teaching.
Elixir
4,720
star
2

inch

A documentation analysis tool for the Ruby language
Ruby
517
star
3

elixir-style-guide

Style Guide for the Elixir language, implemented by Credo
Elixir
395
star
4

elixirstatus-web

Community site for Elixir project/blog post/version updates
Elixir
279
star
5

html_sanitize_ex

HTML sanitizer for Elixir
Elixir
250
star
6

inch_ex

Provides a Mix task that gives you hints where to improve your inline docs.
Elixir
200
star
7

sparkr

▁▂▃▅▂▇ in Ruby (and your shell)
Ruby
151
star
8

inchjs

A documentation tool for JavaScript/NodeJS
JavaScript
48
star
9

tipsy.hovercard

Hovercard extension for tipsy tooltip
JavaScript
33
star
10

inch-pages

Jekyll Page generator for Inch Pages
Ruby
25
star
11

outline

Outline is an open source knowledge management application inspired by timeline focused apps like Facebook and Twitter.
Ruby
9
star
12

inch-badge

Badge generator for Inch
HTML
7
star
13

credo-proposals

Proposals for Credo, the Elixir code analysis tool with a focus on code consistency and teaching
7
star
14

sherlock

A library for filtering lists of files and performing actions on their content.
Ruby
5
star
15

dotfiles

Personal dotfiles
Shell
4
star
16

homecoming

Easy upwards directory traversal in Ruby
Ruby
4
star
17

custom_attributes

CustomAttributes allows you to add custom attributes to ActiveRecord objects, optionally scoped by another model (e.g. users).
Ruby
3
star
18

texas

Texas provides an easy way to create PDFs from LaTeX documents using ERb templates.
Ruby
3
star
19

tps-report

Excel friendly reports for your bosses, clients and the rest.
Ruby
2
star
20

freight-exchange

Source code for a European Online Rail Transport Spot Exchange
Ruby
2
star
21

credo_demo_plugin

A Demo Plugin for Credo
Elixir
2
star
22

outline.github.com

JavaScript
1
star
23

repomen

Interface wrapper for retrieving repos
Ruby
1
star
24

easy_type

Build a complex puppet custom type and provider, the easy way
Ruby
1
star
25

credo-elixir-benchmark

Elixir
1
star