Output¶
cxg.output
¶
OutputFormat
¶
DetailOutputFormat
¶
fit_columns(columns, terminal_width, content_widths=None)
¶
Drop optional columns from the end until flexible columns have enough space.
Source code in src/cxg/output.py
dataset_column_value(dataset, column, *, truncate_id=False, for_table=False)
¶
Extract and format a column value from a dataset dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
dict[str, Any]
|
Dataset dictionary from the API. |
required |
column
|
str
|
Column name to extract. |
required |
truncate_id
|
bool
|
If True, truncate dataset_id to 8 characters. |
False
|
for_table
|
bool
|
If True, return Rich Text with styling and truncated lists. |
False
|
Returns:
| Type | Description |
|---|---|
str | Text
|
Formatted string or Rich Text object. |
Source code in src/cxg/output.py
sort_datasets(datasets, sort_by)
¶
Sort datasets by the given key and direction.
The sort_by value is a column name optionally followed by a direction (asc or desc), separated by a space or colon. Defaults to descending.
Source code in src/cxg/output.py
render_datasets_table(datasets, columns, terminal_width=80)
¶
Render a Rich table of datasets with adaptive column widths.
Source code in src/cxg/output.py
render_dataset_detail(dataset, *, full=False)
¶
Render a polished, multi-section detail view of a single dataset.
Sections (top to bottom): collection headline + DOI, dataset title strip,
side-by-side "Overview" / "Timeline" panels, a "Details" key/value block
with linked ontology terms, "Assets" with linkified URLs, and a "Next"
action block. With full=True, ontology lists expand to one term per
line and an extra metadata/details block surfaces version IDs, citation,
and the full donor list.
Source code in src/cxg/output.py
render_collection_detail(collection, *, full=False)
¶
Render a polished, multi-section detail view of a single collection.
Sections (top to bottom): collection headline + DOI/journal, ID + contact
strip, optional description, side-by-side "At a glance" / "Timeline"
panels, "Composition" key/value block aggregating ontology terms across
nested datasets, "Datasets" table, optional "Links" table, and a "Next"
action block. With full=True, the description is shown in full,
ontology lists expand, and the dataset table shows every row.
Source code in src/cxg/output.py
render_collections_table(collections)
¶
Render a Rich table of collections with index, ID, name, and dataset count.
Source code in src/cxg/output.py
render_fields_list_table(rows)
¶
Render a Rich table of filterable fields with match type and example.
Source code in src/cxg/output.py
render_fields_table(rows)
¶
Render a Rich table of field values and their counts.
Source code in src/cxg/output.py
print_json(console, payload)
¶
datasets_to_tsv(datasets, columns)
¶
Serialize datasets to a TSV string with a header row.
Source code in src/cxg/output.py
fields_to_tsv(rows)
¶
Serialize field value counts to a TSV string with a header row.
Source code in src/cxg/output.py
format_age(fetched_at)
¶
Format a datetime as a human-readable relative age string (e.g., "5m ago").