@@ -15,41 +15,104 @@ fn paint_text(text_style: Style, text: &str, addendum: &str) -> String {
1515 }
1616}
1717
18- pub type DrawFunction = dyn FnMut (
19- & mut dyn Write ,
20- & str ,
21- & str ,
22- & str ,
23- & Width ,
24- Style ,
25- ansi_term:: Style ,
26- ) -> std:: io:: Result < ( ) > ;
18+ pub type DrawFunction =
19+ dyn Fn ( & mut dyn Write , & str , & str , & str , & Width , Style , bool ) -> std:: io:: Result < ( ) > ;
2720
28- pub fn get_draw_function (
29- decoration_style : DecorationStyle ,
30- ) -> ( Box < DrawFunction > , bool , ansi_term:: Style ) {
31- match decoration_style {
32- DecorationStyle :: Box ( style) => ( Box :: new ( write_boxed) , true , style) ,
33- DecorationStyle :: BoxWithUnderline ( style) => {
34- ( Box :: new ( write_boxed_with_underline) , true , style)
35- }
36- DecorationStyle :: BoxWithOverline ( style) => {
37- // TODO: not implemented
38- ( Box :: new ( write_boxed) , true , style)
39- }
40- DecorationStyle :: BoxWithUnderOverline ( style) => {
41- // TODO: not implemented
42- ( Box :: new ( write_boxed) , true , style)
43- }
44- DecorationStyle :: Underline ( style) => ( Box :: new ( write_underlined) , false , style) ,
45- DecorationStyle :: Overline ( style) => ( Box :: new ( write_overlined) , false , style) ,
46- DecorationStyle :: UnderOverline ( style) => ( Box :: new ( write_underoverlined) , false , style) ,
47- DecorationStyle :: NoDecoration => (
48- Box :: new ( write_no_decoration) ,
49- false ,
50- ansi_term:: Style :: new ( ) ,
51- ) ,
52- }
21+ pub fn get_draw_function ( decoration_style : DecorationStyle ) -> Box < DrawFunction > {
22+ Box :: new (
23+ move |writer, text, raw_text, addendum, line_width, text_style, never_pad| {
24+ match decoration_style {
25+ DecorationStyle :: Box ( style) => {
26+ if never_pad {
27+ write_boxed (
28+ writer, text, raw_text, addendum, line_width, text_style, style,
29+ )
30+ } else {
31+ write_boxed (
32+ writer,
33+ & format ! ( "{text} " ) ,
34+ & format ! ( "{raw_text} " ) ,
35+ addendum,
36+ line_width,
37+ text_style,
38+ style,
39+ )
40+ }
41+ }
42+ DecorationStyle :: BoxWithUnderline ( style) => {
43+ if never_pad {
44+ write_boxed_with_underline (
45+ writer, text, raw_text, addendum, line_width, text_style, style,
46+ )
47+ } else {
48+ write_boxed_with_underline (
49+ writer,
50+ & format ! ( "{text} " ) ,
51+ & format ! ( "{raw_text} " ) ,
52+ addendum,
53+ line_width,
54+ text_style,
55+ style,
56+ )
57+ }
58+ }
59+ // TODO: not implemented
60+ DecorationStyle :: BoxWithOverline ( style) => {
61+ if never_pad {
62+ write_boxed_with_underline (
63+ writer, text, raw_text, addendum, line_width, text_style, style,
64+ )
65+ } else {
66+ write_boxed_with_underline (
67+ writer,
68+ & format ! ( "{text} " ) ,
69+ & format ! ( "{raw_text} " ) ,
70+ addendum,
71+ line_width,
72+ text_style,
73+ style,
74+ )
75+ }
76+ }
77+ // TODO: not implemented
78+ DecorationStyle :: BoxWithUnderOverline ( style) => {
79+ if never_pad {
80+ write_boxed_with_underline (
81+ writer, text, raw_text, addendum, line_width, text_style, style,
82+ )
83+ } else {
84+ write_boxed_with_underline (
85+ writer,
86+ & format ! ( "{text} " ) ,
87+ & format ! ( "{raw_text} " ) ,
88+ addendum,
89+ line_width,
90+ text_style,
91+ style,
92+ )
93+ }
94+ }
95+ DecorationStyle :: Underline ( style) => write_underlined (
96+ writer, text, raw_text, addendum, line_width, text_style, style,
97+ ) ,
98+ DecorationStyle :: Overline ( style) => write_overlined (
99+ writer, text, raw_text, addendum, line_width, text_style, style,
100+ ) ,
101+ DecorationStyle :: UnderOverline ( style) => write_underoverlined (
102+ writer, text, raw_text, addendum, line_width, text_style, style,
103+ ) ,
104+ DecorationStyle :: NoDecoration => write_no_decoration (
105+ writer,
106+ text,
107+ raw_text,
108+ addendum,
109+ line_width,
110+ text_style,
111+ ansi_term:: Style :: new ( ) ,
112+ ) ,
113+ }
114+ } ,
115+ )
53116}
54117
55118fn write_no_decoration (
0 commit comments