Skip to content

Commit d3882f5

Browse files
committed
feat: enhance background rendering by using WindowBackground color for terminal areas and adding cursor rendering option
1 parent 60f374b commit d3882f5

File tree

4 files changed

+38
-24
lines changed

4 files changed

+38
-24
lines changed

pkg/raster/draw.go

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,14 @@ func (r *Rasterizer) drawTextRunWithFace(
9292

9393
colors := r.computeTextRunColors(run, rowY, catalog)
9494

95-
// Draw background rectangle for the run
96-
draw.Draw(img,
97-
image.Rect(colors.x, colors.y, colors.x+colors.textWidth, colors.y+r.config.RowHeight),
98-
&image.Uniform{colors.bg},
99-
image.Point{},
100-
draw.Src)
95+
// Draw background rectangle only if it's not the default color
96+
if !catalog.IsDefault(run.Attrs.BG) {
97+
draw.Draw(img,
98+
image.Rect(colors.x, colors.y, colors.x+colors.textWidth, colors.y+r.config.RowHeight),
99+
&image.Uniform{colors.bg},
100+
image.Point{},
101+
draw.Src)
102+
}
101103

102104
// Draw text
103105
drawer := &font.Drawer{
@@ -160,12 +162,13 @@ func (r *Rasterizer) drawBackground(img *image.RGBA) {
160162
}
161163

162164
// drawTerminalBackground draws the terminal content area background.
163-
// Uses the theme's Background color for the terminal content.
165+
// Uses the theme's WindowBackground color to match the window chrome,
166+
// creating a seamless appearance while maintaining full opacity for GIF performance.
164167
func (r *Rasterizer) drawTerminalBackground(img *image.RGBA, width, height int) {
165168
contentX := r.config.Padding
166169
contentY := r.contentOffsetY()
167-
// Use theme Background for terminal content area
168-
termBg := r.config.Theme.Background
170+
// Use WindowBackground to match the window chrome color
171+
termBg := r.config.Theme.WindowBackground
169172

170173
draw.Draw(img,
171174
image.Rect(contentX, contentY, contentX+width, contentY+height),
@@ -251,12 +254,14 @@ func (r *Rasterizer) drawTextRunToPaletted(
251254

252255
colors := r.computeTextRunColors(run, rowY, catalog)
253256

254-
// Draw background rectangle for the run
255-
draw.Draw(img,
256-
image.Rect(colors.x, colors.y, colors.x+colors.textWidth, colors.y+r.config.RowHeight),
257-
&image.Uniform{colors.bg},
258-
image.Point{},
259-
draw.Src)
257+
// Draw background rectangle only if it's not the default color
258+
if !catalog.IsDefault(run.Attrs.BG) {
259+
draw.Draw(img,
260+
image.Rect(colors.x, colors.y, colors.x+colors.textWidth, colors.y+r.config.RowHeight),
261+
&image.Uniform{colors.bg},
262+
image.Point{},
263+
draw.Src)
264+
}
260265

261266
// Draw text directly to paletted image
262267
drawer := &font.Drawer{

pkg/raster/paletted.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,10 @@ func (fr *palettedFrameRenderer) renderSingleFrame(
6464
}
6565
}
6666

67-
// createPalettedBaseImage creates the static base image with window chrome
68-
// and terminal background.
69-
func (fr *palettedFrameRenderer) createPalettedBaseImage(
70-
width, height, contentWidth, contentHeight int,
71-
) *image.Paletted {
67+
// createPalettedBaseImage creates the static base image with window chrome and terminal background.
68+
// Uses WindowBackground color for the terminal area to match window chrome,
69+
// ensuring full opacity for optimal GIF delta encoding performance.
70+
func (fr *palettedFrameRenderer) createPalettedBaseImage(width, height, contentWidth, contentHeight int) *image.Paletted {
7271
// First create RGBA base image
7372
rgbaImg := image.NewRGBA(image.Rect(0, 0, width, height))
7473

@@ -79,7 +78,9 @@ func (fr *palettedFrameRenderer) createPalettedBaseImage(
7978
fr.rasterizer.drawBackground(rgbaImg)
8079
}
8180

82-
// Draw terminal content background
81+
// Draw terminal content background using WindowBackground color
82+
// This ensures full opacity for GIF delta encoding while maintaining
83+
// visual consistency with the window chrome
8384
fr.rasterizer.drawTerminalBackground(rgbaImg, contentWidth, contentHeight)
8485

8586
// Convert to paletted once (this is done only once per recording, not per frame)
@@ -106,8 +107,8 @@ func (fr *palettedFrameRenderer) drawFrameContentToPaletted(img *image.Paletted,
106107
}
107108
}
108109

109-
// Draw cursor if visible
110-
if frame.Cursor.Visible {
110+
// Draw cursor if visible and cursor rendering is enabled
111+
if fr.rasterizer.config.ShowCursor && frame.Cursor.Visible {
111112
fr.rasterizer.drawCursorToPaletted(img, frame.Cursor, fr.rec.Colors)
112113
}
113114
}

pkg/raster/raster.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ type Config struct {
3838
// ShowWindow enables window chrome rendering (macOS-style buttons)
3939
ShowWindow bool
4040

41+
// ShowCursor enables cursor rendering
42+
ShowCursor bool
43+
4144
// FontSize is the font size in points
4245
FontSize int
4346

@@ -79,6 +82,7 @@ func DefaultConfig() Config {
7982
return Config{
8083
Theme: theme.Default(),
8184
ShowWindow: true,
85+
ShowCursor: true,
8286
FontSize: 20,
8387
RowHeight: RowHeight,
8488
ColWidth: ColWidth,

pkg/raster/renderer.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ func (fr *frameRenderer) renderSingleFrame(
6060
}
6161

6262
// createBaseImage creates the static base image with window chrome and terminal background.
63+
// Uses WindowBackground color for the terminal area to match window chrome,
64+
// ensuring full opacity for optimal GIF delta encoding performance.
6365
func (fr *frameRenderer) createBaseImage(width, height, contentWidth, contentHeight int) *image.RGBA {
6466
img := image.NewRGBA(image.Rect(0, 0, width, height))
6567

@@ -70,7 +72,9 @@ func (fr *frameRenderer) createBaseImage(width, height, contentWidth, contentHei
7072
fr.rasterizer.drawBackground(img)
7173
}
7274

73-
// Draw terminal content background
75+
// Draw terminal content background using WindowBackground color
76+
// This ensures full opacity for GIF delta encoding while maintaining
77+
// visual consistency with the window chrome
7478
fr.rasterizer.drawTerminalBackground(img, contentWidth, contentHeight)
7579

7680
return img

0 commit comments

Comments
 (0)