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

Function calculateDimensions

scripts/tmux/tmux-viewer/gif-exporter.ts:53–86  ·  view source on GitHub ↗

* Calculate canvas dimensions based on terminal size and font metrics

(
  sessionData: SessionData,
  options: GifExportOptions
)

Source from the content-addressed store, hash-verified

51 * Calculate canvas dimensions based on terminal size and font metrics
52 */
53function calculateDimensions(
54 sessionData: SessionData,
55 options: GifExportOptions
56): { width: number; height: number; charWidth: number; lineHeight: number } {
57 const fontSize = options.fontSize ?? 14
58 // Approximate character dimensions for monospace font
59 const charWidth = fontSize * 0.6
60 const lineHeight = fontSize * 1.2
61
62 // Get terminal dimensions from session info or first capture
63 let termWidth = 80
64 let termHeight = 24
65
66 if (sessionData.sessionInfo.dimensions) {
67 termWidth =
68 typeof sessionData.sessionInfo.dimensions.width === 'number'
69 ? sessionData.sessionInfo.dimensions.width
70 : 80
71 termHeight =
72 typeof sessionData.sessionInfo.dimensions.height === 'number'
73 ? sessionData.sessionInfo.dimensions.height
74 : 24
75 }
76
77 // Calculate canvas size with padding
78 const padding = 20
79 const labelHeight = options.showLabel !== false ? 30 : 0
80
81 const width = options.width ?? Math.ceil(termWidth * charWidth + padding * 2)
82 const height =
83 options.height ?? Math.ceil(termHeight * lineHeight + padding * 2 + labelHeight)
84
85 return { width, height, charWidth, lineHeight }
86}
87
88/**
89 * Render a single capture frame to the canvas

Callers 1

renderSessionToGifFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected