Skip to content

Commit

Permalink
some more phpcs cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dvnc0 committed Aug 17, 2023
1 parent 25a6077 commit 45fc985
Show file tree
Hide file tree
Showing 3 changed files with 332 additions and 331 deletions.
2 changes: 1 addition & 1 deletion src/App/Args/Arg_Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function shortName(string $short_name): Arg_Option {
return $this;
}

public function defaultValue(bool $default_value): Arg_Option {
public function defaultValue(string $default_value): Arg_Option {
$this->Option_Object->default_value = $default_value;
return $this;
}
Expand Down
180 changes: 90 additions & 90 deletions src/App/Tasks/Task_Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,106 +8,106 @@

class Task_Runner {

protected Printer $Printer;
protected Application $Application;
protected Event_Dispatcher $Event_Dispatcher;
protected Printer $Printer;
protected Application $Application;
protected Event_Dispatcher $Event_Dispatcher;

/**
* symbols to use for animation
*
* @var array
*/
protected array $symbols = [];
/**
* symbols to use for animation
*
* @var array
*/
protected array $symbols = [];

public function __construct(Application $Application ,$symbols = []){
$this->symbols = $symbols ?: mb_str_split('⢿⣻⣽⣾⣷⣯⣟⡿');
$this->Application = $Application;
$this->Printer = $this->Application->Printer;
$this->Event_Dispatcher = $this->Application->Event_Dispatcher;
}
public function __construct(Application $Application ,$symbols = []){
$this->symbols = $symbols ?: mb_str_split('⢿⣻⣽⣾⣷⣯⣟⡿');
$this->Application = $Application;
$this->Printer = $this->Application->Printer;
$this->Event_Dispatcher = $this->Application->Event_Dispatcher;
}

/**
* Execute the task with inline spinner
*
* @param Task_Base $Task
* @return void
*/
public function run(Task_Base $Task) {
$this->hideCursor();
/**
* Execute the task with inline spinner
*
* @param Task_Base $Task
* @return void
*/
public function run(Task_Base $Task) {
$this->hideCursor();

$pid = pcntl_fork();
$pid = pcntl_fork();

if ($pid === -1) {
die("Could not fork.");
} elseif ($pid === 0) {
$Task->execute();
exit(0);
} else {
$index = 0;
$running = true;
pcntl_signal(SIGTERM, function ($signo) use (&$running) {
$running = false;
});
if ($pid === -1) {
die("Could not fork.");
} elseif ($pid === 0) {
$Task->execute();
exit(0);
} else {
$index = 0;
$running = true;
pcntl_signal(SIGTERM, function ($signo) use (&$running) {
$running = false;
});

pcntl_signal(SIGHUP, function ($signo) use (&$running) {
$running = false;
});
pcntl_signal(SIGHUP, function ($signo) use (&$running) {
$running = false;
});

while ($running) {
$this->overWriteLine();
$symbol = $this->symbols[$index];
$message = $Task->task_message;
$this->write("$message {$symbol}");
$index = ($index === (count($this->symbols) - 1)) ? 0 : $index + 1;
$result = pcntl_waitpid($pid, $status, WNOHANG);
while ($running) {
$this->overWriteLine();
$symbol = $this->symbols[$index];
$message = $Task->task_message;
$this->write("$message {$symbol}");
$index = ($index === (count($this->symbols) - 1)) ? 0 : $index + 1;
$result = pcntl_waitpid($pid, $status, WNOHANG);

if ($result === -1 || $result > 0) {
$running = false;
}
usleep(200000);
}
}
$this->overWriteLine();
$this->Printer->success($Task->task_message . "\n");
$this->showCursor();
}
if ($result === -1 || $result > 0) {
$running = false;
}
usleep(200000);
}
}
$this->overWriteLine();
$this->Printer->success($Task->task_message . "\n");
$this->showCursor();
}

/**
* Write a line to cli
*
* @param string $message
* @return void
*/
protected function write(string $message) {
$this->Printer->warning($message, false);
}
/**
* Write a line to cli
*
* @param string $message
* @return void
*/
protected function write(string $message) {
$this->Printer->warning($message, false);
}

/**
* Over write last printed line
*
* @return void
*/
protected function overWriteLine() {
print("\x0D");
print("\x1B[2K");
}
/**
* Over write last printed line
*
* @return void
*/
protected function overWriteLine() {
print("\x0D");
print("\x1B[2K");
}

/**
* hide the cli cursor
*
* @return void
*/
protected function hideCursor() {
print("\e[?25l");
}
/**
* hide the cli cursor
*
* @return void
*/
protected function hideCursor() {
print("\e[?25l");
}

/**
* show the cli cursor
*
* @return void
*/
protected function showCursor() {
print("\e[?25h");
}
/**
* show the cli cursor
*
* @return void
*/
protected function showCursor() {
print("\e[?25h");
}
}
Loading

0 comments on commit 45fc985

Please sign in to comment.