条形
在终端中创建框

安装
$ npm install boxen
使用量
const boxen = require('boxen');
console.log(boxen('unicorn', {padding: 1}));
/*
┌─────────────┐
│ │
│ unicorn │
│ │
└─────────────┘
*/
console.log(boxen('unicorn', {padding: 1, margin: 1, borderStyle: 'double'}));
/*
╔═════════════╗
║ ║
║ unicorn ║
║ ║
╚═════════════╝
*/
console.log(boxen('unicorns love rainbows', {title: 'magical', titleAlignment: 'center'}));
/*
┌────── magical ───────┐
│unicorns love rainbows│
└──────────────────────┘
*/
API 密码
boxen( 文本, 选项 )
文本
类型 : string
箱内有文字.
选项
类型 : object
边框颜色
类型 : string
数值 : 'black' 'red' 'green' 'yellow' 'blue' 'magenta' 'cyan' 'white' 'gray' 或十六进制值 '#ff0000'
框边框的颜色.
边框样式
类型 : string | object
默认 : 'single'
数值 :
'single'
┌───┐
│foo│
└───┘
'double'
╔═══╗
║foo║
╚═══╝
'round'(单位:千美元)'single'圆角相接)
╭───╮
│foo│
╰───╯
'bold'
┏━━━┓
┃foo┃
┗━━━┛
'singleDouble'(单位:千美元)'single'上下两地,'double'左右两侧)
╓───╖
║foo║
╙───╜
'doubleSingle'(单位:千美元)'double'上下两地,'single'左右两侧)
╒═══╕
│foo│
╘═══╛
'classic'
+---+
|foo|
+---+
框边框的样式.
可以是上面任何预先定义的样式,也可以是带有以下密钥的对象:
{
topLeft: '+',
topRight: '+',
bottomLeft: '+',
bottomRight: '+',
horizontal: '-',
vertical: '|'
}
淡出边界
类型 : boolean
默认 : false
减少边界的不透明度.
标题
类型 : string
框上方显示标题. 如果需要,框会横向扩展以适应标题.
示例
console.log(boxen('foo bar', {title: 'example'}));
/*
┌ example ┐
│foo bar │
└─────────┘
*/
标题对齐
类型 : string
默认 : 'left'
在上行对齐标题 .
数值 :
'left'
/*
┌ example ──────┐
│foo bar foo bar│
└───────────────┘
*/
'center'
/*
┌─── example ───┐
│foo bar foo bar│
└───────────────┘
*/
'right'
/*
┌────── example ┐
│foo bar foo bar│
└───────────────┘
*/
粘贴
类型 : number | object
默认 : 0
文本和框边框之间的空格 .
接受带有其中任何一个数字或对象 top, (中文(简体) ), right, (中文(简体) ), bottom, (中文(简体) ), left 属性。 当指定一个数字时, 左/ 右粘接是上/ 下相加的3 倍, 使其看起来不错 .
边距
类型 : number | object
默认 : 0
围绕盒子的空间.
接受带有其中任何一个数字或对象 top, (中文(简体) ), right, (中文(简体) ), bottom, (中文(简体) ), left 属性。 当指定一个数字时,左/右比值为上/下相差3倍,使其看起来不错.
浮动
类型 : string
默认 : 'left'
数值 : 'right' 'center' 'left'
在可用的终端屏幕空间上浮出盒子.
背景颜色
类型 : string
数值 : 'black' 'red' 'green' 'yellow' 'blue' 'magenta' 'cyan' 'white' 'gray' 或十六进制值 '#ff0000'
背景颜色 .
文本对齐
类型 : string
默认 : 'left'
数值 : 'left' 'center' 'right'
基于最宽行对齐框中的文本 .