@@ -3,7 +3,7 @@ mod config;
33use itertools:: Itertools ;
44use modules:: {
55 modules:: ToModule ,
6- outputter:: { self , Outputter } ,
6+ outputter:: { self , Outputter , TmuxOutputter } ,
77 Module , Style ,
88} ;
99use std:: {
@@ -23,17 +23,12 @@ struct CacheEntry<'a> {
2323
2424struct Cache < ' a > ( Vec < CacheEntry < ' a > > ) ;
2525
26- #[ cfg( not( debug_assertions) ) ]
27- const OUTPUTTER : outputter:: TmuxOutputter = outputter:: TmuxOutputter ;
28- #[ cfg( debug_assertions) ]
29- const OUTPUTTER : outputter:: TtyOutputter = outputter:: TtyOutputter ;
30-
3126impl < ' a > Cache < ' a > {
3227 fn new ( entries : Vec < CacheEntry < ' a > > ) -> Self {
3328 Self ( entries)
3429 }
3530
36- fn update ( self ) -> ( Self , bool ) {
31+ fn update ( self , outputter : & Box < dyn Outputter > ) -> ( Self , bool ) {
3732 let now = Instant :: now ( ) ;
3833 let mut rerender = false ;
3934
@@ -55,7 +50,7 @@ impl<'a> Cache<'a> {
5550 . module
5651 . internal_set_mut_style ( entry. module . content . style ( ) ) ;
5752 entry. rerender_interval = entry. module . content . next_render_time ( ) ;
58- entry. cached_str = entry. module . output ( OUTPUTTER ) ;
53+ entry. cached_str = entry. module . output ( outputter ) ;
5954 entry. include = entry. module . content . include ( ) ;
6055 }
6156 entry
@@ -77,12 +72,15 @@ impl From<&Cache<'_>> for String {
7772}
7873
7974fn main ( ) {
75+ let outputter_arg = std:: env:: args ( ) . nth ( 1 ) ;
76+ let outputter = outputter_arg. and_then ( |s| outputter:: new_outputter ( & s) ) . unwrap_or ( Box :: new ( TmuxOutputter ) ) ;
77+
8078 let mods = config:: get_modules ( ) ;
8179 let cached_modules: Vec < _ > = mods
8280 . iter ( )
8381 . map ( |module| {
8482 (
85- module. output ( OUTPUTTER ) ,
83+ module. output ( & outputter ) ,
8684 module. content . next_render_time ( ) ,
8785 module. content . include ( ) ,
8886 )
@@ -109,7 +107,7 @@ fn main() {
109107 loop {
110108 let now = Instant :: now ( ) ;
111109
112- let updated = cache. update ( ) ;
110+ let updated = cache. update ( & outputter ) ;
113111 cache = updated. 0 ;
114112
115113 if updated. 1 || !first_render {
@@ -119,7 +117,7 @@ fn main() {
119117 config:: PRE_MODULES ,
120118 String :: from( & cache) ,
121119 config:: POST_MODULES ,
122- OUTPUTTER . prefix( Style :: default ( ) )
120+ outputter . prefix( Style :: default ( ) )
123121 ) ;
124122 }
125123
0 commit comments