Allow changing the default background color in PixelImage #33

Closed
opened 2026-04-07 11:22:34 -07:00 by ronisbr · 3 comments
ronisbr commented 2026-04-07 11:22:34 -07:00 (Migrated from github.com)

Hi @kahliburke !

I saw that PixelImage has a field bg that is supposed to contain the background color. However, I cannot use it to store a default background color because it is overwritten here github.com/kahliburke/Tachikoma.jl@c2ab53de99/src/sixel_image.jl (L79), which calls canvas_bg and replace the color I selected. Am I understanding it right? If so, can we add a function inside PixelImage so that we have more control?

Hi @kahliburke ! I saw that `PixelImage` has a field `bg` that is supposed to contain the background color. However, I cannot use it to store a default background color because it is overwritten here https://github.com/kahliburke/Tachikoma.jl/blob/c2ab53de99b158cedd14ad6a91dfe189cb2e4969/src/sixel_image.jl#L79, which calls `canvas_bg` and replace the color I selected. Am I understanding it right? If so, can we add a function inside `PixelImage` so that we have more control?
kahliburke commented 2026-04-08 07:20:56 -07:00 (Migrated from github.com)

@ronisbr Looking into this.

@ronisbr Looking into this.
kahliburke commented 2026-04-12 08:39:45 -07:00 (Migrated from github.com)

Hi @ronisbr! You're right — _sync_pixelimage_bg! was unconditionally overwriting the user-set bg with canvas_bg(). This is fixed on main now.

What changed

  • PixelImage has a new bg_tracks_canvas::Bool field. When true (the default if you don't pass bg), the background tracks canvas_bg() across theme changes — same as before. When false, your chosen color is preserved.

  • Constructor: passing bg=my_color now disables canvas tracking automatically:

    img = PixelImage(w, h; bg=ColorRGBA(0x20, 0x40, 0x60))
    # img.bg_tracks_canvas == false → clear! and resize won't clobber it
    
  • set_background!(img, color): changes the bg at runtime — rewrites any pixels currently holding the old bg to the new color and disables tracking.

  • reset_background!(img): re-enables canvas tracking and immediately syncs to the current canvas_bg().

Both are exported.

The sixel_gallery demo's Flame Graph pane now uses a custom bg with a [b] keybind to cycle through indigo → crimson → forest → tracked to demonstrate the feature end-to-end.

Hi @ronisbr! You're right — `_sync_pixelimage_bg!` was unconditionally overwriting the user-set `bg` with `canvas_bg()`. This is fixed on `main` now. ### What changed - `PixelImage` has a new `bg_tracks_canvas::Bool` field. When `true` (the default if you don't pass `bg`), the background tracks `canvas_bg()` across theme changes — same as before. When `false`, your chosen color is preserved. - **Constructor**: passing `bg=my_color` now disables canvas tracking automatically: ```julia img = PixelImage(w, h; bg=ColorRGBA(0x20, 0x40, 0x60)) # img.bg_tracks_canvas == false → clear! and resize won't clobber it ``` - **`set_background!(img, color)`**: changes the bg at runtime — rewrites any pixels currently holding the old bg to the new color and disables tracking. - **`reset_background!(img)`**: re-enables canvas tracking and immediately syncs to the current `canvas_bg()`. Both are exported. The `sixel_gallery` demo's Flame Graph pane now uses a custom bg with a `[b]` keybind to cycle through `indigo → crimson → forest → tracked` to demonstrate the feature end-to-end.
ronisbr commented 2026-04-12 12:30:17 -07:00 (Migrated from github.com)

Awesome! Thanks!

Awesome! Thanks!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kahliburke/Tachikoma.jl#33
No description provided.