Giter VIP home page Giter VIP logo

luatext's Introduction

LuaText

A small library to print colored text to the console.



LuaText should be compatible with LuaJIT 2.1, Lua 5.1, 5.2, 5.3, and 5.4.

Example

A simple example to render an entire string in red on a black background, underlined:

local text = require("luatext")

local my_str = text
    .Text
    :new("Hello world!!")
    :fg(160)  -- red as an ANSI256 color code
    :bg({0, 0, 0}) -- black as an RGB value
    :underlined()

print(my_str)

Running this code will produce the following output:

Output from a simple example

You can also add substrings to your text. The substrings will inherit the formatting of the parent text. Thus you can for instance run:

local text = require("luatext")

local my_str = text
    .Text
    :new()
    :fg(text.Color.Red)
    :append(
      "Hello ",
      text.Text:new("beautiful"):underlined(),
      " world"
    )

print(my_str)

Which will produce a fully red string, with only the substring beautiful underlined:

Output from an example with substrings

A LuaText object can also be used as a standard string:

local text = require("luatext")

print("Hello "..text.Text:new("fading"):blink().." world...")

Which will print Hello fading world... with the word fading blinking.

Reference

For a full reference of the API, see the reference.

NO_COLOR

This library supports NO_COLOR.

Installation

This module is hosted on LuaRocks and can thus be installed via:

luarocks install luatext

Otherwise, since the module is fully self contained, one can also simply copy the luatext.lua into their project.

ANSI256 Color Codes

To get a list of ANSI color codes run:

curl -s https://gist.githubusercontent.com/HaleTom/89ffe32783f89f403bba96bd7bcd1263/raw/e50a28ec54188d2413518788de6c6367ffcea4f7/print256colours.sh | bash

Development

You can setup a dev environment with the needed Lua version:

# launch shell with some lua version and the dependencies installed:
nix develop .#lua52

and then test with busted.

luatext's People

Contributors

f4z3r avatar

Stargazers

Nelson II avatar Sandenberg Ferreira Melo avatar

Watchers

 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.