Giter Club home page Giter Club logo

ink's Introduction

License

¡Lee la versión en español aquí!

Ink

Colorize the output of your Lua scripts with Ink like:

local ink = require("Ink")
local my_string = "Hello, #{FG(Green)}world!#{None}"

ink:print(my_string)

And the output looks like this:

Capture 1

You can form more complex outputs like this:

local ink = require("Ink")
local my_string = "#{Bold}This#{None} #{Blink; Italic}is#{None} #{Reverse; FG(RGB(167, 110, 78))}a#{None} #{DobleU; Strike}more#{None} #{BG(146)}complex#{None} %s."
local my_format = "example"

ink:print(my_string, my_format)

Output:

Capture 2

The word "is" has the "Blink" effect, so you can't see in the capture.

Usage

Using Ink is really simple, you only need put the output properties inside of #{}, separating each one using a semicolon (;) and Ink make the rest. Ink allow the following properties:

  • "Effects":
    • None (reset all properties)
    • Bold
    • Dim
    • Italic
    • Underline
    • Blink
    • Reverse
    • Hidden
    • Strike
    • DobleU ("Doble Underline")
  • Colors: you can use colors only with FG() (Foreground) and BG() (Background) functions.
    • Black
    • Red
    • Green
    • Yellow
    • Blue
    • Magenta
    • Cyan
    • White

FG() and BG() functions take 3 types of arguments and only 1 of each it:

  1. A predefined color (one of you see in the above list). Read this
  2. A number from 0 to 255. Read this
  3. A RGB value using the RGB() function. Read this

Ink is case-sensitive. Ink know that FG is a function for foreground colors, but fg is another thing. Also, Ink provide 2 functions/methods:

  1. compile(): takes an string, convert all #{} groups into a ANSI escape code and returns the result string.
  2. print(...): takes an string, formats it with the rest of arguments, passes it to compile() and prints it directly.

Of course, if you want to use manually ANSI codes, Ink provide:

  • Ink.Cache: For internal purposes, contains the cached strings.
  • Ink.DisableCache: Disables the caching if true, false by default.
  • Ink.ESC: The character for colored output (0x1b).
  • Ink.Attr: Maybe the name is not correct, but basically contains the number code for output "effects".
  • Ink.FG: Contains predefined colors (see the first list). You can use it like:
    local ink = require("Ink")
    local my_string = ink.ESC .. "[" .. ink.FG.Green .. "mTesting!" .. ink.ESC .. "[" .. ink.Attr.None
    print(my_string)
  • Ink.BG: same as FG but for background colors.

Is very important to separate properties with a semicolon (please read "Limitations" below).

Limitations

If you don't use semicolons properly, the output maybe wrong because the code behinds Ink is actually simple and don't check this details. The same case if for when you put various semicolons with no properties between each one. Maybe there's others limitations, but I only know these.

Of course, this things are in "TODO" and I want to improve this library.

Sources

I made this using the info provide by Wikipedia in this article

ink's People

Contributors

darltrash avatar miqueas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

darltrash

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.