From c86e075f0df33cc01ac99f167a09f981997727d0 Mon Sep 17 00:00:00 2001 From: Chris Waldon Date: Tue, 14 Sep 2021 11:41:31 -0400 Subject: [PATCH] debug: add function to easily log structures Signed-off-by: Chris Waldon --- debug/debug.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/debug/debug.go b/debug/debug.go index 2bb51e3..045ead1 100644 --- a/debug/debug.go +++ b/debug/debug.go @@ -4,7 +4,11 @@ Package debug provides tools for debugging Gio layout code. package debug import ( + "bytes" + "encoding/json" "image/color" + "io" + "os" "gioui.org/layout" "gioui.org/unit" @@ -23,3 +27,10 @@ func Outline(gtx C, w func(gtx C) D) D { Width: unit.Dp(1), }.Layout(gtx, w) } + +// Dump logs the input as formatting JSON on stderr. +func Dump(v interface{}) { + b, _ := json.MarshalIndent(v, "", " ") + b = append(b, []byte("\n")...) + io.Copy(os.Stderr, bytes.NewBuffer(b)) +} -- 2.34.2