render

package
v0.9.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package render formats melange.Trace values for terminal display.

The renderer is the shared presentation layer for both `melange explain` and `melange expand`. It walks a *melange.Trace and emits a unicode-tree- style summary suitable for human reading. JSON output is left to callers (encoding/json on the Trace value is sufficient — keys are already snake_case to match the SQL convention).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Expand

func Expand(w io.Writer, t *melange.UsersetTree, options ...Option)

Expand writes a human-readable rendering of an OpenFGA-shaped UsersetTree to w. A nil tree prints nothing; an empty Root prints just a "(no nodes)" placeholder so the output is never silent on a successfully-deserialised but degenerate response.

Output shape mirrors the Explain renderer's tree style but using OpenFGA's terminology: each node prints its name followed by either the leaf payload (users / computed pointer / TTU pointer) or the union/intersection/difference structure with children.

func ExpandString

func ExpandString(t *melange.UsersetTree, options ...Option) string

ExpandString renders an UsersetTree into a string. Convenience wrapper around Expand for tests, log lines, and HTTP responses.

func Trace

func Trace(w io.Writer, t *melange.Trace, options ...Option)

Trace writes a human-readable rendering of t to w. A nil trace prints nothing; an empty Root prints just the header line.

The output shape:

<header>
└── <root node>
    ├── <child>
    └── <child>
        └── <grandchild>
<truncation footer if any>

Explain headers include the subject and a ✓/✗ result marker. Expand headers carry only "<relation> on <object>" because the answer is the full tree, not a single boolean.

func TraceString

func TraceString(t *melange.Trace, options ...Option) string

TraceString renders t into a string. Convenience wrapper around Trace for callers that want the rendered output as a value (tests, log lines, HTTP responses).

Types

type Option

type Option func(*opts)

Option configures a single Trace rendering. The zero value is colorless output suitable for piped writers and captured strings.

func WithColor

func WithColor(enabled bool) Option

WithColor enables ANSI color escapes in the rendered output. Callers (e.g. the CLI command) typically detect TTY + NO_COLOR and pass the resolved bool.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL