pub struct OutputData {
pub headers: Option<Vec<String>>,
pub root: Vec<OutputNode>,
}Expand description
Structured output data from a command.
This is the top-level structure for command output. It contains optional column headers and a list of root nodes.
§Rendering Rules
| Structure | Interactive | Piped/Model |
|---|---|---|
Single node with text | Print text | Print text |
Flat nodes, name only | Multi-column, colored | One per line |
Flat nodes with cells | Aligned table | TSV or names only |
Nested children | Box-drawing tree | Brace notation |
Fields§
§headers: Option<Vec<String>>Column headers (optional, for table output).
root: Vec<OutputNode>Top-level nodes.
Implementations§
Source§impl OutputData
impl OutputData
Sourcepub fn text(content: impl Into<String>) -> Self
pub fn text(content: impl Into<String>) -> Self
Create output data with a single text node.
This is the simplest form for commands like echo.
Sourcepub fn nodes(nodes: Vec<OutputNode>) -> Self
pub fn nodes(nodes: Vec<OutputNode>) -> Self
Create output data with named nodes (for ls, etc.).
Sourcepub fn table(headers: Vec<String>, nodes: Vec<OutputNode>) -> Self
pub fn table(headers: Vec<String>, nodes: Vec<OutputNode>) -> Self
Create output data with headers and nodes (for ls -l, ps, etc.).
Sourcepub fn with_headers(self, headers: Vec<String>) -> Self
pub fn with_headers(self, headers: Vec<String>) -> Self
Set column headers.
Sourcepub fn is_simple_text(&self) -> bool
pub fn is_simple_text(&self) -> bool
Check if this output is simple text (single text-only node).
Sourcepub fn is_tabular(&self) -> bool
pub fn is_tabular(&self) -> bool
Check if this output has tabular data (nodes with cells).
Sourcepub fn to_canonical_string(&self) -> String
pub fn to_canonical_string(&self) -> String
Convert to canonical string output (for pipes).
This produces a simple string representation suitable for piping to other commands:
- Text nodes: their text content
- Named nodes: names joined by newlines
- Tabular nodes (name + cells): TSV format (name\tcell1\tcell2…)
- Nested nodes: brace notation
Sourcepub fn to_json(&self) -> Value
pub fn to_json(&self) -> Value
Serialize to a JSON value for --json flag handling.
Bare data, no envelope — optimized for jq patterns.
| Structure | JSON |
|---|---|
| Simple text | "hello world" |
| Flat list (names only) | ["file1", "file2"] |
| Table (headers + cells) | [{"col1": "v1", ...}, ...] |
| Tree (nested children) | {"dir": {"file": null}} |
Trait Implementations§
Source§impl Clone for OutputData
impl Clone for OutputData
Source§fn clone(&self) -> OutputData
fn clone(&self) -> OutputData
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more