modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2023-12-26 20:01:41 +04:00
parent 7fb34f0276
commit ad88b16a32
2 changed files with 33 additions and 18 deletions

View File

@ -5,6 +5,8 @@ use Exception;
use nulib\cl; use nulib\cl;
class Console implements IMessenger { class Console implements IMessenger {
const INDENT = " ";
const VALID_LEVELS = [ const VALID_LEVELS = [
self::LEVEL_DEBUG, self::LEVEL_DEBUG,
self::LEVEL_NORMAL, self::LEVEL_NORMAL,
@ -70,10 +72,12 @@ class Console implements IMessenger {
$this->out = new StdOutput(STDOUT); $this->out = new StdOutput(STDOUT);
$this->err = new StdOutput(STDERR); $this->err = new StdOutput(STDERR);
$this->minLevel = intval($minLevel); $this->minLevel = intval($minLevel);
$this->pending = []; $this->indent = static::INDENT;
$this->inSection = false; $this->inSection = false;
$this->titles = null; $this->titles = null;
$this->currentTitle = null;
$this->actions = null; $this->actions = null;
$this->currentAction = null;
} }
/** @var StdOutput la sortie standard */ /** @var StdOutput la sortie standard */
@ -85,6 +89,9 @@ class Console implements IMessenger {
/** @var int level minimum que doivent avoir les messages pour être affichés */ /** @var int level minimum que doivent avoir les messages pour être affichés */
protected $minLevel; protected $minLevel;
/** @var string valeur unitaire de l'indentation */
protected $indent;
/** @var bool est-on dans une section? */ /** @var bool est-on dans une section? */
protected $inSection; protected $inSection;
@ -139,16 +146,11 @@ class Console implements IMessenger {
if ($this->titles) { if ($this->titles) {
$this->currentTitle =& $this->titles[count($this->titles) - 1]; $this->currentTitle =& $this->titles[count($this->titles) - 1];
} else { } else {
$this->titles = null;
unset($this->currentTitle); unset($this->currentTitle);
} }
} }
function print($content, int $level=self::LEVEL_NORMAL): void {
if ($level < $this->minLevel) return;
$this->printTitles();
$this->out->print($content);
}
/** @var array */ /** @var array */
protected $actions; protected $actions;
@ -158,9 +160,11 @@ class Console implements IMessenger {
function action($content, int $level=self::LEVEL_NORMAL): void { function action($content, int $level=self::LEVEL_NORMAL): void {
$this->actions[] = [ $this->actions[] = [
"level" => $level, "level" => $level,
"contents" => [$content], "content" => $content,
"print_content" => true,
"success" => null,
"result" => null, "result" => null,
"print" => true, "print_result" => true,
]; ];
$this->currentAction =& $this->actions[count($this->actions) - 1]; $this->currentAction =& $this->actions[count($this->actions) - 1];
} }
@ -171,26 +175,30 @@ class Console implements IMessenger {
} }
function step($content): void { function step($content): void {
if (!$this->actions) $this->action(null);
$this->printActions(); $this->printActions();
} }
function success($content=null): void { function success($content=null): void {
$this->currentAction["contents"][] = $content; if (!$this->actions) $this->action(null);
$this->currentAction["result"] = true; $this->currentAction["success"] = true;
$this->currentAction["result"] = $content;
$this->printActions(); $this->printActions();
$this->endAction(); $this->endAction();
} }
function failure($content=null): void { function failure($content=null): void {
$this->currentAction["contents"][] = $content; if (!$this->actions) $this->action(null);
$this->currentAction["result"] = false; $this->currentAction["success"] = false;
$this->currentAction["result"] = $content;
$this->printActions(); $this->printActions();
$this->endAction(); $this->endAction();
} }
function neutral($content=null): void { function neutral($content=null): void {
$this->currentAction["contents"][] = $content; if (!$this->actions) $this->action(null);
$this->currentAction["result"] = null; $this->currentAction["success"] = null;
$this->currentAction["result"] = $content;
$this->printActions(); $this->printActions();
$this->endAction(); $this->endAction();
} }
@ -200,10 +208,17 @@ class Console implements IMessenger {
if ($this->actions) { if ($this->actions) {
$this->currentAction =& $this->actions[count($this->actions) - 1]; $this->currentAction =& $this->actions[count($this->actions) - 1];
} else { } else {
$this->actions = null;
unset($this->currentAction); unset($this->currentAction);
} }
} }
function print($content, int $level=self::LEVEL_NORMAL): void {
if ($level < $this->minLevel) return;
$this->printActions();
$this->out->print($content);
}
function info($content, int $level=self::LEVEL_NORMAL): void { function info($content, int $level=self::LEVEL_NORMAL): void {
if ($level < $this->minLevel) return; if ($level < $this->minLevel) return;
$this->printActions(); $this->printActions();

View File

@ -26,9 +26,6 @@ interface IMessenger {
/** ajouter une description au chapitre courant. */ /** ajouter une description au chapitre courant. */
function desc($content, int $level=self::LEVEL_NORMAL): void; function desc($content, int $level=self::LEVEL_NORMAL): void;
/** afficher une donnée non structurée dans la chapitre courant */
function print($content, int $level=self::LEVEL_NORMAL): void;
/** /**
* comencer une action dans le chapitre courant. * comencer une action dans le chapitre courant.
* *
@ -64,6 +61,9 @@ interface IMessenger {
*/ */
function neutral($content=null): void; function neutral($content=null): void;
/** afficher une donnée non structurée */
function print($content, int $level=self::LEVEL_NORMAL): void;
/** ajouter un événément "information" */ /** ajouter un événément "information" */
function info($content, int $level=self::LEVEL_NORMAL): void; function info($content, int $level=self::LEVEL_NORMAL): void;