Package Exports
- tty-width-frame
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (tty-width-frame) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
tty-width-frame
Generate simple framed text fitting for the current text terminal
const ttyWidthFrame = require('tty-width-frame');
console.log(ttyWidthFrame(`tty-width-frame
Generate simple framed text from a string`));
┌──────────────────────────────────────────────────────────────────────────┐
│ │
│ tty-width-frame │
│ Generate simple framed text from a string │
│ │
└──────────────────────────────────────────────────────────────────────────┘
- No configuration, a single tidy default
- Single-line border
- 1 padding between text and borders
- 2 horizontal spaces on both side of the box
- Left-aligned text
- Automatic box width adjustment for the current terminal width
- Automatic line breaking for long text
Installation
npm install tty-width-frame
API
const ttyWidthFrame = require('tty-width-frame');
ttyWidthFrame(input)
input: string
Return: string
// When the terminal width is 30
ttyWidthFrame('abcdefghijklmnopqrstuvwxyz');
/* =>
┌────────────────────────┐
│ │
│ abcdefghijklmnopqrstuv │
│ wxyz │
│ │
└────────────────────────┘
*/
// When the terminal width is 20
ttyWidthFrame('abcdefghijklmnopqrstuvwxyz');
/* =>
┌──────────────┐
│ │
│ abcdefghijkl │
│ mnopqrstuvwx │
│ yz │
│ │
└──────────────┘
*/
On a non-interactive script, it thrown an Error
instead.
// cp.js
const ttyWidthFrame = require('tty-width-frame');
ttyWidthFrame('This script throws an error.');
const {execFile} = require('child_process');
const {promisify} = require('util');
(async () => {
const {stderr} = await promisify(execFile)('node', ['cp.js']);
// Error: tty-width-frame only supports TTY environments, but the program is running under a non-TTY environment.
})();
Related project
- neat-frame – works on both TTY and non-TTY environments, in exchange for larger dependency size
License
ISC License © 2018 Shinnosuke Watanabe