Real-image posters: draw placeholder cells on the panes' background color

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-20 23:17:40 +02:00
co-authored by Claude Sonnet 5.5
parent dd6f862d61
commit 0ccd02b3c5
3 changed files with 10 additions and 3 deletions
+4 -1
View File
@@ -9,6 +9,7 @@ import (
"strings"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
// The Kitty graphics protocol with Unicode placeholders, as supported by
@@ -139,7 +140,9 @@ func (k *kittyGraphics) deleteAll() {
func placeholderCell(id uint32, row, col int) (main rune, comb []rune, style tcell.Style) {
comb = []rune{kittyDiacritics[row], kittyDiacritics[col]}
fg := tcell.NewRGBColor(int32(id>>16&0xFF), int32(id>>8&0xFF), int32(id&0xFF))
return placeholderRune, comb, tcell.StyleDefault.Foreground(fg)
// The background shows wherever the picture does not cover the cell (a
// sliver at the edge): use the panes' own color so it is not visible.
return placeholderRune, comb, tcell.StyleDefault.Foreground(fg).Background(tview.Styles.PrimitiveBackgroundColor)
}
// maxPlaceholders is how many rows and columns can be numbered.
+5 -1
View File
@@ -12,6 +12,7 @@ import (
"testing"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
// recorder collects what is written to the terminal.
@@ -138,10 +139,13 @@ func TestPlaceholderCell(t *testing.T) {
if ch != '\U0010EEEE' || len(comb) != 2 || comb[0] != kittyDiacritics[2] || comb[1] != kittyDiacritics[5] {
t.Errorf("cell = %U %U", ch, comb)
}
fg, _, _ := style.Decompose()
fg, bg, _ := style.Decompose()
if r, g, b := fg.RGB(); r != 1 || g != 2 || b != 3 {
t.Errorf("the id must be in the foreground color, got %d,%d,%d", r, g, b)
}
if bg != tview.Styles.PrimitiveBackgroundColor {
t.Errorf("background %v must match the panes (%v), or uncovered slivers show", bg, tview.Styles.PrimitiveBackgroundColor)
}
}
func TestKittyTerminalDetection(t *testing.T) {