status.rs

  1use gpui::Hsla;
  2use refineable::Refineable;
  3
  4use crate::{blue, grass, neutral, red, yellow};
  5
  6#[derive(Refineable, Clone, Debug)]
  7#[refineable(Debug, serde::Deserialize)]
  8pub struct StatusColors {
  9    /// Indicates some kind of conflict, like a file changed on disk while it was open, or
 10    /// merge conflicts in a Git repository.
 11    pub conflict: Hsla,
 12
 13    /// Indicates something new, like a new file added to a Git repository.
 14    pub created: Hsla,
 15
 16    /// Indicates that something no longer exists, like a deleted file.
 17    pub deleted: Hsla,
 18
 19    /// Indicates a system error, a failed operation or a diagnostic error.
 20    pub error: Hsla,
 21
 22    /// Represents a hidden status, such as a file being hidden in a file tree.
 23    pub hidden: Hsla,
 24
 25    /// Indicates a hint or some kind of additional information.
 26    pub hint: Hsla,
 27
 28    /// Indicates that something is deliberately ignored, such as a file or operation ignored by Git.
 29    pub ignored: Hsla,
 30
 31    /// Represents informational status updates or messages.
 32    pub info: Hsla,
 33
 34    /// Indicates a changed or altered status, like a file that has been edited.
 35    pub modified: Hsla,
 36
 37    /// Indicates something that is predicted, like automatic code completion, or generated code.
 38    pub predictive: Hsla,
 39
 40    /// Represents a renamed status, such as a file that has been renamed.
 41    pub renamed: Hsla,
 42
 43    /// Indicates a successful operation or task completion.
 44    pub success: Hsla,
 45
 46    /// Indicates some kind of unreachable status, like a block of code that can never be reached.
 47    pub unreachable: Hsla,
 48
 49    /// Represents a warning status, like an operation that is about to fail.
 50    pub warning: Hsla,
 51}
 52
 53impl Default for StatusColors {
 54    /// Don't use this!
 55    /// We have to have a default to be `[refineable::Refinable]`.
 56    /// todo!("Find a way to not need this for Refinable")
 57    fn default() -> Self {
 58        Self::dark()
 59    }
 60}
 61
 62pub struct DiagnosticColors {
 63    pub error: Hsla,
 64    pub warning: Hsla,
 65    pub info: Hsla,
 66}
 67
 68pub struct GitStatusColors {
 69    pub created: Hsla,
 70    pub deleted: Hsla,
 71    pub modified: Hsla,
 72    pub renamed: Hsla,
 73    pub conflict: Hsla,
 74    pub ignored: Hsla,
 75}
 76
 77impl StatusColors {
 78    pub fn dark() -> Self {
 79        Self {
 80            conflict: red().dark().step_9(),
 81            created: grass().dark().step_9(),
 82            deleted: red().dark().step_9(),
 83            error: red().dark().step_9(),
 84            hidden: neutral().dark().step_9(),
 85            hint: blue().dark().step_9(),
 86            ignored: neutral().dark().step_9(),
 87            info: blue().dark().step_9(),
 88            modified: yellow().dark().step_9(),
 89            predictive: neutral().dark_alpha().step_9(),
 90            renamed: blue().dark().step_9(),
 91            success: grass().dark().step_9(),
 92            unreachable: neutral().dark().step_10(),
 93            warning: yellow().dark().step_9(),
 94        }
 95    }
 96
 97    pub fn light() -> Self {
 98        Self {
 99            conflict: red().light().step_9(),
100            created: grass().light().step_9(),
101            deleted: red().light().step_9(),
102            error: red().light().step_9(),
103            hidden: neutral().light().step_9(),
104            hint: blue().light().step_9(),
105            ignored: neutral().light().step_9(),
106            info: blue().light().step_9(),
107            modified: yellow().light().step_9(),
108            predictive: neutral().light_alpha().step_9(),
109            renamed: blue().light().step_9(),
110            success: grass().light().step_9(),
111            unreachable: neutral().light().step_10(),
112            warning: yellow().light().step_9(),
113        }
114    }
115
116    pub fn diagnostic(&self) -> DiagnosticColors {
117        DiagnosticColors {
118            error: self.error,
119            warning: self.warning,
120            info: self.info,
121        }
122    }
123
124    pub fn git(&self) -> GitStatusColors {
125        GitStatusColors {
126            created: self.created,
127            deleted: self.deleted,
128            modified: self.modified,
129            renamed: self.renamed,
130            conflict: self.conflict,
131            ignored: self.ignored,
132        }
133    }
134}