256 colours for your terminal expressions. You're welcome.
npm install @gesslar/colours256 colours for your terminal expressions. Template literal-based ANSI colour
library with precise colour selection, granular styles, and semantic aliases.
``bash`
npm install @gesslar/colours
`javascript
import c from '@gesslar/colours'
console.log(c{F045}Running:{/} {F213}${testName}{/}){F034}[OK]{/} Build completed {F240}(${time}ms){/}
console.log(c){F196}[ERR]{/} {)
console.log(c
`
Use any colour from the 256-colour terminal palette:
`javascript{F045}Bright green text{/}
// Foreground colours
c{F196}Red text{/}
c{F033}Blue text{/}
c
// Background colours
c{B196}Red background{/}{B045}Green background{/}
c
// Combined
c{F255}{B196}White text on red background{/}`
Turn styles on and off individually:
`javascript{
// Turn on styles
c
c{
c{
// Turn off specific styles
c{
// Available styles:
// - B(old)
// - D(im)
// - F(lash)
// - I(talic)
// - O(verline)
// - R(everse),
// - S(trikethrough)
// - U(nderline)
`
Create meaningful names for your colours:
`javascript
// Set up aliases
c.alias.set("success", "{F034}")
c.alias.set("error", "{F196}")
c.alias.set("warning", "{F214}")
c.alias.set("muted", "{F240}")
// Use them in your code
console.log(c{success}[OK]{/} Operation completed){error}[ERR]{/} Something went wrong
console.log(c){warning}!{/} Check this out {muted}(optional){/}
console.log(c)
// Complex aliases with styles
c.alias.set("header", "{F045}{)`
`javascript
import c from '@gesslar/colours'
// Status messages
const success = (msg) => console.log(c{F034}[OK]{/} ${msg}){F196}[ERR]{/} ${msg}
const error = (msg) => console.log(c){F045}[INFO]{/} ${msg}
const info = (msg) => console.log(c)
success("Build completed successfully")
error("Failed to load configuration")
info(Processing ${count} files...)`
`javascriptRunning: ${testName}
// Before: boring
console.log()[OK] ${testName} passed (${time}ms)
console.log()
// After: beautiful
console.log(c{F045}Running:{/} {F213}${testName}{/}){F034}[OK]{/} {F085}${testName}{/} passed {F240}(${time}ms){/}
console.log(c)`
`javascript{F196}{),
const debug = {
error: (msg) => console.log(c
warn: (msg) => console.log(c{F214}[WARN]{/} ${msg}),{F045}[INFO]{/} ${msg}
info: (msg) => console.log(c),{F240}[DEBUG]{/} ${msg}
debug: (msg) => console.log(c)`
}
- {F###} - Foreground colour (0-255){B###}
- - Background colour (0-255){/}
- - Reset all formatting
- {
- {STYLES>} - Turn off styles (e.g., {B>} to turn off bold)
- B - Bold/BrightD
- - DimF
- - Flash/BlinkI
- - ItalicO
- - OverlineR
- - ReverseS
- - StrikethroughU
- - Underline
- {aliasName} - Any alias you've created
- Built-in: none (you define what you need)
1. Run colours command to see the colour chart (if CLI installed)
2. Pick the colour number you want
3. Use it in your code: c{F045}text{/}`
- ctemplate` - Process template literal with colour codes
- c.alias.set(name, replacement) - Create an aliasc.alias.del(name)
- - Remove an alias
vs ansi-colours:
- Precise colour selection with visual picker
- Cleaner syntax: c{F045}text{/}` vs ansiColors.rgb(255,100,50)('text').yellowBright` actually looks like
- No guessing what
- Granular style control
vs chalk:
- 256-colour palette support
- Template literal syntax
- Semantic aliases you define
- Lighter weight, focused scope
The Unlicense, because colours belong to everybody
and if you disagree, well, you probably _would_ download a car. 🤨
---
_"I want green here, but which green?" -> colours -> "oooo ok that one"_
The workflow that just works.