1
1
use std:: collections:: { BTreeMap , BTreeSet } ;
2
2
3
+ use egui:: Color32 ;
4
+
3
5
#[ derive( serde:: Deserialize , serde:: Serialize , Debug , PartialEq , Eq ) ]
4
6
#[ serde( default ) ] // if we add new fields, give them default values when deserializing old state
5
7
pub struct DataDisplayOptions {
@@ -13,6 +15,9 @@ pub struct DataDisplayOptions {
13
15
/// WARNING: This must be a valid index into the list as this is assumed in method implementations
14
16
emphasize_if_matching_field_idx : Option < usize > ,
15
17
18
+ /// Fields that should be colored based on their value. Key is field name
19
+ pub colored_fields : BTreeMap < String , FieldColoringRules > ,
20
+
16
21
/// When set adds a field with this name and populates it with the row numbers (Skips record if field name already exists)
17
22
pub row_idx_field_name : Option < String > ,
18
23
@@ -23,6 +28,12 @@ pub struct DataDisplayOptions {
23
28
pub level_conversion : Option < LevelConversion > ,
24
29
}
25
30
31
+ #[ derive( serde:: Deserialize , serde:: Serialize , Debug , PartialEq , Eq ) ]
32
+ pub struct FieldColoringRules {
33
+ /// Matches a field value to color
34
+ pub value_color_map : BTreeMap < String , Color32 > ,
35
+ }
36
+
26
37
#[ derive( serde:: Deserialize , serde:: Serialize , Debug , PartialEq , Eq ) ]
27
38
pub enum RowParseErrorHandling {
28
39
AbortOnAnyErrors ,
@@ -99,6 +110,23 @@ impl Default for DataDisplayOptions {
99
110
row_idx_field_name : Some ( "row#" . to_string ( ) ) ,
100
111
row_parse_error_handling : Default :: default ( ) ,
101
112
level_conversion : Some ( Default :: default ( ) ) ,
113
+ colored_fields : [ (
114
+ "level_str" . to_string ( ) ,
115
+ FieldColoringRules {
116
+ value_color_map : [
117
+ ( "Trace" . to_string ( ) , Color32 :: from_rgb ( 150 , 100 , 200 ) ) ,
118
+ ( "Debug" . to_string ( ) , Color32 :: from_rgb ( 80 , 140 , 205 ) ) ,
119
+ ( "Info" . to_string ( ) , Color32 :: from_rgb ( 15 , 175 , 85 ) ) ,
120
+ ( "Warn" . to_string ( ) , Color32 :: from_rgb ( 210 , 210 , 20 ) ) ,
121
+ ( "Error" . to_string ( ) , Color32 :: from_rgb ( 220 , 105 , 105 ) ) ,
122
+ ( "Fatal" . to_string ( ) , Color32 :: from_rgb ( 255 , 20 , 20 ) ) ,
123
+ ]
124
+ . into_iter ( )
125
+ . collect ( ) ,
126
+ } ,
127
+ ) ]
128
+ . into_iter ( )
129
+ . collect ( ) ,
102
130
}
103
131
}
104
132
}
0 commit comments