File tree Expand file tree Collapse file tree 5 files changed +30
-0
lines changed Expand file tree Collapse file tree 5 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ The metadata section contains:
36
36
- ` id ` : Unique OS identifier
37
37
- ` name ` : Full OS name
38
38
- ` display ` : Display name for presentation
39
+ - ` ansi_color ` : ANSI color escape sequence for terminal branding (optional)
39
40
- ` id_like ` : Parent OS identifier (optional)
40
41
- ` former_identities ` : Historical names and identifiers
41
42
Original file line number Diff line number Diff line change @@ -61,6 +61,8 @@ pub struct Identity {
61
61
pub name : String ,
62
62
/// Display name/branding
63
63
pub display : String ,
64
+ /// ANSI terminal color code for branding
65
+ pub ansi_color : Option < String > ,
64
66
/// Previous identities/names
65
67
pub former_identities : Vec < FormerIdentity > ,
66
68
}
Original file line number Diff line number Diff line change @@ -115,6 +115,13 @@ impl From<&OSInfo> for OsRelease {
115
115
// Set optional fields
116
116
release. id_like = info. metadata . identity . id_like . clone ( ) ;
117
117
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
+
118
125
// Map website URLs based on their scope
119
126
for site in info. resources . websites . values ( ) {
120
127
match site. scope {
@@ -207,6 +214,21 @@ mod tests {
207
214
assert_eq ! ( shell_escape( "with \" quotes\" " ) , "\" with \\ \" quotes\\ \" \" " ) ;
208
215
}
209
216
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
+
210
232
#[ test]
211
233
fn test_extra_fields ( ) {
212
234
let mut release = OsRelease :: new (
Original file line number Diff line number Diff line change 8
8
"id_like" : " linux" ,
9
9
"name" : " AerynOS" ,
10
10
"display" : " AerynOS 0.25.1" ,
11
+ "ansi_color" : " 1;35" ,
11
12
"former_identities" : [
12
13
{
13
14
"id" : " serpent-os" ,
Original file line number Diff line number Diff line change 27
27
"id_like" : { "type" : " string" },
28
28
"name" : { "type" : " string" },
29
29
"display" : { "type" : " string" },
30
+ "ansi_color" : {
31
+ "type" : " string" ,
32
+ "description" : " ANSI color escape sequence for terminal branding"
33
+ },
30
34
"former_identities" : {
31
35
"type" : " array" ,
32
36
"items" : {
You can’t perform that action at this time.
0 commit comments