File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,18 @@ pub enum KeyNode {
99 Node ( HashMap < String , KeyNode > ) ,
1010}
1111
12+ fn truncate ( s : & str , max_chars : usize ) -> String {
13+ match s. char_indices ( ) . nth ( max_chars) {
14+ None => String :: from ( s) ,
15+ Some ( ( idx, _) ) => {
16+ let shorter = & s[ ..idx] ;
17+ let snip = "//SNIP//" ;
18+ let new_s = format ! ( "{}{}" , shorter, snip) ;
19+ String :: from ( new_s)
20+ }
21+ }
22+ }
23+
1224impl KeyNode {
1325 pub fn absolute_keys ( & self , keys : & mut Vec < String > , key_from_root : Option < String > ) {
1426 let val_key = |key : Option < String > | {
@@ -24,8 +36,8 @@ impl KeyNode {
2436 KeyNode :: Value ( a, b) => keys. push ( format ! (
2537 "{} [ {} :: {} ]" ,
2638 val_key( key_from_root) ,
27- a. to_string( ) . blue( ) . bold( ) ,
28- b. to_string( ) . cyan( ) . bold( )
39+ truncate ( a. to_string( ) . as_str ( ) , 20 ) . blue( ) . bold( ) ,
40+ truncate ( b. to_string( ) . as_str ( ) , 20 ) . cyan( ) . bold( )
2941 ) ) ,
3042 KeyNode :: Node ( map) => {
3143 for ( key, value) in map {
@@ -38,3 +50,4 @@ impl KeyNode {
3850 }
3951 }
4052}
53+
You can’t perform that action at this time.
0 commit comments