DEV Community

Abdullah
Abdullah

Posted on

I built a zero-dependency terminal styling toolkit for Node.js

tired of staring at walls of plain console.log? i built termpainter to fix that.

it is a small npm package that gives your terminal output actual structure. semantic styles, boxes, badges, tables, timestamps, spinners. zero dependencies, full TypeScript support, works in Node 18+ and Bun.

install

npm install termpainter
Enter fullscreen mode Exit fullscreen mode

what it does

semantic styles

instead of hardcoding colors every time, you call what you mean:

style.success('Build complete')       // ✔ green
style.error('Connection failed')      // ✖ red
style.warn('Disk usage at 87%')       // ⚠ yellow
style.info('Server started on :3000') // ℹ blue
style.muted('debug: cache hit')       // gray, dimmed
Enter fullscreen mode Exit fullscreen mode

structured log output

any style method accepts an optional object as a second argument:

style.info('User created', { id: 123, role: 'admin' })
// ℹ User created
//   id    123
//   role  admin
Enter fullscreen mode Exit fullscreen mode

boxes

box('Deploy complete\n3 services restarted\nAll checks passed', 'green')
box(style.success('done'))  // fully composable
Enter fullscreen mode Exit fullscreen mode

spinner

const s = spin('Deploying...')
s.succeed('Deploy complete')
s.fail('Something went wrong')
Enter fullscreen mode Exit fullscreen mode

strip

useful for writing styled output to log files without escape codes:

fs.appendFileSync('app.log', strip(style.info('Server started')) + '\n')
Enter fullscreen mode Exit fullscreen mode

debug helper

style.debug('cache miss')  // only shows when DEBUG=1
Enter fullscreen mode Exit fullscreen mode

why i built it

i kept writing the same boilerplate across projects. chalk for colors, manual icon prefixes, rolling my own box drawing every time. termpainter packages all of that into one small thing with a clean API.

it also respects NO_COLOR, CI environments, and non-TTY output automatically so your logs do not get filled with broken escape sequences.

links

feedback welcome, this is v1.2.0 and i am actively maintaining it.

Top comments (0)