Giter VIP home page Giter VIP logo

forked_chalk_for_docs's Introduction



Chalk


Rich Text styling done right

Highlights

  • Expressive API
  • Highly performant
  • No dependencies
  • Ability to nest styles
  • Auto-detects color support
  • Clean and focused
  • Actively maintained
  • Extremely Lightweight (less than 250 lines)

Install

-- Run in Roblox Studio Console
local HttpService = game:GetService("HttpService"); 
local ReplicatedStorage = game:GetService("ReplicatedStorage");

HttpService.HttpEnabled = true

local ChalkModule = Instance.new("ModuleScript");
ChalkModule.Name = "Chalk";
ChalkModule.Parent = ReplicatedStorage;

local Request = HttpService:RequestAsync({
    Url = "https://raw.githubusercontent.com/Perthys/chalk/main/source/main.lua";
    Method = "GET";
});

if Request.Success and Request.StatusCode == 200 then
    ChalkModule.Source = Request.Body

    print("Successfully installed Chalk module. At:", ChalkModule);
else
    error("Failed to install Chalk module.");
end

Usage

local ReplicatedStorage = game:GetService("ReplicatedStorage");
local Chalk = require(ReplicatedStorage:WaitForChild("Chalk"));

local TextBox = script.Parent;

TextBox.Text = chalk.blue('Hello world!')

Chalk comes with an easy to use composable API where you just chain and nest the styles you want.

local ReplicatedStorage = game:GetService("ReplicatedStorage");
local Chalk = require(ReplicatedStorage:WaitForChild("Chalk"));

local TextBox = script.Parent;

TextBox.Text = Chalk.blue("Hello") .. 'World' .. chalk.red("!")
TextBox.Text = Chalk.blue.bold("Hello world!")
TextBox.Text = Chalk.blue("Hello", "World!", "Foo", "bar", "biz", "baz")
TextBox.Text = Chalk.red("Hello", Chalk.underline("world") .. "!")
TextBox.Text = Chalk.green(
    "I am a green line " ..
    Chalk.blue.underline.bold("with a blue substring") ..
    " that becomes green again!"
)

TextBox.Text = ([[
CPU: %s
RAM: %s
DISK: %s
]]):format(
    Chalk.red("90%"),
    Chalk.green("40%"),
    Chalk.yellow("70%")
)

TextBox.Text = Chalk.color(123, 45, 67).underline("Underlined reddish color")
TextBox.Text = Chalk.color("#DEADED").bold("Bold gray!")

Easily define your own themes:

local ReplicatedStorage = game:GetService("ReplicatedStorage");
local Chalk = require(ReplicatedStorage:WaitForChild("Chalk"));

local TextBox = script.Parent;

local error = Chalk.bold.red;
local warning = Chalk.color("#FFA500");

TextBox.Text = error("Error!") 
TextBox.Text = warning("Warning!");

Take advantage of string substitution:

local ReplicatedStorage = game:GetService("ReplicatedStorage");
local Chalk = require(ReplicatedStorage:WaitForChild("Chalk"));

local TextBox = script.Parent;

local Name = "Sindre";
TextBox.Text = Chalk.green(("%s"):format(Name))

API

chalk.<style>[.<style>...](string, [string...])

Example: chalk.red.bold.underline('Hello', 'world');

Chain styles and call the last one as a method with a string argument. Order doesn't matter, and earlier styles take precedent in case of a conflict. This simply means that chalk.red.yellow.green is equivalent to chalk.red.

Styles

Modifiers

  • Chalk.[<BrickColorName>] - Index a BrickColor

  • Chalk.bold - Make the text bold

  • Chalk.italic - Make the text italic

  • Chalk.underline - Underline the text

  • Chalk.strikethrough - Strike through the text

  • Chalk.uppercase - Convert text to uppercase

  • Chalk.smallcaps - Convert text to small capitals

  • Chalk.color(Hex) | Chalk.color(R, G, B) | Chalk.color(Color3.new()) - Set the color

  • Chalk.size([<Size>]) - Set the size of the text (Number)

  • Chalk.face([<Face>]) - Set the typeface of the text (String)

  • Chalk.family([<rbxasset://>]) - Set the font family from an asset (String)

  • Chalk.weight([<Weight>]) - Set the font weight (String)

  • Chalk.transparency([<Transparency>]) - Set the transparency of the text (Number 0-1)

  • Chalk.stroke({Color = [<Color>], Joins = [<Joins>], Thickness = [<Thickness>], Transparency = [<Transparency>]}) - Define stroke properties: color (Color3), joins (String), thickness (Number), and transparency (Number)

Colors

  • All BrickColor Colors
  • Chalk.white - Set the color to white
  • Chalk.black - Set the color to black
  • Chalk.red - Set the color to red
  • Chalk.brown - Set the color to brown
  • Chalk.orange - Set the color to orange
  • Chalk.yellow - Set the color to yellow
  • Chalk.lime - Set the color to lime
  • Chalk.green - Set the color to green
  • Chalk.blue - Set the color to blue
  • Chalk.purple - Set the color to purple
  • Chalk.pink - Set the color to pink

256 and Truecolor color support

Chalk supports Color3 and hex colors.

Examples:

  • chalk.color('#DEADED').underline('Hello, world!')
  • chalk.color(15, 100, 204)

The following color models can be used:

  • rgb - Example: chalk.color(255, 136, 0).bold('Orange!')
  • hex - Example: chalk.color('#FF8800').bold('Orange!')

Origin story

Literally made the npm package but for roblox luau richtext Cause I really did not want to do styling manually.

Side Note

ROBLOX PLEASE ADD CONSOLE STYLING I KNOW ITS POSSIBLE JUST ENABLE RICH TEXT

If roblox adds support for background text directly with richtext i will also add support

Maintainers

forked_chalk_for_docs's People

Contributors

aslilac avatar bokub avatar calebboyd avatar jbnicolai avatar kevva avatar ksxgithub avatar lightnerdev avatar litomore avatar lukeapage avatar m4ttsch avatar marado avatar marionebl avatar martinheidegger avatar mischah avatar nazrhyn avatar noamokman avatar paulmelnikow avatar pedrottimark avatar perthys avatar popey456963 avatar qix- avatar richienb avatar saadq avatar seanmonstar avatar simenb avatar sindresorhus avatar stevemao avatar stroncium avatar thefourtheye avatar toonijn 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.