Dependency injection in Xvc
Almost all Xvc functions receive a channel in the form
fn cmd_api(output_snd: Sender<XvcOutputLine>, ...)
Functions use this to send messages to user.
XvcOutputLine
is an enum in the form:
pub enum XvcOutputLine {
/// The output that we should be reporting
Output(String),
/// For informational messages the user doesn't usually follow
Info(String),
/// Warnings that are against some usual workflows
Warn(String),
/// Errors that interrupts a workflow but may be recoverable
Error(String),
/// Panics that interrupts the workflow and ends the program
/// Note that this doesn't call panic! automatically
Panic(String),
/// Progress bar ticks.
/// Self::Info is also used for Tick(1)
Tick(usize),
}
When a commands wants to send a text to the outside world or wants to increment a counter, it uses this enum.
Currently, all these outputs are written to the console. In the future, when other output channels (like web etc.) are created, these functions will return their output there.