pub enum ProcessEvent {
Started {
id: RunId,
invocation: Invocation,
process_id: Option<ProcessId>,
},
Line {
id: RunId,
line: Line,
},
Finished {
id: RunId,
invocation: Invocation,
outcome: Outcome,
duration: Duration,
},
}Expand description
One step in the run of an external program
Clawless sends these events while a program runs, so that a presenter can render the output of the program as it arrives instead of after the program ends. A build that takes two minutes therefore shows two minutes of progress.
Every run sends Started first and Finished last, with one Line
in between for each line that the program wrote. Two things end a run
without a Finished: a consumer that stopped listening, which cannot be
told anything, and a caller that dropped the run instead of cancelling it,
which leaves no code to send the event.
Each variant carries the RunId of its run. Two programs that run at
the same time interleave their lines in the channel, and the identity is
what separates them again. Started and Finished also carry the
command itself, so that a presenter which keeps no state can name the
program it is reporting on.
Started carries the ProcessId of the program as well. That value is
the name the operating system knows the program by, which is what an
operator needs to find it in a process list.
§Examples
use clawless_core::event::process::{ProcessEvent, RunId};
use clawless_core::process::Invocation;
let event = ProcessEvent::Started {
id: RunId::next(),
invocation: Invocation::new("git").arg("status"),
process_id: None,
};
assert_eq!(event.to_string(), "$ git status");Variants§
Started
The program started
The event names the command, which is what a consumer shows while the program runs.
Fields
invocation: InvocationThe command that the run starts
Line
The program wrote one line
The line carries the stream that produced it, so that a consumer can show a diagnostic apart from a result, or drop one of the two. It holds no characters that end a line.
Finished
The program ended
No further event carries this identity. A consumer that shows running programs removes the run here.
Implementations§
Source§impl ProcessEvent
impl ProcessEvent
Sourcepub fn id(&self) -> RunId
pub fn id(&self) -> RunId
Returns the run that the event belongs to
A consumer that groups the events of one program reads the identity here instead of matching on the variant.
§Examples
use clawless_core::event::process::{ProcessEvent, RunId};
use clawless_core::process::Invocation;
let id = RunId::next();
let event = ProcessEvent::Started {
id,
invocation: Invocation::new("git"),
process_id: None,
};
assert_eq!(event.id(), id);Trait Implementations§
Source§impl Clone for ProcessEvent
impl Clone for ProcessEvent
Source§impl Debug for ProcessEvent
impl Debug for ProcessEvent
Source§impl Display for ProcessEvent
Renders the event as one line of a transcript
impl Display for ProcessEvent
Renders the event as one line of a transcript
The start of a run reads as a shell prompt, a line of output reads as the program wrote it, and the end of a run states what became of the command. A consumer that wants another shape matches on the variant and builds its own.
The text never names the stream that produced a line. A presenter that separates the two writes them to different places instead of labelling them, which keeps the output of the program readable.