All Tips

Tool of the Trade for CLI Apps - `Boxen` πŸ”²

This is a series of libraries and utilities for building Command-line-interfaces aka CLI using Node.js and ecosystem around it. Similar utilities/helpers may be available for other languages but, these series is focused on JavaScript and its friends.

You can check all articles under CLI Build Tool tag.

boxen

If you are building a CLI and need to present some good output wrapped in box! Yes, square box, β€˜boxen’ is the tool for you. Just like you had seen boxes around output of update-notifier. It makes the CLI app more appealing.

Screenshot

It can present your application output in boxes with various styles like β€˜double dashed’, β€˜rounded corners’ along with some β€˜margin’ and β€˜padding’ options.

Screenshot

Boxen has a very easy to follow, simple to use API. Here is a code example:

const boxen = require('boxen');

console.log(boxen('unicorn', { padding: 1 }));
/*
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚             β”‚
β”‚   unicorn   β”‚
β”‚             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
*/

console.log(boxen('unicorn', { padding: 1, margin: 1, borderStyle: 'double' }));
/*

   ╔═════════════╗
   β•‘             β•‘
   β•‘   unicorn   β•‘
   β•‘             β•‘
   β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•

*/

You can check out official repo for all usage details.

Github Repo: boxen


Published Jun 26, 2019

Web/Product Engineer.