use {
crate::*,
serde::{
Deserialize,
Serialize,
},
std::process::ExitStatus,
};
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Eq)]
pub enum CommandStream {
StdOut,
StdErr,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct RawCommandOutputLine {
pub content: String,
pub origin: CommandStream,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct CommandOutputLine {
pub content: TLine,
pub origin: CommandStream,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
pub struct CommandOutput {
pub lines: Vec<Line>,
}
#[derive(Debug)]
pub enum CommandExecInfo {
End { status: ExitStatus },
Interruption,
Error(anyhow::Error),
Line(RawCommandOutputLine),
}
impl CommandOutput {
pub fn reverse(&mut self) {
self.lines.reverse();
}
pub fn push<L: Into<Line>>(
&mut self,
line: L,
) {
self.lines.push(line.into());
}
pub fn len(&self) -> usize {
self.lines.len()
}
}
impl From<RawCommandOutputLine> for CommandOutputLine {
fn from(raw: RawCommandOutputLine) -> Self {
CommandOutputLine {
content: TLine::from_tty(&raw.content),
origin: raw.origin,
}
}
}