@@ -16,7 +16,7 @@ use std::io::{BufReader, Write};
1616use std:: path:: Path ;
1717use std:: process;
1818
19- use bat:: output:: OutputType ;
19+ use bat:: output:: { OutputHandle , OutputType } ;
2020use bat:: theme:: DetectColorScheme ;
2121use nu_ansi_term:: Color :: Green ;
2222use nu_ansi_term:: Style ;
@@ -206,11 +206,10 @@ pub fn list_themes(
206206 config. language = Some ( "Rust" ) ;
207207 config. style_components = StyleComponents ( style) ;
208208
209- let mut output_type =
210- OutputType :: from_mode ( config. paging_mode , config. wrapping_mode , config. pager ) ?;
211- let mut writer = output_type. handle ( ) ?;
212-
213209 let default_theme_name = default_theme ( color_scheme ( detect_color_scheme) . unwrap_or_default ( ) ) ;
210+ let mut buf = String :: new ( ) ;
211+ let mut handle = OutputHandle :: FmtWrite ( & mut buf) ;
212+
214213 for theme in assets. themes ( ) {
215214 let default_theme_info = if default_theme_name == theme {
216215 " (default)"
@@ -221,35 +220,39 @@ pub fn list_themes(
221220 } else {
222221 ""
223222 } ;
223+
224224 if config. colored_output {
225- writeln ! (
226- writer,
227- "Theme: {}{default_theme_info}\n " ,
225+ handle. write_fmt ( format_args ! (
226+ "{}{default_theme_info}\n \n " ,
228227 Style :: new( ) . bold( ) . paint( theme. to_string( ) ) ,
229- ) ?;
228+ ) ) ?;
230229 config. theme = theme. to_string ( ) ;
231230 Controller :: new ( & config, & assets)
232- . run ( vec ! [ theme_preview_file( ) ] , Some ( & mut writer ) )
231+ . run ( vec ! [ theme_preview_file( ) ] , Some ( & mut handle ) )
233232 . ok ( ) ;
234- writeln ! ( writer ) ?;
233+ handle . write_fmt ( format_args ! ( " \n " ) ) ?;
235234 } else if config. loop_through {
236- writeln ! ( writer , "{theme}" ) ?;
235+ handle . write_fmt ( format_args ! ( "{theme}\n " ) ) ?;
237236 } else {
238- writeln ! ( writer , "{theme}{default_theme_info}" ) ?;
237+ handle . write_fmt ( format_args ! ( "{theme}{default_theme_info}\n " ) ) ?;
239238 }
240239 }
241240
242241 if config. colored_output {
243- writeln ! (
244- writer,
242+ handle. write_fmt ( format_args ! (
245243 "Further themes can be installed to '{}', \
246244 and are added to the cache with `bat cache --build`. \
247245 For more information, see:\n \n \
248246 https://github.com/sharkdp/bat#adding-new-themes",
249247 config_dir. join( "themes" ) . to_string_lossy( )
250- ) ?;
248+ ) ) ?;
251249 }
252250
251+ let mut output_type =
252+ OutputType :: from_mode ( config. paging_mode , config. wrapping_mode , config. pager ) ?;
253+ let mut writer = output_type. handle ( ) ?;
254+ writer. write_fmt ( format_args ! ( "{buf}" ) ) ?;
255+
253256 Ok ( ( ) )
254257}
255258
0 commit comments