pub struct Output { /* private fields */ }Expand description
Command output interface that wraps an event channel sender
Output provides typed methods for each event kind, decoupling commands from the event channel
API. Commands call message, detail, or artifact to emit events; the Presenter
consumes them for rendering.
Output is cheaply clonable. Cloning an Output produces another handle to the same
underlying channel, not an independent channel.
§Examples
use clawless_core::event::event_channel;
use clawless_core::output::Output;
let (sender, mut receiver) = event_channel();
let output = Output::new(sender);
output.message("hello").await.expect("should send");Implementations§
Source§impl Output
impl Output
Sourcepub fn new(sender: EventSender) -> Self
pub fn new(sender: EventSender) -> Self
Creates a new Output wrapping the given event sender
§Examples
use clawless_core::event::event_channel;
use clawless_core::output::Output;
let (sender, _receiver) = event_channel();
let output = Output::new(sender);Sourcepub async fn message(&self, message: impl Display) -> Result<(), SendError>
pub async fn message(&self, message: impl Display) -> Result<(), SendError>
Sends an informational message event
Converts the value to a string via Display and sends it as an Event::Message.
§Errors
Returns SendError if the EventReceiver has been dropped.
§Examples
use clawless_core::event::event_channel;
use clawless_core::output::Output;
let (sender, _receiver) = event_channel();
let output = Output::new(sender);
output.message("processing files").await.expect("should send");
output.message(format!("found {} items", 42)).await.expect("should send");Sourcepub async fn detail(&self, detail: impl Display) -> Result<(), SendError>
pub async fn detail(&self, detail: impl Display) -> Result<(), SendError>
Sends a supplementary detail event
Converts the value to a string via Display and sends it as an Event::Detail.
Details carry lower-priority information that the Presenter may suppress at default
verbosity.
§Errors
Returns SendError if the EventReceiver has been dropped.
§Examples
use clawless_core::event::event_channel;
use clawless_core::output::Output;
let (sender, _receiver) = event_channel();
let output = Output::new(sender);
output.detail("reading config from ~/.config/app.toml").await.expect("should send");Sourcepub async fn artifact<T>(&self, value: T) -> Result<(), SendError>
pub async fn artifact<T>(&self, value: T) -> Result<(), SendError>
Sends a structured artifact event
Wraps the value in a Box and sends it as an Event::Artifact. The value must
implement Display (for text rendering), Serialize (for JSON rendering), and
Debug (for diagnostics).
§Errors
Returns SendError if the EventReceiver has been dropped.
§Examples
use std::fmt;
use serde::Serialize;
use clawless_core::event::event_channel;
use clawless_core::output::Output;
#[derive(Clone, Debug, Serialize)]
struct UserCount {
count: usize,
}
impl fmt::Display for UserCount {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{} users", self.count)
}
}
let (sender, _receiver) = event_channel();
let output = Output::new(sender);
output.artifact(UserCount { count: 42 }).await.expect("should send");Sourcepub async fn process_event(&self, event: ProcessEvent) -> Result<(), SendError>
pub async fn process_event(&self, event: ProcessEvent) -> Result<(), SendError>
Sends one step in the run of an external program
Process calls this for every step of a run, so a command that runs a program through
Clawless does not call it. An application that drives a program itself, and wants its
output to reach the presenter in the same shape, reports the run through this method.
§Errors
Returns SendError if the EventReceiver has been dropped.
§Examples
use clawless_core::event::event_channel;
use clawless_core::event::process::{ProcessEvent, RunId};
use clawless_core::output::Output;
use clawless_core::process::Invocation;
let (sender, _receiver) = event_channel();
let output = Output::new(sender);
output
.process_event(ProcessEvent::Started {
id: RunId::next(),
invocation: Invocation::new("git").arg("status"),
process_id: None,
})
.await
.expect("should send");Sourcepub async fn prompt(&self, request: PromptRequest) -> Result<(), SendError>
pub async fn prompt(&self, request: PromptRequest) -> Result<(), SendError>
Sends a question for the user
The request arrives after every event that this output sent before it. The answer
arrives at the PendingAnswer that was created together with the request.
§Errors
Returns SendError if the EventReceiver has been dropped.
§Examples
use clawless_core::event::event_channel;
use clawless_core::event::prompt::PromptRequest;
use clawless_core::output::Output;
use clawless_core::prompt::Confirm;
let (sender, _receiver) = event_channel();
let output = Output::new(sender);
let (request, _pending) = PromptRequest::confirm(Confirm::new("Delete the branch?"));
output.prompt(request).await.expect("should send");