@poppinss/cliui
Advanced tools
Comparing version 5.0.0-0 to 5.1.0-0
@@ -10,2 +10,4 @@ import type { Colors } from '@poppinss/colors/types'; | ||
useColors(color: Colors): this; | ||
fullScreen(): this; | ||
drawBorder(callback: (borderChar: string, colors: Colors) => string): this; | ||
heading(text: string): this; | ||
@@ -12,0 +14,0 @@ add(text: string): this; |
@@ -19,10 +19,5 @@ import boxes from 'cli-boxes'; | ||
#options; | ||
#totalColumns = process.stdout.columns - 2; | ||
#getHorizontalLength() { | ||
const length = this.#widestLineLength + this.#leftPadding + this.#rightPadding; | ||
if (length > this.#totalColumns) { | ||
return this.#totalColumns; | ||
} | ||
return length; | ||
} | ||
#drawBorder = (border, colors) => { | ||
return colors.dim(border); | ||
}; | ||
constructor(options = {}) { | ||
@@ -34,2 +29,5 @@ this.#options = { | ||
} | ||
#getHorizontalLength() { | ||
return this.#widestLineLength + this.#leftPadding + this.#rightPadding; | ||
} | ||
#repeat(text, times) { | ||
@@ -39,17 +37,22 @@ return new Array(times + 1).join(text); | ||
#wrapInVerticalLines(content, leftWhitespace, rightWhitespace) { | ||
return `${this.getColors().dim(BOX.left)}${leftWhitespace}${content}${rightWhitespace}${this.getColors().dim(BOX.right)}`; | ||
return `${this.#drawBorder(BOX.left, this.getColors())}${leftWhitespace}${content}${rightWhitespace}${this.#drawBorder(BOX.right, this.getColors())}`; | ||
} | ||
#getTopLine() { | ||
const horizontalLength = this.#getHorizontalLength(); | ||
const horizontalLine = this.#repeat(this.getColors().dim(BOX.top), horizontalLength); | ||
return `${this.getColors().dim(BOX.topLeft)}${horizontalLine}${this.getColors().dim(BOX.topRight)}`; | ||
const horizontalLine = this.#repeat(this.#drawBorder(BOX.top, this.getColors()), horizontalLength); | ||
return `${this.#drawBorder(BOX.topLeft, this.getColors())}${horizontalLine}${this.#drawBorder(BOX.topRight, this.getColors())}`; | ||
} | ||
#getBottomLine() { | ||
const horizontalLength = this.#getHorizontalLength(); | ||
const horizontalLine = this.#repeat(this.getColors().dim(BOX.bottom), horizontalLength); | ||
return `${this.getColors().dim(BOX.bottomLeft)}${horizontalLine}${this.getColors().dim(BOX.bottomRight)}`; | ||
const horizontalLine = this.#repeat(this.#drawBorder(BOX.bottom, this.getColors()), horizontalLength); | ||
return `${this.#drawBorder(BOX.bottomLeft, this.getColors())}${horizontalLine}${this.#drawBorder(BOX.bottomRight, this.getColors())}`; | ||
} | ||
#getHeadingBorderBottom() { | ||
const horizontalLength = this.#getHorizontalLength(); | ||
const horizontalLine = this.#repeat(this.#drawBorder(boxes.single.top, this.getColors()), horizontalLength); | ||
return this.#wrapInVerticalLines(horizontalLine, '', ''); | ||
} | ||
#getContentLine(line) { | ||
const leftWhitespace = this.#repeat(' ', this.#leftPadding); | ||
const rightWhitespace = this.#repeat(' ', this.#widestLineLength - line.width + this.#rightPadding); | ||
const leftWhitespace = this.#repeat(' ', this.#leftPadding); | ||
return this.#wrapInVerticalLines(line.text, leftWhitespace, rightWhitespace); | ||
@@ -61,18 +64,19 @@ } | ||
} | ||
const leftWhitespace = this.#repeat(' ', this.#leftPadding); | ||
const rightWhitespace = this.#repeat(' ', this.#widestLineLength - this.#state.heading.width + this.#rightPadding); | ||
const headingContent = this.#wrapInVerticalLines(this.#state.heading.text, leftWhitespace, rightWhitespace); | ||
const horizontalLength = this.#widestLineLength + this.#leftPadding + this.#rightPadding; | ||
const borderLine = this.#repeat(this.getColors().dim(boxes.single.top), horizontalLength); | ||
const border = this.#wrapInVerticalLines(borderLine, '', ''); | ||
return `${headingContent}\n${border}`; | ||
return this.#getContentLine(this.#state.heading); | ||
} | ||
#getBody() { | ||
if (!this.#state.content || !this.#state.content.length) { | ||
return; | ||
} | ||
const top = new Array(this.#paddingTop).fill('').map(this.#getEmptyLineNode); | ||
const bottom = new Array(this.#paddingBottom).fill('').map(this.#getEmptyLineNode); | ||
return top | ||
.concat(this.#state.content) | ||
.concat(bottom) | ||
.map((line) => this.#getContentLine(line)) | ||
.join('\n'); | ||
} | ||
#getEmptyLineNode() { | ||
return { text: '', width: 0 }; | ||
} | ||
#getLinesWithPadding() { | ||
const top = new Array(this.#paddingTop).fill('').map(this.#getEmptyLineNode); | ||
const bottom = new Array(this.#paddingBottom).fill('').map(this.#getEmptyLineNode); | ||
return top.concat(this.#state.content).concat(bottom); | ||
} | ||
getRenderer() { | ||
@@ -98,2 +102,12 @@ if (!this.#renderer) { | ||
} | ||
fullScreen() { | ||
const borderWidth = 2; | ||
this.#widestLineLength = | ||
process.stdout.columns - (this.#leftPadding + this.#rightPadding) - borderWidth; | ||
return this; | ||
} | ||
drawBorder(callback) { | ||
this.#drawBorder = callback; | ||
return this; | ||
} | ||
heading(text) { | ||
@@ -123,17 +137,19 @@ const width = stringWidth(text); | ||
} | ||
if (this.#widestLineLength > process.stdout.columns) { | ||
this.#widestLineLength = process.stdout.columns; | ||
} | ||
const top = this.#getTopLine(); | ||
const heading = this.#getHeading(); | ||
const body = this.#getLinesWithPadding() | ||
.map((line) => this.#getContentLine(line)) | ||
.join('\n'); | ||
const headingBorderBottom = this.#getHeadingBorderBottom(); | ||
const body = this.#getBody(); | ||
const bottom = this.#getBottomLine(); | ||
let output = `${top}\n`; | ||
if (heading) { | ||
output = `${output}${heading}\n`; | ||
output = `${output}${heading}`; | ||
} | ||
renderer.log(`${output}${body}\n${bottom}`); | ||
if (heading && body) { | ||
output = `${output}\n${headingBorderBottom}\n`; | ||
} | ||
if (body) { | ||
output = `${output}${body}`; | ||
} | ||
renderer.log(`${output}\n${bottom}`); | ||
} | ||
} |
{ | ||
"name": "@poppinss/cliui", | ||
"version": "5.0.0-0", | ||
"version": "5.1.0-0", | ||
"description": "Opinionated UI KIT for Command Line apps", | ||
@@ -44,8 +44,8 @@ "main": "build/index.js", | ||
"@japa/spec-reporter": "^1.3.2", | ||
"@swc/core": "^1.3.23", | ||
"@types/node": "^18.11.15", | ||
"@swc/core": "^1.3.24", | ||
"@types/node": "^18.11.18", | ||
"@types/pretty-hrtime": "^1.0.1", | ||
"del-cli": "^5.0.0", | ||
"doctoc": "^2.2.1", | ||
"eslint": "^8.29.0", | ||
"eslint": "^8.30.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
@@ -68,3 +68,3 @@ "eslint-plugin-adonis": "^3.0.3", | ||
"string-width": "^5.1.2", | ||
"supports-color": "^9.3.0" | ||
"supports-color": "^9.3.1" | ||
}, | ||
@@ -71,0 +71,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
64367
1512
Updatedsupports-color@^9.3.1