1616use std:: borrow:: Cow ;
1717use std:: fmt:: { Display , Write } ;
1818
19- use nu_ansi_term:: { Color , Style } ;
20-
2119use crate :: matcher_support:: edit_distance;
2220
2321/// Environment variable controlling the usage of ansi color in difference
@@ -154,26 +152,32 @@ fn compress_common_lines(common_lines: Vec<&str>) -> String {
154152 truncated_lines
155153}
156154
155+ // See
157156struct LineStyle {
158- ansi : Style ,
157+ ansi_prefix : & ' static str ,
158+ ansi_suffix : & ' static str ,
159159 header : char ,
160160}
161161
162162impl LineStyle {
163+ // Font in red and bold
163164 fn extra_actual_style ( ) -> Self {
164- Self { ansi : Style :: new ( ) . fg ( Color :: Red ) . bold ( ) , header : '-' }
165+ Self { ansi_prefix : " \x1B [1;31m" , ansi_suffix : " \x1B [0m" , header : '-' }
165166 }
166167
168+ // Font in green and bold
167169 fn extra_expected_style ( ) -> Self {
168- Self { ansi : Style :: new ( ) . fg ( Color :: Green ) . bold ( ) , header : '+' }
170+ Self { ansi_prefix : " \x1B [1;32m" , ansi_suffix : " \x1B [0m" , header : '+' }
169171 }
170172
173+ // Font in italic
171174 fn comment_style ( ) -> Self {
172- Self { ansi : Style :: new ( ) . italic ( ) , header : ' ' }
175+ Self { ansi_prefix : " \x1B [3m" , ansi_suffix : " \x1B [0m" , header : ' ' }
173176 }
174177
178+ // No ansi styling
175179 fn unchanged_style ( ) -> Self {
176- Self { ansi : Style :: new ( ) , header : ' ' }
180+ Self { ansi_prefix : "" , ansi_suffix : "" , header : ' ' }
177181 }
178182
179183 fn style ( self , line : & str ) -> StyledLine < ' _ > {
@@ -192,10 +196,7 @@ impl<'a> Display for StyledLine<'a> {
192196 write ! (
193197 f,
194198 "{}{}{}{}" ,
195- self . style. header,
196- self . style. ansi. prefix( ) ,
197- self . line,
198- self . style. ansi. suffix( )
199+ self . style. header, self . style. ansi_prefix, self . line, self . style. ansi_suffix
199200 )
200201 } else {
201202 write ! ( f, "{}{}" , self . style. header, self . line)
0 commit comments