11<?php
22class CLI {
33
4+ const OVERVIEW_TIME = 'd.m. H:i ' ;
5+
46 private CLIParser $ parser ;
57 private CLIOutput $ output ;
68
@@ -14,33 +16,22 @@ public function checkTask(){
1416 case CLIParser::TASK_VERSION :
1517 $ this ->version ();
1618 break ;
17- case CLIParser::TASK_HELP :
18- $ this ->help ();
19- break ;
2019 case CLIParser::TASK_STATS :
2120 new Stats ($ this ->parser , $ this ->output );
2221 break ;
2322 case CLIParser::TASK_SETTINGS :
2423 new Settings ($ this ->parser , $ this ->output );
2524 break ;
2625 case CLIParser::TASK_RECORD :
27- if ( isset ($ this ->parser ->getCommands ()[0 ]) && $ this ->parser ->getCommands ()[0 ] == 'inTerminalDialog ' ){
28- (new Recorder (true ))->record ();
29- }
30- else {
31- $ this ->output ->print (array (
32- 'Force new record ' ,
33- array ('Add command ' . CLIOutput::colorString ('inTerminalDialog ' , CLIOutput::BLUE ) . ' to do a normal record using the InTerminalDialog. ' )
34- ));
35- (new Recorder ())->record (true );
36- if ( Config::getStorageReader ('config ' )->isValue (['status ' ]) && !Config::getStorageReader ('config ' )->getValue (['status ' ]) ){
37- $ this ->togglePause (); // make sure to enable
38- }
39- }
26+ $ this ->record ();
27+ break ;
28+ case CLIParser::TASK_OVERVIEW :
29+ $ this ->overview ();
4030 break ;
4131 case CLIParser::TASK_PAUSE :
4232 $ this ->togglePause ();
4333 break ;
34+ case CLIParser::TASK_HELP :
4435 default :
4536 $ this ->help ();
4637 break ;
@@ -59,6 +50,70 @@ private function help(){
5950
6051 }
6152
53+ private function record (){
54+ if ( isset ($ this ->parser ->getCommands ()[0 ]) && $ this ->parser ->getCommands ()[0 ] == 'inTerminalDialog ' ){
55+ (new Recorder (true ))->record ();
56+ }
57+ else {
58+ $ this ->output ->print (array (
59+ 'Force new record ' ,
60+ array ('Add command ' . CLIOutput::colorString ('inTerminalDialog ' , CLIOutput::BLUE ) . ' to do a normal record using the InTerminalDialog. ' )
61+ ));
62+ (new Recorder ())->record (true );
63+ if ( !Config::getRecordStatus (false ) ){
64+ $ this ->togglePause (); // make sure to enable
65+ }
66+ }
67+ }
68+
69+ private function overview (){
70+ $ enabled = Config::getRecordStatus (false );
71+ $ current = Config::getStorageReader ('current ' );
72+ $ this ->output ->print (array (
73+ 'Overview ' ,
74+ array (
75+ 'TaskTimeTerminate is ' . ( $ enabled ?
76+ CLIOutput::colorString ( 'enabled ' , CLIOutput::GREEN ) : CLIOutput::colorString ( 'disabled ' , CLIOutput::RED )
77+ ) . '! '
78+ )
79+ ));
80+ $ this ->output ->print (array ('' ));
81+ if ( $ enabled ){
82+ if ( $ current ->getValue (['end ' ]) !== -1 ){
83+ $ this ->output ->print (array (
84+ 'Your current Task: '
85+ ), CLIOutput::BLUE );
86+ $ this ->output ->table (array (
87+ array (
88+ '' => 'Category ' ,
89+ 'Value ' => $ current ->getValue (['category ' ])
90+ ),
91+ array (
92+ '' => 'Name ' ,
93+ 'Value ' => $ current ->getValue (['name ' ])
94+ ),
95+ array (
96+ '' => 'Started ' ,
97+ 'Value ' => date ( self ::OVERVIEW_TIME , $ current ->getValue (['begin ' ]))
98+ ),
99+ array (
100+ '' => 'Planned end ' ,
101+ 'Value ' => date ( self ::OVERVIEW_TIME , $ current ->getValue (['end ' ]))
102+ ),
103+ array (
104+ '' => 'Worked until now ' ,
105+ 'Value ' => Stats::secToTime ($ current ->getValue (['lastopend ' ]) - $ current ->getValue (['begin ' ]))
106+ )
107+ ));
108+ }
109+ else {
110+ $ this ->output ->print (array (
111+ 'Currently you have a break. '
112+ ), CLIOutput::YELLOW , 1 );
113+ }
114+ }
115+ }
116+
62117 private function version (){
63118 $ this ->output ->print (array (
64119 'Version ' ,
@@ -76,8 +131,8 @@ private function version(){
76131 }
77132
78133 private function togglePause (){
134+ $ enabled = Config::getRecordStatus (false );
79135 $ c = Config::getStorageReader ('config ' );
80- $ enabled = !$ c ->isValue (['status ' ]) ? true : $ c ->getValue (['status ' ]);
81136 $ c ->setValue (['status ' ], !$ enabled );
82137
83138 if ( $ enabled ){ // not enabled
0 commit comments