Skip to content
This repository was archived by the owner on Mar 30, 2024. It is now read-only.

Commit 462d550

Browse files
committed
Fix #4
1 parent fe12783 commit 462d550

File tree

5 files changed

+86
-26
lines changed

5 files changed

+86
-26
lines changed

core/CLI.php

Lines changed: 72 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
class 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

core/CLIParser.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ class CLIParser {
55
private bool $empty = true;
66

77
const TASK_VERSION = 'v', TASK_HELP = 'h', TASK_STATS = 's',
8-
TASK_SETTINGS = 'p', TASK_RECORD = 'r', TASK_PAUSE = 'e';
8+
TASK_SETTINGS = 'p', TASK_RECORD = 'r', TASK_PAUSE = 'e',
9+
TASK_OVERVIEW = 'o';
910
private $tasks = array(
1011
'v' => array('version', 'v'),
1112
'h' => array('help', 'h'),
1213
's' => array('stats', 's'),
1314
'p' => array('settings', 'preferences', 'p', 'conf', 'c'),
1415
'r' => array('record', 'r', 'change', 'new'),
15-
'e' => array('end', 'begin', 'pause', 'stop', 'e', 'start', 't', 'toggle')
16+
'e' => array('end', 'begin', 'pause', 'stop', 'e', 'start', 't', 'toggle'),
17+
'o' => array('overview', 'o')
1618
);
1719

1820
public function __construct(int $argc, array $argv) {
@@ -49,7 +51,8 @@ public function getTaskParams() : array {
4951
's' => 'Show statistic of collected data',
5052
'p' => 'Edit settings of program, e.g. categories',
5153
'r' => 'Start a new task now, will stop the current and open task dialog',
52-
'e' => 'Switch the program status, between enabled [collect data, ask for tasks] and disabled [dont do anything]'
54+
'e' => 'Switch the program status, between enabled [collect data, ask for tasks] and disabled [do nothing]',
55+
'o' => 'Get an overview about current task and program status'
5356
);
5457
$o = array();
5558
foreach( $this->tasks as $key => $task ){

core/Config.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@ public static function getStorageDir() : string {
7676
return self::$instance->savedir;
7777
}
7878

79-
public static function getRecordStatus() : bool {
79+
public static function getRecordStatus(bool $useManager = true) : bool {
8080
$c = self::getStorageReader('config');
81-
ReaderManager::addReader($c);
81+
if( $useManager ){
82+
ReaderManager::addReader($c);
83+
}
8284
if( !self::$statusSetup && !$c->isValue(['status']) ){
8385
$s->setValue(['status'], true);
8486
self::$statusSetup = true;

core/Stats.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private function printDataset(array $data) : void {
115115
);
116116

117117
foreach( $table as &$d ){
118-
$d['Time'] = $this->secToTime($d['Time']);
118+
$d['Time'] = self::secToTime($d['Time']);
119119
}
120120

121121
$this->output->table($table);
@@ -125,7 +125,7 @@ private function printDataset(array $data) : void {
125125
}
126126
}
127127

128-
private function secToTime(int $t) : string {
128+
public static function secToTime(int $t) : string {
129129
return str_pad(
130130
($t >= 3600 ? intval($t/3600) . 'h ' : '' ) .
131131
str_pad(
@@ -165,7 +165,7 @@ private function printTodayView(array $data) : void {
165165
}
166166

167167
foreach( $table as &$d ){
168-
$d['Time'] = $this->secToTime($d['Time']);
168+
$d['Time'] = self::secToTime($d['Time']);
169169
}
170170

171171
$this->output->table($table);

core/Utilities.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
class Utilities {
66

7-
const VERSION = 'v0.8.3 alpha';
7+
const VERSION = 'v0.8.5 alpha';
88

99
/**
1010
* OS Consts

0 commit comments

Comments
 (0)