11use std:: collections:: { BTreeMap , BTreeSet } ;
22
3+ use egui:: Color32 ;
4+
35#[ derive( serde:: Deserialize , serde:: Serialize , Debug , PartialEq , Eq ) ]
46#[ serde( default ) ] // if we add new fields, give them default values when deserializing old state
57pub struct DataDisplayOptions {
@@ -13,6 +15,9 @@ pub struct DataDisplayOptions {
1315 /// WARNING: This must be a valid index into the list as this is assumed in method implementations
1416 emphasize_if_matching_field_idx : Option < usize > ,
1517
18+ /// Fields that should be colored based on their value. Key is field name
19+ pub colored_fields : BTreeMap < String , FieldColoringRules > ,
20+
1621 /// When set adds a field with this name and populates it with the row numbers (Skips record if field name already exists)
1722 pub row_idx_field_name : Option < String > ,
1823
@@ -23,6 +28,12 @@ pub struct DataDisplayOptions {
2328 pub level_conversion : Option < LevelConversion > ,
2429}
2530
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+
2637#[ derive( serde:: Deserialize , serde:: Serialize , Debug , PartialEq , Eq ) ]
2738pub enum RowParseErrorHandling {
2839 AbortOnAnyErrors ,
@@ -99,6 +110,23 @@ impl Default for DataDisplayOptions {
99110 row_idx_field_name : Some ( "row#" . to_string ( ) ) ,
100111 row_parse_error_handling : Default :: default ( ) ,
101112 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 ( ) ,
102130 }
103131 }
104132}
0 commit comments