@@ -3,7 +3,7 @@ use anyhow::Result;
33use chrono:: { Datelike , Duration , Local , NaiveDate } ;
44use inquire:: DateSelect ;
55use regex:: Regex ;
6- use std:: { fmt, io :: Write } ;
6+ use std:: fmt;
77use yansi:: { Paint , Style } ;
88
99static STYLE_START : Style = Style :: new ( ) . cyan ( ) ;
@@ -28,7 +28,7 @@ impl Entry {
2828 "{} {} {}" ,
2929 self . timestamp_formatted( ) . rgb( 244 , 9 , 84 ) ,
3030 ":" . dim( ) ,
31- style_entry ( & self . message , config) ?
31+ self . style_message ( config) ?
3232 ) ?;
3333 if let Some ( ref long_message) = self . long {
3434 if long {
@@ -39,6 +39,22 @@ impl Entry {
3939 }
4040 Ok ( ( ) )
4141 }
42+
43+ pub fn message_matches ( & self , rx : & str ) -> Result < bool > {
44+ Ok ( Regex :: new ( rx) ?. is_match ( & self . message ) )
45+ }
46+
47+ fn style_message < ' a > ( & ' a self , config : & Config ) -> Result < Box < dyn fmt:: Display + ' a > > {
48+ Ok ( if self . message_matches ( & config. start_regex ) ? {
49+ Box :: new ( self . message . paint ( STYLE_START ) )
50+ } else if self . message_matches ( & config. pause_regex ) ? {
51+ Box :: new ( self . message . paint ( STYLE_PAUSE ) )
52+ } else if self . message_matches ( & config. end_regex ) ? {
53+ Box :: new ( self . message . paint ( STYLE_END ) )
54+ } else {
55+ Box :: new ( & self . message )
56+ } )
57+ }
4258}
4359
4460fn format_long ( long : & str ) -> String {
@@ -50,18 +66,6 @@ fn format_long(long: &str) -> String {
5066 str
5167}
5268
53- fn style_entry < ' a > ( v : & ' a str , config : & Config ) -> Result < Box < dyn fmt:: Display + ' a > > {
54- Ok ( if Regex :: new ( & config. start_regex ) ?. is_match ( v) {
55- Box :: new ( v. paint ( STYLE_START ) )
56- } else if Regex :: new ( & config. pause_regex ) ?. is_match ( v) {
57- Box :: new ( v. paint ( STYLE_PAUSE ) )
58- } else if Regex :: new ( & config. end_regex ) ?. is_match ( v) {
59- Box :: new ( v. paint ( STYLE_END ) )
60- } else {
61- Box :: new ( v)
62- } )
63- }
64-
6569pub fn parse_date ( date : & str ) -> Result < NaiveDate > {
6670 let today = Local :: now ( ) . date_naive ( ) ;
6771
@@ -106,7 +110,7 @@ impl<'a> FormatableEntry<'a> {
106110 }
107111}
108112
109- impl < ' a > fmt:: Display for FormatableEntry < ' a > {
113+ impl fmt:: Display for FormatableEntry < ' _ > {
110114 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
111115 self . entry
112116 . format ( f, self . config , self . long )
0 commit comments