diff --git a/d2cli/main.go b/d2cli/main.go index b252815a5..f80aa4a2b 100644 --- a/d2cli/main.go +++ b/d2cli/main.go @@ -363,7 +363,7 @@ func compile(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, rende if err != nil { return nil, false, err } - out, err := xgif.AnimatePNGs(pngs, int(animateInterval)) + out, err := xgif.AnimatePNGs(ms, pngs, int(animateInterval)) if err != nil { return nil, false, err } diff --git a/lib/xgif/xgif.go b/lib/xgif/xgif.go index f6d1389ea..967b446fc 100644 --- a/lib/xgif/xgif.go +++ b/lib/xgif/xgif.go @@ -15,10 +15,13 @@ import ( "image/color" "image/gif" "image/png" + "time" "github.com/ericpauley/go-quantize/quantize" + "oss.terrastruct.com/d2/lib/background" "oss.terrastruct.com/util-go/go2" + "oss.terrastruct.com/util-go/xmain" ) const INFINITE_LOOP = 0 @@ -26,7 +29,14 @@ const BG_INDEX uint8 = 255 var BG_COLOR = color.White -func AnimatePNGs(pngs [][]byte, animIntervalMs int) ([]byte, error) { +func AnimatePNGs(ms *xmain.State, pngs [][]byte, animIntervalMs int) ([]byte, error) { + if ms != nil { + cancel := background.Repeat(func() { + ms.Log.Info.Printf("generating GIF...") + }, time.Second*5) + defer cancel() + } + var width, height int pngImgs := make([]image.Image, len(pngs)) for i, pngBytes := range pngs { diff --git a/lib/xgif/xgif_test.go b/lib/xgif/xgif_test.go index fcdc370e7..bc3cc1061 100644 --- a/lib/xgif/xgif_test.go +++ b/lib/xgif/xgif_test.go @@ -20,7 +20,7 @@ var test_output []byte func TestPngToGif(t *testing.T) { boards := [][]byte{test_input1, test_input2} interval := 1_000 - gifBytes, err := AnimatePNGs(boards, interval) + gifBytes, err := AnimatePNGs(nil, boards, interval) assert.NoError(t, err) // use this to update the test output