@@ -4,6 +4,8 @@ mod store;
44use std:: error:: Error ;
55use std:: io:: { self , Write } ;
66
7+ use chrono:: prelude:: * ;
8+
79use store:: Timelog ;
810
911enum TimeMode {
@@ -34,24 +36,41 @@ Any other input is the description of a task that you just finished."
3436 ) ;
3537}
3638
37- fn show_today ( timelog : & Timelog ) {
38- println ! ( "Work done today:" ) ;
39- let a = activity:: Activities :: new_from_entries ( timelog. get_today ( ) ) ;
40- println ! ( "{}" , a) ;
41- }
39+ fn show ( timelog : & Timelog , mode : & TimeMode ) {
40+ clear_screen ( ) ;
41+ let entries = match mode {
42+ TimeMode :: Day => {
43+ println ! ( "Work done today:" ) ;
44+ timelog. get_today ( )
45+ }
46+ TimeMode :: Week => {
47+ println ! ( "Work done this week:" ) ;
48+ timelog. get_this_week ( )
49+ }
50+ } ;
4251
43- fn show_week ( timelog : & Timelog ) {
44- println ! ( "Work done this week:" ) ;
45- let a = activity:: Activities :: new_from_entries ( timelog. get_this_week ( ) ) ;
52+ let a = activity:: Activities :: new_from_entries ( entries) ;
4653 println ! ( "{}" , a) ;
4754}
4855
49- fn show ( timelog : & Timelog , mode : & TimeMode ) {
50- clear_screen ( ) ;
51- match mode {
52- TimeMode :: Day => show_today ( timelog) ,
53- TimeMode :: Week => show_week ( timelog) ,
54- }
56+ fn show_prompt ( timelog : & Timelog ) -> Result < ( ) , io:: Error > {
57+ let since_last = timelog
58+ . get_today ( )
59+ . last ( )
60+ . map ( |e| Local :: now ( ) . naive_local ( ) . signed_duration_since ( e. stop ) ) ;
61+
62+ let since_str = match since_last {
63+ None => "no entries yet today" . to_string ( ) ,
64+ Some ( d) => format ! (
65+ "{} h {} min since last entry" ,
66+ d. num_hours( ) ,
67+ d. num_minutes( ) % 60
68+ ) ,
69+ } ;
70+
71+ print ! ( "\n {}; type command (:h for help) or entry\n > " , since_str) ;
72+ io:: stdout ( ) . flush ( ) ?;
73+ Ok ( ( ) )
5574}
5675
5776fn main ( ) -> Result < ( ) , Box < dyn Error > > {
@@ -62,8 +81,7 @@ fn main() -> Result<(), Box<dyn Error>> {
6281 show ( & timelog, & time_mode) ;
6382
6483 while running {
65- print ! ( "\n command (:h for help) or entry: " ) ;
66- io:: stdout ( ) . flush ( ) ?;
84+ show_prompt ( & timelog) ?;
6785 let input = stdin_line ( ) ?;
6886 match input. as_str ( ) {
6987 ":q" => running = false ,
0 commit comments