* Generate iTerm2 inline image escape sequence * @param base64Data - Base64 encoded image data * @param options - Display options
(
base64Data: string,
options: {
width?: number | string // cells or 'auto'
height?: number | string // cells or 'auto'
preserveAspectRatio?: boolean
inline?: boolean
name?: string
} = {},
)
| 62 | * @param options - Display options |
| 63 | */ |
| 64 | function generateITerm2ImageSequence( |
| 65 | base64Data: string, |
| 66 | options: { |
| 67 | width?: number | string // cells or 'auto' |
| 68 | height?: number | string // cells or 'auto' |
| 69 | preserveAspectRatio?: boolean |
| 70 | inline?: boolean |
| 71 | name?: string |
| 72 | } = {}, |
| 73 | ): string { |
| 74 | const { |
| 75 | width = 'auto', |
| 76 | height = 'auto', |
| 77 | preserveAspectRatio = true, |
| 78 | inline = true, |
| 79 | name, |
| 80 | } = options |
| 81 | |
| 82 | // Build the parameter string |
| 83 | const params: string[] = [] |
| 84 | |
| 85 | if (inline) { |
| 86 | params.push('inline=1') |
| 87 | } |
| 88 | |
| 89 | if (width !== 'auto') { |
| 90 | params.push(`width=${width}`) |
| 91 | } |
| 92 | |
| 93 | if (height !== 'auto') { |
| 94 | params.push(`height=${height}`) |
| 95 | } |
| 96 | |
| 97 | if (!preserveAspectRatio) { |
| 98 | params.push('preserveAspectRatio=0') |
| 99 | } |
| 100 | |
| 101 | if (name) { |
| 102 | params.push(`name=${Buffer.from(name).toString('base64')}`) |
| 103 | } |
| 104 | |
| 105 | // Add size parameter (required) |
| 106 | params.push(`size=${base64Data.length}`) |
| 107 | |
| 108 | const paramString = params.join(';') |
| 109 | |
| 110 | // Format: ESC ] 1337 ; File = [params] : base64data BEL |
| 111 | // Using \x1b for ESC and \x07 for BEL |
| 112 | return `\x1b]1337;File=${paramString}:${base64Data}\x07` |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Generate Kitty graphics protocol escape sequence |
no test coverage detected