MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / embedTextInBorder

Function embedTextInBorder

source code/ink/render-border.ts:37–70  ·  view source on GitHub ↗
(
  borderLine: string,
  text: string,
  align: 'start' | 'end' | 'center',
  offset: number = 0,
  borderChar: string,
)

Source from the content-addressed store, hash-verified

35 | BoxStyle
36
37function embedTextInBorder(
38 borderLine: string,
39 text: string,
40 align: 'start' | 'end' | 'center',
41 offset: number = 0,
42 borderChar: string,
43): [before: string, text: string, after: string] {
44 const textLength = stringWidth(text)
45 const borderLength = borderLine.length
46
47 if (textLength >= borderLength - 2) {
48 return ['', text.substring(0, borderLength), '']
49 }
50
51 let position: number
52 if (align === 'center') {
53 position = Math.floor((borderLength - textLength) / 2)
54 } else if (align === 'start') {
55 position = offset + 1 // +1 to account for corner character
56 } else {
57 // align === 'end'
58 position = borderLength - textLength - offset - 1 // -1 for corner character
59 }
60
61 // Ensure position is valid
62 position = Math.max(1, Math.min(position, borderLength - textLength - 1))
63
64 const before = borderLine.substring(0, 1) + borderChar.repeat(position - 1)
65 const after =
66 borderChar.repeat(borderLength - position - textLength - 1) +
67 borderLine.substring(borderLength - 1)
68
69 return [before, text, after]
70}
71
72function styleBorderLine(
73 line: string,

Callers 1

renderBorderFunction · 0.85

Calls 1

maxMethod · 0.80

Tested by

no test coverage detected