1
- use ansi_term :: Colour ;
1
+ use colored :: Colorize ;
2
2
use std:: fmt;
3
3
4
4
use crate :: * ;
@@ -49,41 +49,33 @@ impl<'a> Format for VTypeExt<'a> {
49
49
impl < ' a > FormatColored for VTypeExt < ' a > {
50
50
fn get_oneline_colored ( & self ) -> String {
51
51
match * self {
52
- VTypeExt :: Plain ( VType :: Bool ) => Colour :: Cyan . paint ( "bool" ) . to_string ( ) ,
53
- VTypeExt :: Plain ( VType :: Int ) => Colour :: Cyan . paint ( "int" ) . to_string ( ) ,
54
- VTypeExt :: Plain ( VType :: Float ) => Colour :: Cyan . paint ( "float" ) . to_string ( ) ,
55
- VTypeExt :: Plain ( VType :: String ) => Colour :: Cyan . paint ( "string" ) . to_string ( ) ,
56
- VTypeExt :: Plain ( VType :: Object ) => Colour :: Cyan . paint ( "object" ) . to_string ( ) ,
57
- VTypeExt :: Plain ( VType :: Typename ( ref v) ) => {
58
- Colour :: Cyan . paint ( v. to_string ( ) ) . to_string ( )
59
- }
52
+ VTypeExt :: Plain ( VType :: Bool ) => "bool" . cyan ( ) . to_string ( ) ,
53
+ VTypeExt :: Plain ( VType :: Int ) => "int" . cyan ( ) . to_string ( ) ,
54
+ VTypeExt :: Plain ( VType :: Float ) => "float" . cyan ( ) . to_string ( ) ,
55
+ VTypeExt :: Plain ( VType :: String ) => "string" . cyan ( ) . to_string ( ) ,
56
+ VTypeExt :: Plain ( VType :: Object ) => "object" . cyan ( ) . to_string ( ) ,
57
+ VTypeExt :: Plain ( VType :: Typename ( ref v) ) => v. to_string ( ) . cyan ( ) . to_string ( ) ,
60
58
VTypeExt :: Plain ( VType :: Struct ( ref v) ) => v. get_oneline_colored ( ) ,
61
59
VTypeExt :: Plain ( VType :: Enum ( ref v) ) => v. get_oneline_colored ( ) ,
62
60
VTypeExt :: Array ( ref v) => format ! ( "[]{}" , v. get_oneline_colored( ) ) ,
63
- VTypeExt :: Dict ( ref v) => format ! (
64
- "[{}]{}" ,
65
- Colour :: Cyan . paint( "string" ) ,
66
- v. get_oneline_colored( )
67
- ) ,
61
+ VTypeExt :: Dict ( ref v) => format ! ( "[{}]{}" , "string" . cyan( ) , v. get_oneline_colored( ) ) ,
68
62
VTypeExt :: Option ( ref v) => format ! ( "?{}" , v. get_oneline_colored( ) ) ,
69
63
}
70
64
}
71
65
fn get_multiline_colored ( & self , indent : usize , max : usize ) -> String {
72
66
match * self {
73
- VTypeExt :: Plain ( VType :: Bool ) => Colour :: Cyan . paint ( "bool" ) . to_string ( ) ,
74
- VTypeExt :: Plain ( VType :: Int ) => Colour :: Cyan . paint ( "int" ) . to_string ( ) ,
75
- VTypeExt :: Plain ( VType :: Float ) => Colour :: Cyan . paint ( "float" ) . to_string ( ) ,
76
- VTypeExt :: Plain ( VType :: String ) => Colour :: Cyan . paint ( "string" ) . to_string ( ) ,
77
- VTypeExt :: Plain ( VType :: Object ) => Colour :: Cyan . paint ( "object" ) . to_string ( ) ,
78
- VTypeExt :: Plain ( VType :: Typename ( ref v) ) => {
79
- Colour :: Cyan . paint ( v. to_string ( ) ) . to_string ( )
80
- }
67
+ VTypeExt :: Plain ( VType :: Bool ) => "bool" . cyan ( ) . to_string ( ) ,
68
+ VTypeExt :: Plain ( VType :: Int ) => "int" . cyan ( ) . to_string ( ) ,
69
+ VTypeExt :: Plain ( VType :: Float ) => "float" . cyan ( ) . to_string ( ) ,
70
+ VTypeExt :: Plain ( VType :: String ) => "string" . cyan ( ) . to_string ( ) ,
71
+ VTypeExt :: Plain ( VType :: Object ) => "object" . cyan ( ) . to_string ( ) ,
72
+ VTypeExt :: Plain ( VType :: Typename ( ref v) ) => v. to_string ( ) . cyan ( ) . to_string ( ) ,
81
73
VTypeExt :: Plain ( VType :: Struct ( ref v) ) => v. get_multiline_colored ( indent, max) ,
82
74
VTypeExt :: Plain ( VType :: Enum ( ref v) ) => v. get_multiline_colored ( indent, max) ,
83
75
VTypeExt :: Array ( ref v) => format ! ( "[]{}" , v. get_multiline_colored( indent, max) ) ,
84
76
VTypeExt :: Dict ( ref v) => format ! (
85
77
"[{}]{}" ,
86
- Colour :: Cyan . paint ( "string" ) ,
78
+ "string" . cyan ( ) ,
87
79
v. get_multiline_colored( indent, max)
88
80
) ,
89
81
VTypeExt :: Option ( ref v) => format ! ( "?{}" , v. get_multiline_colored( indent, max) ) ,
@@ -555,53 +547,53 @@ impl<'a> FormatColored for IDL<'a> {
555
547
let mut f = String :: new ( ) ;
556
548
557
549
if !self . doc . is_empty ( ) {
558
- f += & Colour :: Blue . paint ( self . doc ) ;
550
+ f += & self . doc . blue ( ) ;
559
551
f += "\n " ;
560
552
}
561
- f += & format ! ( "{} {}\n " , Colour :: Purple . paint ( "interface" ) , self . name) ;
553
+ f += & format ! ( "{} {}\n " , "interface" , self . name. purple ( ) ) ;
562
554
563
555
for t in self . typedef_keys . iter ( ) . map ( |k| & self . typedefs [ k] ) {
564
556
f += "\n " ;
565
557
if !t. doc . is_empty ( ) {
566
- f += & Colour :: Blue . paint ( t. doc ) ;
558
+ f += & t. doc . blue ( ) ;
567
559
f += "\n " ;
568
560
}
569
561
570
562
f += & format ! (
571
563
"{} {} {}\n " ,
572
- Colour :: Purple . paint ( "type" ) ,
573
- Colour :: Cyan . paint ( t. name) ,
564
+ "type" . purple ( ) ,
565
+ t. name. cyan ( ) ,
574
566
t. elt. get_oneline_colored( )
575
567
) ;
576
568
}
577
569
578
570
for m in self . method_keys . iter ( ) . map ( |k| & self . methods [ k] ) {
579
571
f += "\n " ;
580
572
if !m. doc . is_empty ( ) {
581
- f += & Colour :: Blue . paint ( m. doc ) ;
573
+ f += & m. doc . blue ( ) ;
582
574
f += "\n " ;
583
575
}
584
576
585
577
f += & format ! (
586
578
"{} {}{} {} {}\n " ,
587
- Colour :: Purple . paint ( "method" ) ,
588
- Colour :: Green . paint ( m. name) ,
579
+ "method" . purple ( ) ,
580
+ m. name. green ( ) ,
589
581
m. input. get_oneline_colored( ) ,
590
- Colour :: Purple . paint ( "->" ) ,
582
+ "->" . purple ( ) ,
591
583
m. output. get_oneline_colored( )
592
584
) ;
593
585
}
594
586
for t in self . error_keys . iter ( ) . map ( |k| & self . errors [ k] ) {
595
587
f += "\n " ;
596
588
if !t. doc . is_empty ( ) {
597
- f += & Colour :: Blue . paint ( t. doc ) ;
589
+ f += & t. doc . blue ( ) ;
598
590
f += "\n " ;
599
591
}
600
592
601
593
f += & format ! (
602
594
"{} {} {}\n " ,
603
- Colour :: Purple . paint ( "error" ) ,
604
- Colour :: Cyan . paint ( t. name) ,
595
+ "error" . purple ( ) ,
596
+ t. name. cyan ( ) ,
605
597
t. parm. get_oneline_colored( )
606
598
) ;
607
599
}
@@ -615,15 +607,15 @@ impl<'a> FormatColored for IDL<'a> {
615
607
f += & self
616
608
. doc
617
609
. split ( '\n' )
618
- . map ( |s| format ! ( "{:indent$}{}" , "" , Colour :: Blue . paint ( s ) , indent = indent) )
610
+ . map ( |s| format ! ( "{:indent$}{}" , "" , s . blue ( ) , indent = indent) )
619
611
. collect :: < Vec < String > > ( )
620
612
. join ( "\n " ) ;
621
613
f += "\n " ;
622
614
}
623
615
f += & format ! (
624
616
"{:indent$}{} {}\n " ,
625
617
"" ,
626
- Colour :: Purple . paint ( "interface" ) ,
618
+ "interface" . purple ( ) ,
627
619
self . name,
628
620
indent = indent
629
621
) ;
@@ -635,7 +627,7 @@ impl<'a> FormatColored for IDL<'a> {
635
627
. doc
636
628
. to_string ( )
637
629
. split ( '\n' )
638
- . map ( |s| format ! ( "{:indent$}{}" , "" , Colour :: Blue . paint ( s ) , indent = indent) )
630
+ . map ( |s| format ! ( "{:indent$}{}" , "" , s . blue ( ) , indent = indent) )
639
631
. collect :: < Vec < String > > ( )
640
632
. join ( "\n " ) ;
641
633
f += "\n " ;
@@ -647,17 +639,17 @@ impl<'a> FormatColored for IDL<'a> {
647
639
f += & format ! (
648
640
"{:indent$}{} {} {}\n " ,
649
641
"" ,
650
- Colour :: Purple . paint ( "type" ) ,
651
- Colour :: Cyan . paint ( t. name) ,
642
+ "type" . purple ( ) ,
643
+ t. name. cyan ( ) ,
652
644
t. elt. get_oneline_colored( ) ,
653
645
indent = indent
654
646
) ;
655
647
} else {
656
648
f += & format ! (
657
649
"{:indent$}{} {} {}\n " ,
658
650
"" ,
659
- Colour :: Purple . paint ( "type" ) ,
660
- Colour :: Cyan . paint ( t. name) ,
651
+ "type" . purple ( ) ,
652
+ t. name. cyan ( ) ,
661
653
t. elt. get_multiline_colored( indent, max) ,
662
654
indent = indent
663
655
) ;
@@ -671,7 +663,7 @@ impl<'a> FormatColored for IDL<'a> {
671
663
. doc
672
664
. to_string ( )
673
665
. split ( '\n' )
674
- . map ( |s| format ! ( "{:indent$}{}" , "" , Colour :: Blue . paint ( s ) , indent = indent) )
666
+ . map ( |s| format ! ( "{:indent$}{}" , "" , s . blue ( ) , indent = indent) )
675
667
. collect :: < Vec < String > > ( )
676
668
. join ( "\n " ) ;
677
669
@@ -687,43 +679,43 @@ impl<'a> FormatColored for IDL<'a> {
687
679
f += & format ! (
688
680
"{:indent$}{} {}{} {} {}\n " ,
689
681
"" ,
690
- Colour :: Purple . paint ( "method" ) ,
691
- Colour :: Green . paint ( m. name) ,
682
+ "method" . purple ( ) ,
683
+ m. name. green ( ) ,
692
684
m. input. get_oneline_colored( ) ,
693
- Colour :: Purple . paint ( "->" ) ,
685
+ "->" . purple ( ) ,
694
686
m. output. get_oneline_colored( ) ,
695
687
indent = indent
696
688
) ;
697
689
} else if ( m_line. len ( ) + m_input. len ( ) + 6 <= max) || ( m_input. len ( ) == 2 ) {
698
690
f += & format ! (
699
691
"{:indent$}{} {}{} {} {}\n " ,
700
692
"" ,
701
- Colour :: Purple . paint ( "method" ) ,
702
- Colour :: Green . paint ( m. name) ,
693
+ "method" . purple ( ) ,
694
+ m. name. green ( ) ,
703
695
m. input. get_oneline_colored( ) ,
704
- Colour :: Purple . paint ( "->" ) ,
696
+ "->" . purple ( ) ,
705
697
m. output. get_multiline_colored( indent, max) ,
706
698
indent = indent
707
699
) ;
708
700
} else if m_output. len ( ) + 7 <= max {
709
701
f += & format ! (
710
702
"{:indent$}{} {}{} {} {}\n " ,
711
703
"" ,
712
- Colour :: Purple . paint ( "method" ) ,
713
- Colour :: Green . paint ( m. name) ,
704
+ "method" . purple ( ) ,
705
+ m. name. green ( ) ,
714
706
m. input. get_multiline_colored( indent, max) ,
715
- Colour :: Purple . paint ( "->" ) ,
707
+ "->" . purple ( ) ,
716
708
m. output. get_oneline_colored( ) ,
717
709
indent = indent
718
710
) ;
719
711
} else {
720
712
f += & format ! (
721
713
"{:indent$}{} {}{} {} {}\n " ,
722
714
"" ,
723
- Colour :: Purple . paint ( "method" ) ,
724
- Colour :: Green . paint ( m. name) ,
715
+ "method" . purple ( ) ,
716
+ m. name. green ( ) ,
725
717
m. input. get_multiline_colored( indent, max) ,
726
- Colour :: Purple . paint ( "->" ) ,
718
+ "->" . purple ( ) ,
727
719
m. output. get_multiline_colored( indent, max) ,
728
720
indent = indent
729
721
) ;
@@ -736,7 +728,7 @@ impl<'a> FormatColored for IDL<'a> {
736
728
. doc
737
729
. to_string ( )
738
730
. split ( '\n' )
739
- . map ( |s| format ! ( "{:indent$}{}" , "" , Colour :: Blue . paint ( s ) , indent = indent) )
731
+ . map ( |s| format ! ( "{:indent$}{}" , "" , s . blue ( ) , indent = indent) )
740
732
. collect :: < Vec < String > > ( )
741
733
. join ( "\n " ) ;
742
734
@@ -749,17 +741,17 @@ impl<'a> FormatColored for IDL<'a> {
749
741
f += & format ! (
750
742
"{:indent$}{} {} {}\n " ,
751
743
"" ,
752
- Colour :: Purple . paint ( "error" ) ,
753
- Colour :: Cyan . paint ( t. name) ,
744
+ "error" . purple ( ) ,
745
+ t. name. cyan ( ) ,
754
746
t. parm. get_oneline_colored( ) ,
755
747
indent = indent
756
748
) ;
757
749
} else {
758
750
f += & format ! (
759
751
"{:indent$}{} {} {}\n " ,
760
752
"" ,
761
- Colour :: Purple . paint ( "error" ) ,
762
- Colour :: Cyan . paint ( t. name) ,
753
+ "error" . purple ( ) ,
754
+ t. name. cyan ( ) ,
763
755
t. parm. get_multiline_colored( indent, max) ,
764
756
indent = indent
765
757
) ;
0 commit comments