({
availableWidth,
applySheenToChar,
textColor,
accentColor = '#9EFC62',
blockColor = '#ffffff',
maxHeight,
}: UseLogoOptions)
| 62 | * - No consumer needs to know about parseLogoLines, split, join, etc. |
| 63 | */ |
| 64 | export const useLogo = ({ |
| 65 | availableWidth, |
| 66 | applySheenToChar, |
| 67 | textColor, |
| 68 | accentColor = '#9EFC62', |
| 69 | blockColor = '#ffffff', |
| 70 | maxHeight, |
| 71 | }: UseLogoOptions): LogoResult => { |
| 72 | // The ASCII art (full and small) is 6 lines tall. If the caller can't spare |
| 73 | // that many rows, collapse straight to the single-line text variant. |
| 74 | const ASCII_LOGO_LINES = 6 |
| 75 | const rawLogoString = useMemo(() => { |
| 76 | if (maxHeight != null && maxHeight < ASCII_LOGO_LINES) { |
| 77 | return IS_FREEBUFF ? 'FREEBUFF' : 'CODEBUFF' |
| 78 | } |
| 79 | if (availableWidth >= 70) return LOGO |
| 80 | if (availableWidth >= 20) return LOGO_SMALL |
| 81 | return IS_FREEBUFF ? 'FREEBUFF' : 'CODEBUFF' |
| 82 | }, [availableWidth, maxHeight]) |
| 83 | |
| 84 | // Format text block for plain text contexts (chat messages, etc.) |
| 85 | const textBlock = useMemo(() => { |
| 86 | if (rawLogoString === 'CODEBUFF' || rawLogoString === 'FREEBUFF') { |
| 87 | return '' // Don't show ASCII art for text-only variant in plain text contexts |
| 88 | } |
| 89 | // Parse and format for plain text display |
| 90 | return parseLogoLines(rawLogoString) |
| 91 | .map((line) => line.slice(0, availableWidth)) |
| 92 | .join('\n') |
| 93 | }, [rawLogoString, availableWidth]) |
| 94 | |
| 95 | // Format component for React contexts (login modal, etc.) |
| 96 | const component = useMemo(() => { |
| 97 | // Text-only variant for very narrow widths |
| 98 | if (rawLogoString === 'CODEBUFF' || rawLogoString === 'FREEBUFF') { |
| 99 | const brandName = IS_FREEBUFF ? 'Freebuff' : 'Codebuff' |
| 100 | // When we collapsed to text purely to fit a short terminal (not because |
| 101 | // the terminal is narrow), keep it to the bare brand name — "Freebuff |
| 102 | // CLI" reads as filler in that already-cramped space. |
| 103 | const forcedByHeight = maxHeight != null && maxHeight < ASCII_LOGO_LINES |
| 104 | const displayText = |
| 105 | availableWidth < 30 || forcedByHeight |
| 106 | ? brandName |
| 107 | : `${brandName} CLI` |
| 108 | |
| 109 | return ( |
| 110 | <text style={{ wrapMode: 'none' }}> |
| 111 | <b> |
| 112 | {textColor ? ( |
| 113 | <span fg={textColor}>{displayText}</span> |
| 114 | ) : ( |
| 115 | <>{displayText}</> |
| 116 | )} |
| 117 | </b> |
| 118 | </text> |
| 119 | ) |
| 120 | } |
| 121 |
no test coverage detected