tty-width-frame

1.0.3 • Public • Published

tty-width-frame

npm version Build Status Coverage Status

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

Use npm.

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           │
  │              │
  └──────────────┘
*/

When the terminal window is too narrow, or more specifically, its width is less than 15, it just returns the original string.

// When the terminal width is 14
 
ttyWidthFrame('abcdefghijklmnopqrstuvwxyz'); //=> 'abcdefghijklmnopqrstuvwxyz'

On a non-interactive script, it throws an Error instead.

Related project

  • neat-frame – works on both TTY and non-TTY environments, in exchange for larger dependency size

License

ISC License © 2018 - 2019 Watanabe Shinnosuke

Package Sidebar

Install

npm i tty-width-frame

Weekly Downloads

6

Version

1.0.3

License

ISC

Unpacked Size

6.31 kB

Total Files

4

Last publish

Collaborators

  • shinnn