MCPcopy Index your code
hub / github.com/codeaashu/claude-code / embedTextInBorder

Function embedTextInBorder

src/ink/render-border.ts:35–68  ·  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

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

Callers 1

renderBorderFunction · 0.85

Calls 1

maxMethod · 0.80

Tested by

no test coverage detected