1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use comfy_table::Color;
use crossterm::style::Stylize;
use serde::{Deserialize, Serialize};
use std::fmt::{Display, Formatter};
use strum::Display;
#[derive(Deserialize, Serialize)]
pub struct Response {
pub name: String,
pub state: State,
}
#[derive(Clone, Debug, Deserialize, Display, Serialize, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
#[strum(serialize_all = "lowercase")]
pub enum State {
Creating,
Starting,
Started,
Ready,
Stopping,
Stopped,
Destroying,
Destroyed,
Errored,
}
impl Display for Response {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"project '{}' is {}",
self.name,
self.state.to_string().with(self.state.get_color())
)
}
}
impl State {
pub fn get_color(&self) -> Color {
match self {
State::Creating | State::Starting | State::Started => Color::Cyan,
State::Ready => Color::Green,
State::Stopped | State::Stopping | State::Destroying | State::Destroyed => Color::Blue,
State::Errored => Color::Red,
}
}
}