11use super :: View ;
22use crate :: app:: App ;
33use crate :: dbgp:: client:: Property ;
4+ use crate :: dbgp:: client:: PropertyType ;
45use crate :: event:: input:: AppEvent ;
6+ use crate :: theme:: Scheme ;
57use ratatui:: layout:: Rect ;
6- use ratatui:: style:: Color ;
7- use ratatui:: style:: Style ;
88use ratatui:: text:: Line ;
99use ratatui:: text:: Span ;
1010use ratatui:: widgets:: Paragraph ;
@@ -28,7 +28,7 @@ impl View for ContextComponent {
2828 None => return ,
2929 } ;
3030 let mut lines: Vec < Line > = vec ! [ ] ;
31- draw_properties ( & context. properties , & mut lines, 0 ) ;
31+ draw_properties ( & app . theme ( ) , & context. properties , & mut lines, 0 ) ;
3232
3333 frame. render_widget (
3434 Paragraph :: new ( lines)
@@ -39,37 +39,58 @@ impl View for ContextComponent {
3939 }
4040}
4141
42- pub fn draw_properties ( properties : & Vec < Property > , lines : & mut Vec < Line > , level : usize ) {
42+ pub fn draw_properties (
43+ theme : & Scheme ,
44+ properties : & Vec < Property > ,
45+ lines : & mut Vec < Line > ,
46+ level : usize ,
47+ ) {
4348 for property in properties {
44- let value = property. value . clone ( ) . unwrap_or ( "" . to_string ( ) ) ;
45- lines. push ( Line :: from ( vec ! [
49+ let mut spans = vec ! [
4650 Span :: raw( " " . repeat( level) ) ,
47- Span :: styled( property. name. to_string( ) , Style :: default ( ) . fg ( Color :: White ) ) ,
51+ Span :: styled( property. name. to_string( ) , theme . syntax_label ) ,
4852 Span :: raw( " " . to_string( ) ) ,
4953 Span :: styled(
50- property. property_type. to_string( ) ,
51- Style :: default ( ) . fg( Color :: Blue ) ,
54+ property. type_name( ) ,
55+ match property. property_type {
56+ PropertyType :: Object => theme. syntax_type_object,
57+ _ => theme. syntax_type,
58+ } ,
5259 ) ,
5360 Span :: raw( " = " . to_string( ) ) ,
54- match property. property_type. as_str( ) {
55- "bool" => Span :: styled( value, Style :: default ( ) . fg( Color :: LightRed ) ) ,
56- "int" => Span :: styled( value, Style :: default ( ) . fg( Color :: LightBlue ) ) ,
57- "float" => Span :: styled( value, Style :: default ( ) . fg( Color :: LightBlue ) ) ,
58- "string" => Span :: styled( value, Style :: default ( ) . fg( Color :: LightGreen ) ) ,
59- "array" => Span :: styled( value, Style :: default ( ) . fg( Color :: Cyan ) ) ,
60- "hash" => Span :: styled( value, Style :: default ( ) . fg( Color :: Cyan ) ) ,
61- "object" => match & property. classname {
62- Some ( name) => Span :: styled( name. to_string( ) , Style :: default ( ) . fg( Color :: Red ) ) ,
63- None => Span :: styled( value, Style :: default ( ) . fg( Color :: Red ) ) ,
64- } ,
65- "resource" => Span :: styled( value, Style :: default ( ) . fg( Color :: Red ) ) ,
66- "undefined" => Span :: styled( value, Style :: default ( ) . fg( Color :: White ) ) ,
67- _ => Span :: raw( value) ,
68- } ,
69- ] ) ) ;
61+ render_value( theme, property) ,
62+ ] ;
63+
64+ let delimiters = match property. property_type {
65+ PropertyType :: Array => ( "[" , "]" ) ,
66+ _ => ( "{" , "}" ) ,
67+ } ;
7068
7169 if !property. children . is_empty ( ) {
72- draw_properties ( & property . children , lines , level + 1 ) ;
70+ spans . push ( Span :: raw ( delimiters . 0 ) . style ( theme . syntax_brace ) ) ;
7371 }
72+
73+ lines. push ( Line :: from ( spans) ) ;
74+
75+ if !property. children . is_empty ( ) {
76+ draw_properties ( theme, & property. children , lines, level + 1 ) ;
77+ lines. push ( Line :: from ( vec ! [ Span :: raw( delimiters. 1 ) ] ) . style ( theme. syntax_brace ) ) ;
78+ }
79+ }
80+ }
81+
82+ pub fn render_value < ' a > ( theme : & Scheme , property : & Property ) -> Span < ' a > {
83+ let value = property. value . clone ( ) . unwrap_or ( "" . to_string ( ) ) ;
84+ match property. property_type {
85+ PropertyType :: Bool => Span :: styled ( value, theme. syntax_literal ) ,
86+ PropertyType :: Int => Span :: styled ( value, theme. syntax_literal ) ,
87+ PropertyType :: Float => Span :: styled ( value, theme. syntax_literal ) ,
88+ PropertyType :: String => Span :: styled ( format ! ( "\" {}\" " , value) , theme. syntax_literal_string ) ,
89+ PropertyType :: Array => Span :: styled ( value, theme. syntax_literal ) ,
90+ PropertyType :: Hash => Span :: styled ( value, theme. syntax_literal ) ,
91+ PropertyType :: Object => Span :: styled ( value, theme. syntax_literal ) ,
92+ PropertyType :: Resource => Span :: styled ( value, theme. syntax_literal ) ,
93+ PropertyType :: Undefined => Span :: styled ( value, theme. syntax_literal ) ,
94+ _ => Span :: styled ( value, theme. syntax_literal ) ,
7495 }
7596}
0 commit comments