Skip to main content

kaish_types/
job.rs

1//! Job identification and status types.
2
3use std::path::PathBuf;
4
5/// Unique identifier for a background job.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7pub struct JobId(pub u64);
8
9impl std::fmt::Display for JobId {
10    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
11        write!(f, "{}", self.0)
12    }
13}
14
15/// Status of a background job.
16#[derive(Debug, Clone, PartialEq, Eq)]
17pub enum JobStatus {
18    /// Job is currently running.
19    Running,
20    /// Job was stopped by a signal (e.g., Ctrl-Z / SIGTSTP).
21    Stopped,
22    /// Job completed successfully.
23    Done,
24    /// Job failed with an error.
25    Failed,
26}
27
28impl std::fmt::Display for JobStatus {
29    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
30        match self {
31            JobStatus::Running => write!(f, "Running"),
32            JobStatus::Stopped => write!(f, "Stopped"),
33            JobStatus::Done => write!(f, "Done"),
34            JobStatus::Failed => write!(f, "Failed"),
35        }
36    }
37}
38
39/// Information about a job for listing.
40#[derive(Debug, Clone)]
41pub struct JobInfo {
42    /// Job ID.
43    pub id: JobId,
44    /// Command description.
45    pub command: String,
46    /// Current status.
47    pub status: JobStatus,
48    /// Path to output file (if available).
49    pub output_file: Option<PathBuf>,
50    /// OS process ID (if this is a stopped/foreground process).
51    pub pid: Option<u32>,
52}