MCPcopy
hub / github.com/prisma/prisma / drawBox

Function drawBox

packages/internals/src/utils/drawBox.ts:27–65  ·  view source on GitHub ↗
({ title, width, height, str, horizontalPadding }: BoxOptions)

Source from the content-addressed store, hash-verified

25}
26
27export function drawBox({ title, width, height, str, horizontalPadding }: BoxOptions): string {
28 // This avoids having NaN later
29 // if these required param were not passed (in JS, for example)
30 horizontalPadding = horizontalPadding || 0
31 width = width || 0
32 height = height || 0
33 // Make sure the width is at least as long as the string
34 width = Math.max(width, maxLineLength(str) + horizontalPadding * 2)
35
36 const topLine = title
37 ? grey(chars.topLeft + chars.horizontal) +
38 ' ' +
39 reset(bold(title)) +
40 ' ' +
41 grey(chars.horizontal.repeat(width - title.length - 2 - 3) + chars.topRight) +
42 reset()
43 : grey(chars.topLeft + chars.horizontal) + grey(chars.horizontal.repeat(width - 3) + chars.topRight)
44
45 const bottomLine = chars.bottomLeft + chars.horizontal.repeat(width - 2) + chars.bottomRight
46
47 const lines = str.split('\n')
48
49 if (lines.length < height) {
50 lines.push(...new Array(height - lines.length).fill(''))
51 }
52
53 const mappedLines = lines
54 .slice(-height)
55 .map((l) => {
56 const lineWidth = Math.min(stringWidth(l), width)
57 const paddingRight = Math.max(width - lineWidth - 2, 0)
58 return `${grey(chars.vertical)}${' '.repeat(horizontalPadding!)}${reset(cliTruncate(l, width - 2))}${' '.repeat(
59 paddingRight - horizontalPadding!,
60 )}${grey(chars.vertical)}`
61 })
62 .join('\n')
63
64 return grey(topLine + '\n' + mappedLines + '\n' + bottomLine)
65}

Callers 3

CLIClass · 0.90
printUpdateMessageFunction · 0.90

Calls 4

maxLineLengthFunction · 0.85
fillMethod · 0.80
pushMethod · 0.45
sliceMethod · 0.45

Tested by

no test coverage detected