MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / renderSessionToGif

Function renderSessionToGif

scripts/tmux/tmux-viewer/gif-exporter.ts:195–259  ·  view source on GitHub ↗
(
  sessionData: SessionData,
  options: GifExportOptions
)

Source from the content-addressed store, hash-verified

193 * @returns Promise that resolves to the output path when complete
194 */
195export async function renderSessionToGif(
196 sessionData: SessionData,
197 options: GifExportOptions
198): Promise<string> {
199 const captures = sessionData.captures
200
201 if (captures.length === 0) {
202 throw new Error('No captures to export - session has no captured frames')
203 }
204
205 // Apply defaults
206 const frameDelay = options.frameDelay ?? 1500
207 const fontSize = options.fontSize ?? 14
208 const bgColor = options.bgColor ?? '#1e1e1e'
209 const fgColor = options.fgColor ?? '#d4d4d4'
210 const loop = options.loop ?? 0
211 const quality = options.quality ?? 10
212 const showLabel = options.showLabel !== false
213
214 // Calculate dimensions
215 const { width, height, charWidth, lineHeight } = calculateDimensions(sessionData, {
216 ...options,
217 fontSize,
218 showLabel,
219 })
220
221 // Create canvas
222 const canvas = createCanvas(width, height)
223 const ctx = canvas.getContext('2d')
224
225 // Create GIF encoder
226 const encoder = new GIFEncoder(width, height)
227
228 encoder.start()
229 encoder.setDelay(frameDelay)
230 encoder.setRepeat(loop)
231 encoder.setQuality(quality)
232
233 // Render context for frames
234 const renderCtx: RenderContext = {
235 fontSize,
236 lineHeight,
237 charWidth,
238 bgColor,
239 fgColor,
240 labelColor: '#888888',
241 showLabel,
242 }
243
244 // Render each capture as a frame
245 for (const capture of captures) {
246 renderFrame(ctx, capture, width, height, renderCtx)
247 encoder.addFrame(ctx)
248 }
249
250 encoder.finish()
251
252 // Write to file

Callers 1

runViewerFunction · 0.90

Calls 4

calculateDimensionsFunction · 0.85
renderFrameFunction · 0.85
startMethod · 0.45
finishMethod · 0.45

Tested by

no test coverage detected