Real-image posters: blocks while the window is being resized; ARR_TUI_DEBUG_GFX log
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"image"
|
||||
"image/png"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
@@ -39,8 +40,24 @@ type kittyGraphics struct {
|
||||
nextID uint32
|
||||
ids map[footprint]uint32
|
||||
latest map[*image.RGBA]footprint // the footprint of each poster that is currently uploaded
|
||||
|
||||
holdUntil time.Time // no real images until then (the window is being resized)
|
||||
debug func(string) // reports what is uploaded, if set
|
||||
}
|
||||
|
||||
// settleDelay is how long the window size must stay the same before real
|
||||
// images are shown again. While a window is dragged to another size, tens of
|
||||
// sizes go by; uploading and placing images for each of them races with the
|
||||
// terminal's own resizing, and the result can be a placement that does not
|
||||
// match the cells (a small poster in a big area, or a corner of a big one).
|
||||
const settleDelay = 300 * time.Millisecond
|
||||
|
||||
// hold stops real images being drawn until the window has been left alone for settleDelay.
|
||||
func (k *kittyGraphics) hold() { k.holdUntil = time.Now().Add(settleDelay) }
|
||||
|
||||
// settling reports whether the window size changed so recently that blocks are drawn instead.
|
||||
func (k *kittyGraphics) settling() bool { return time.Now().Before(k.holdUntil) }
|
||||
|
||||
// footprint identifies an uploaded image: a poster, the part of it that was
|
||||
// sent, and the cells it covers.
|
||||
type footprint struct {
|
||||
@@ -112,6 +129,9 @@ func (k *kittyGraphics) show(img *image.RGBA, rect image.Rectangle, cols, rows i
|
||||
}
|
||||
k.ids[key] = id
|
||||
k.latest[img] = key
|
||||
if k.debug != nil {
|
||||
k.debug(fmt.Sprintf("graphics: id %d, poster %dx%d px cropped to %v, placed over %dx%d cells", id, img.Bounds().Dx(), img.Bounds().Dy(), rect, cols, rows))
|
||||
}
|
||||
return id, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user