Git Product home page Git Product logo

ansicolors.lua's Introduction

ansicolors.lua

ansicolors is a simple Lua function for printing to the console in color.

Installation

Put the file ansicolors.lua somewhere where your Lua interpreter will be able to find it. Then:

  local ansicolors = require 'ansicolors'

Usage

  local colors = require 'ansicolors'
  print(colors('%{red}hello'))
  print(colors('%{redbg}hello%{reset}'))
  print(colors('%{bright red underline}hello'))

The colors function makes sure that color attributes are reset at each end of the generated string. If you want to generate complex strings piece-by-piece, use colors.noReset, which works exactly the same, but without adding the reset codes at each end of the string.

Testing

This application uses telescope in order to perform the tests. Install telescope, and then execute


tsc specs/ansicolors_spec.lua

Notice that the tests will only work on an ANSI-compatible machine (windows isn’t ANSI-compatible)

Windows

Windows console, by default, isn’t capable of handling ANSI color codes correctly. This library tries to detect whether it is on a windows machine (by looking at package.path) and in that case it suppresses all ANSI control characters (the text appears devoid of color, but legible).

Valid attribute list:

Misc. attributes:

  • reset
  • bright
  • dim
  • underline
  • blink
  • reverse
  • hidden

Foreground colors:

  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white

Background colors:

  • blackbg
  • redbg
  • greenbg
  • yellowbg
  • bluebg
  • magentabg
  • cyanbg
  • whitebg

ansicolors.lua's People

Contributors

kikito avatar rrthomas avatar robertwahler avatar agladysh avatar doriangray avatar hoelzro avatar

Watchers

James Cloos avatar hangsu,cho avatar  avatar

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.