output
Class info¶
Classes¶
| Name | Children | Inherits |
|---|---|---|
| CallbackOutputWriter slashed.output Output writer that directly delegates printing to a callback function. |
||
| DefaultOutputWriter slashed.output Default output implementation using rich if available. |
||
| QueueOutputWriter slashed.output Output writer that puts messages in queue. |
||
| TransformOutputWriter slashed.output Output writer that transforms messages before printing via another writer. |
🛈 DocStrings¶
Output implementations for command system.
CallbackOutputWriter
¶
Bases: OutputWriter
Output writer that directly delegates printing to a callback function.
The callback can be either sync or async and is fully responsible for how the message is displayed/written.
Examples:
# Async callback
async def log_to_file(msg: str, file: str) -> None:
with open(file, "a") as f:
f.write(msg)
# Sync callback
def print_to_console(msg: str, prefix: str) -> None:
print(f"{prefix}: {msg}")
writer1 = CallbackOutputWriter(log_to_file, "output.log")
writer2 = CallbackOutputWriter(print_to_console, prefix="Debug")
Source code in src/slashed/output.py
DefaultOutputWriter
¶
Bases: OutputWriter
Default output implementation using rich if available.
Source code in src/slashed/output.py
QueueOutputWriter
¶
Bases: DefaultOutputWriter
Output writer that puts messages in queue.
Source code in src/slashed/output.py
TransformOutputWriter
¶
Bases: OutputWriter
Output writer that transforms messages before printing via another writer.
Unlike CallbackOutputWriter, this doesn't handle the actual output. Instead, it transforms the message and delegates printing to a base writer. Use this for adding prefixes, timestamps, or other message modifications.
Example
Source code in src/slashed/output.py
__init__
¶
__init__(
transform: Callable[..., Awaitable[str]],
*args: Any,
base_writer: OutputWriter | None = None,
**kwargs: Any,
) -> None
Initialize with transform function and base writer.