diff --git a/frontend/cli/cmd_call.go b/frontend/cli/cmd_call.go index 20bdd165bd..54c755f3b1 100644 --- a/frontend/cli/cmd_call.go +++ b/frontend/cli/cmd_call.go @@ -19,6 +19,7 @@ import ( "github.com/TBD54566975/ftl/go-runtime/ftl/reflection" "github.com/TBD54566975/ftl/internal/log" "github.com/TBD54566975/ftl/internal/rpc" + "github.com/TBD54566975/ftl/internal/status" ) type callCmd struct { @@ -77,7 +78,7 @@ func callVerb(ctx context.Context, client ftlv1connect.VerbServiceClient, ctlCli return fmt.Errorf("verb error: %s", resp.Error.Message) case *ftlv1.CallResponse_Body: - fmt.Println(string(resp.Body)) + status.PrintJSON(ctx, resp.Body) } return nil } diff --git a/frontend/cli/cmd_replay.go b/frontend/cli/cmd_replay.go index 8fdcfe942c..cc7930cf5c 100644 --- a/frontend/cli/cmd_replay.go +++ b/frontend/cli/cmd_replay.go @@ -17,6 +17,7 @@ import ( "github.com/TBD54566975/ftl/go-runtime/ftl/reflection" "github.com/TBD54566975/ftl/internal/log" "github.com/TBD54566975/ftl/internal/rpc" + "github.com/TBD54566975/ftl/internal/status" ) type replayCmd struct { @@ -97,6 +98,8 @@ func (c *replayCmd) Run(ctx context.Context, client ftlv1connect.VerbServiceClie } requestJSON := events.Msg.GetEvents()[0].GetCall().Request - logger.Infof("Calling %s with body:\n%s", c.Verb, requestJSON) + logger.Infof("Calling %s with body:", c.Verb) + status.PrintJSON(ctx, []byte(requestJSON)) + logger.Infof("Response:") return callVerb(ctx, client, ctlCli, c.Verb, []byte(requestJSON)) } diff --git a/frontend/cli/cmd_status.go b/frontend/cli/cmd_status.go index 0eb8beb6c1..0fc802af9a 100644 --- a/frontend/cli/cmd_status.go +++ b/frontend/cli/cmd_status.go @@ -9,6 +9,7 @@ import ( ftlv1 "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1" "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/ftlv1connect" + console "github.com/TBD54566975/ftl/internal/status" ) type statusCmd struct { @@ -35,6 +36,6 @@ func (s *statusCmd) Run(ctx context.Context, client ftlv1connect.ControllerServi if err != nil { return fmt.Errorf("failed to marshal status: %w", err) } - fmt.Printf("%s\n", data) + console.PrintJSON(ctx, data) return nil } diff --git a/go.mod b/go.mod index 57baf76b3c..063bc6e30d 100644 --- a/go.mod +++ b/go.mod @@ -49,6 +49,7 @@ require ( github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 github.com/sqlc-dev/pqtype v0.3.0 github.com/swaggest/jsonschema-go v0.3.72 + github.com/tidwall/pretty v1.2.1 github.com/tink-crypto/tink-go-awskms v0.0.0-20230616072154-ba4f9f22c3e9 github.com/tink-crypto/tink-go/v2 v2.2.0 github.com/titanous/json5 v1.0.0 diff --git a/go.sum b/go.sum index 6f13421ca4..f57345e066 100644 --- a/go.sum +++ b/go.sum @@ -338,6 +338,8 @@ github.com/swaggest/jsonschema-go v0.3.72 h1:IHaGlR1bdBUBPfhe4tfacN2TGAPKENEGiNy github.com/swaggest/jsonschema-go v0.3.72/go.mod h1:OrGyEoVqpfSFJ4Am4V/FQcQ3mlEC1vVeleA+5ggbVW4= github.com/swaggest/refl v1.3.0 h1:PEUWIku+ZznYfsoyheF97ypSduvMApYyGkYF3nabS0I= github.com/swaggest/refl v1.3.0/go.mod h1:3Ujvbmh1pfSbDYjC6JGG7nMgPvpG0ehQL4iNonnLNbg= +github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4= +github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/tink-crypto/tink-go-awskms v0.0.0-20230616072154-ba4f9f22c3e9 h1:MoIsYvBNJd8vkKZjLYloE3OK8bfcO10cMPw/EtydMBs= github.com/tink-crypto/tink-go-awskms v0.0.0-20230616072154-ba4f9f22c3e9/go.mod h1:TTE4PoQLsYB5jQ1kK2g7WU4wzHg0Arn1CEozIUXiGSY= github.com/tink-crypto/tink-go/v2 v2.2.0 h1:L2Da0F2Udh2agtKztdr69mV/KpnY3/lGTkMgLTVIXlA= diff --git a/internal/status/status.go b/internal/status/status.go index 2130fcb710..f68bf47195 100644 --- a/internal/status/status.go +++ b/internal/status/status.go @@ -13,6 +13,7 @@ import ( "unicode/utf8" "github.com/alecthomas/atomic" + "github.com/tidwall/pretty" "golang.org/x/term" ) @@ -165,6 +166,18 @@ func UpdateModuleState(ctx context.Context, module string, state BuildState) { sm.SetModuleState(module, state) } +// PrintJSON prints a json string to the terminal +// It probably doesn't belong here, but it will be moved later with the interactive terminal work +func PrintJSON(ctx context.Context, json []byte) { + sm := FromContext(ctx) + if _, ok := sm.(*terminalStatusManager); ok { + // ANSI enabled + fmt.Printf("%s\n", pretty.Color(pretty.Pretty(json), nil)) + } else { + fmt.Printf("%s\n", json) + } +} + func (r *terminalStatusManager) gotoCoords(line int, col int) { r.underlyingWrite(fmt.Sprintf("\033[%d;%dH", line, col)) }