MCPcopy Create free account
hub / github.com/ShipSecAI/studio / getDisplayWidth

Function getDisplayWidth

backend/scripts/version-check-summary.ts:21–30  ·  view source on GitHub ↗
(str: string)

Source from the content-addressed store, hash-verified

19const emojiRegex = /\p{Emoji_Presentation}|\p{Extended_Pictographic}/gu;
20
21function getDisplayWidth(str: string): number {
22 // Remove ANSI codes first
23 // eslint-disable-next-line no-control-regex
24 const plain = str.replace(/\x1b\[[0-9;]*m/g, '');
25 // Count emojis (each takes 2 columns but counts as 1-2 chars)
26 const emojis = plain.match(emojiRegex) || [];
27 // Base length minus emoji chars, plus 2 per emoji for display width
28 const baseLen = [...plain].length;
29 return baseLen + emojis.length; // Add 1 extra column per emoji
30}
31
32function printBox(lines: string[], borderColor: string) {
33 const maxLen = Math.max(...lines.map((l) => getDisplayWidth(l)));

Callers 1

printBoxFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected