Skip to content

Commit 8628080

Browse files
committed
Account for ansi_color os-release compatability
Tbqh this is an ugly option but os-release propogates this to systemd and such so we'd break branding integration immediately without it. Signed-off-by: Ikey Doherty <ikey@aerynos.com>
1 parent bf08ac4 commit 8628080

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed

SPECIFICATION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ The metadata section contains:
3636
- `id`: Unique OS identifier
3737
- `name`: Full OS name
3838
- `display`: Display name for presentation
39+
- `ansi_color`: ANSI color escape sequence for terminal branding (optional)
3940
- `id_like`: Parent OS identifier (optional)
4041
- `former_identities`: Historical names and identifiers
4142

crates/os-info/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ pub struct Identity {
6161
pub name: String,
6262
/// Display name/branding
6363
pub display: String,
64+
/// ANSI terminal color code for branding
65+
pub ansi_color: Option<String>,
6466
/// Previous identities/names
6567
pub former_identities: Vec<FormerIdentity>,
6668
}

crates/os-info/src/os_release.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ impl From<&OSInfo> for OsRelease {
115115
// Set optional fields
116116
release.id_like = info.metadata.identity.id_like.clone();
117117

118+
// Set ANSI color if available
119+
if let Some(ansi_color) = &info.metadata.identity.ansi_color {
120+
release
121+
.extra_fields
122+
.insert("ANSI_COLOR".to_string(), ansi_color.clone());
123+
}
124+
118125
// Map website URLs based on their scope
119126
for site in info.resources.websites.values() {
120127
match site.scope {
@@ -207,6 +214,21 @@ mod tests {
207214
assert_eq!(shell_escape("with \"quotes\""), "\"with \\\"quotes\\\"\"");
208215
}
209216

217+
#[test]
218+
fn test_ansi_color() {
219+
let mut info = load_os_info(include_str!("../../../sample.json")).unwrap();
220+
info.metadata.identity.ansi_color = Some("38;2;23;147;209".to_string());
221+
222+
let release = OsRelease::from(&info);
223+
assert_eq!(
224+
release.extra_fields.get("ANSI_COLOR"),
225+
Some(&"38;2;23;147;209".to_string())
226+
);
227+
228+
let output = release.to_string();
229+
assert!(output.contains("ANSI_COLOR=\"38;2;23;147;209\"\n"));
230+
}
231+
210232
#[test]
211233
fn test_extra_fields() {
212234
let mut release = OsRelease::new(

sample.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"id_like": "linux",
99
"name": "AerynOS",
1010
"display": "AerynOS 0.25.1",
11+
"ansi_color": "1;35",
1112
"former_identities": [
1213
{
1314
"id": "serpent-os",

schema/0.1/os-info.schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
"id_like": { "type": "string" },
2828
"name": { "type": "string" },
2929
"display": { "type": "string" },
30+
"ansi_color": {
31+
"type": "string",
32+
"description": "ANSI color escape sequence for terminal branding"
33+
},
3034
"former_identities": {
3135
"type": "array",
3236
"items": {

0 commit comments

Comments
 (0)