use super::super::config::{OutputMode, OutputStream};
use crate::localization::{self, keys};
#[derive(Clone, Copy)]
pub(super) struct ExitDetails<'a> {
pub(super) status: Option<i32>,
pub(super) stderr: &'a [u8],
}
impl<'a> ExitDetails<'a> {
pub(super) const fn new(status: Option<i32>, stderr: &'a [u8]) -> Self {
Self { status, stderr }
}
}
#[derive(Clone, Copy)]
pub(super) struct LimitExceeded {
pub(super) stream: OutputStream,
pub(super) mode: OutputMode,
pub(super) limit: u64,
}
impl LimitExceeded {
pub(super) const fn new(stream: OutputStream, mode: OutputMode, limit: u64) -> Self {
Self {
stream,
mode,
limit,
}
}
}
pub(super) fn append_exit_status(message: &mut String, status: Option<i32>) {
if let Some(code) = status {
let suffix = localization::message(keys::COMMAND_EXIT_STATUS_SUFFIX)
.with_arg("status", code)
.to_string();
message.push(' ');
message.push_str(&suffix);
} else {
message.push(' ');
message.push_str(&localization::message(keys::COMMAND_SIGNAL_SUFFIX).to_string());
}
}
pub(super) fn append_stderr(message: &mut String, stderr: &[u8]) {
let stderr_text = String::from_utf8_lossy(stderr);
let trimmed = stderr_text.trim();
if !trimmed.is_empty() {
message.push_str(": ");
message.push_str(trimmed);
}
}