plasma

An easy-to-use composable ANSI styling API
https://github.com/hackx2/plasma

To install, run:

haxelib install plasma 1.0.0 

See using Haxelib in Haxelib documentation for more information.

README.md

Plasma

Plasma

A type-safe, native Haxe library for terminals, providing a Chalk-like, easy-to-use, composable ANSI API, and other utilities such as, cursor, screen, and buffer manipulation. \ Known Support Platforms: hl, py, njs, js, cpp, cppia, and neko.


Usage

final plasma = new plasma.Plasma({level: TRUE_COLOR}); // Max Level

trace(plasma.yellow.bold.apply('Mrraow', 'Meow', 'Mrrp', 'Nya', 'Mlem'));

Combined styles showcase

final red:Plasma = new Plasma().hex(0xFF0000);
final bold:Plasma = new Plasma().bold;

trace((red + bold) + "CRITICAL MEOW DETECTED");

Merged style instances showcase

For additional usage examples, please refer to /tests

API

plasma.<style>[.<style>...].apply(string, [string...])

e.g. plasma.blue.bold.underline.apply("Hello,", "world!");

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

Multiple arguments will be separated by space.


Modifiers

Primary ConstantEnumAliases
resetReset-
boldBoldstrong
dimDimfaint
italicItalic-
underlineUnderline-
overlineOverline-
inverseInverseinvert reverse
hiddenHiddenconceal
strikethroughStrikethrough-
visibleVisible-

Color Styles

Base HueForegroundBackgroundAliases
Base Variants
BlackblackbgBlack-
RedredbgRed-
GreengreenbgGreen-
YellowyellowbgYellow-
BluebluebgBlue-
MagentamagentabgMagentapink bgPink
CyancyanbgCyanaqua bgAqua
WhitewhitebgWhite-
Bright Variants
Bright BlackblackBrightbgBlackBrightgray grey
Bright RedredBrightbgRedBright-
Bright GreengreenBrightbgGreenBright-
Bright YellowyellowBrightbgYellowBright-
Bright BlueblueBrightbgBlueBright-
Bright MagentamagentaBrightbgMagentaBrightpinkBright
Bright CyancyanBrightbgCyanBrightaquaBright
Bright WhitewhiteBrightbgWhiteBright-

Since Chrome 69, ANSI escape codes are natively supported in the developer console.


Utilities

CategoryMethodEnumDescription
CursorTerminal.hideCursor()HideCursorSuppresses the visibility of the terminal Cursor.
CursorTerminal.showCursor()ShowCursorRestores Cursor visibility to the user interface.
CursorTerminal.saveCursor()SaveCursorCaptures the current spatial coordinates of the Cursor.
CursorTerminal.restoreCursor()RestoreCursorReinstates the Cursor to its previously recorded position.
ScreenTerminal.clearScreen()ClearScreenClears all content from the current, active terminal Buffer.
ScreenTerminal.clearLine()ClearLineClears all textual data on the current Cursor line.
BufferTerminal.enterAltBuffer()EnterAltBufferInitializes the secondary alternate Screen environment Buffer.
BufferTerminal.leaveAltBuffer()LeaveAltBufferTerminates the alternate Buffer and returns to the primary view.
SystemTerminal.beep()BellTriggers an audible hardware-based notification signal.

Contributors
hackx2
Version
1.0.0
Published
2 months ago
License
MIT

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub