diff --git a/CHANGELOG.md b/CHANGELOG.md index dee16cd..338714f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v0.10.5 (2024-08-21) +* Converted consts to protected PascalCase +* Updated Veneer dependency and Stub +* Removed unneeded LazyLoad binding attribute +* Updated dependency versions + ## v0.10.4 (2024-07-17) * Updated Veneer dependency diff --git a/composer.json b/composer.json index 740ec1f..4258e21 100644 --- a/composer.json +++ b/composer.json @@ -11,13 +11,13 @@ "require": { "php": "^8.1", - "decodelabs/archetype": "^0.2|^0.3", + "decodelabs/archetype": "^0.3", "decodelabs/coercion": "^0.2", "decodelabs/deliverance": "^0.2", "decodelabs/exceptional": "^0.4", "decodelabs/glitch-support": "^0.4", "decodelabs/tightrope": "^0.1.1", - "decodelabs/veneer": "^0.11.1", + "decodelabs/veneer": "^0.11.6", "psr/log": "^3" }, diff --git a/src/Context.php b/src/Context.php index 5d2599f..a9b10b7 100644 --- a/src/Context.php +++ b/src/Context.php @@ -22,7 +22,6 @@ /** * @mixin Session */ -#[LazyLoad] class Context { #[Plugin(Command::class)] diff --git a/src/Io/Style.php b/src/Io/Style.php index 87172bf..c7023ba 100644 --- a/src/Io/Style.php +++ b/src/Io/Style.php @@ -14,7 +14,7 @@ class Style { - public const FG_COLORS = [ + protected const FgColors = [ 'black' => 30, 'red' => 31, 'green' => 32, @@ -35,7 +35,7 @@ class Style 'brightWhite' => 97 ]; - public const BG_COLORS = [ + protected const BgColors = [ 'black' => 40, 'red' => 41, 'green' => 42, @@ -56,7 +56,7 @@ class Style 'brightWhite' => 107 ]; - public const OPTIONS = [ + protected const Options = [ 'bold' => [1, 22], 'dim' => [2, 22], 'italic' => [3, 23], @@ -91,8 +91,8 @@ public static function isKeyword( string $string ): bool { return - isset(self::FG_COLORS[$string]) || - isset(self::OPTIONS[$string]); + isset(self::FgColors[$string]) || + isset(self::Options[$string]); } /** @@ -120,13 +120,13 @@ public static function parse( $testPart = '_select'; } - if (isset(self::FG_COLORS[$testPart])) { + if (isset(self::FgColors[$testPart])) { if (!$fg) { $fg = $part; } elseif (!$bg) { $bg = $part; } - } elseif (isset(self::OPTIONS[$testPart])) { + } elseif (isset(self::Options[$testPart])) { $options[] = $part; } elseif (!empty($part)) { throw Exceptional::InvalidArgument( @@ -203,7 +203,7 @@ public function setForeground( $bits = 24; $foreground = $this->hexToRgb($colorMatches[3]); } - } elseif (!isset(self::FG_COLORS[$foreground])) { + } elseif (!isset(self::FgColors[$foreground])) { throw Exceptional::InvalidArgument( 'Invalid foreground color: ' . $foreground ); @@ -253,7 +253,7 @@ public function setBackground( $bits = 24; $background = $this->hexToRgb($colorMatches[3]); } - } elseif (!isset(self::FG_COLORS[$background])) { + } elseif (!isset(self::FgColors[$background])) { throw Exceptional::InvalidArgument( 'Invalid background color: ' . $background ); @@ -326,7 +326,7 @@ public function setOptions( continue; } - if (!isset(self::OPTIONS[$option])) { + if (!isset(self::Options[$option])) { throw Exceptional::InvalidArgument( 'Invalid option: ' . $option ); @@ -511,42 +511,42 @@ protected function format( if ($this->foreground !== null) { switch ($this->foregroundBits) { case 4: - $setCodes[] = static::FG_COLORS[$this->foreground]; + $setCodes[] = static::FgColors[$this->foreground]; break; case 8: - $setCodes[] = static::FG_COLORS['_select'] . ';5;' . $this->foreground; + $setCodes[] = static::FgColors['_select'] . ';5;' . $this->foreground; break; case 24: - $setCodes[] = static::FG_COLORS['_select'] . ';2;' . str_replace(',', ';', $this->foreground); + $setCodes[] = static::FgColors['_select'] . ';2;' . str_replace(',', ';', $this->foreground); break; } - $unsetCodes[] = static::FG_COLORS['reset']; + $unsetCodes[] = static::FgColors['reset']; } if ($this->background !== null) { switch ($this->backgroundBits) { case 4: - $setCodes[] = static::BG_COLORS[$this->background]; + $setCodes[] = static::BgColors[$this->background]; break; case 8: - $setCodes[] = static::BG_COLORS['_select'] . ';5;' . $this->background; + $setCodes[] = static::BgColors['_select'] . ';5;' . $this->background; break; case 24: - $setCodes[] = static::BG_COLORS['_select'] . ';2;' . str_replace(',', ';', $this->background); + $setCodes[] = static::BgColors['_select'] . ';2;' . str_replace(',', ';', $this->background); break; } - $unsetCodes[] = static::BG_COLORS['reset']; + $unsetCodes[] = static::BgColors['reset']; } foreach ($this->options as $option) { - $setCodes[] = static::OPTIONS[$option][0]; - $unsetCodes[] = static::OPTIONS[$option][1]; + $setCodes[] = static::Options[$option][0]; + $unsetCodes[] = static::Options[$option][1]; } return sprintf("\e[%sm%s\e[%sm", implode(';', $setCodes), $message, implode(';', $unsetCodes)); diff --git a/src/Session.php b/src/Session.php index c517da1..61e5cae 100644 --- a/src/Session.php +++ b/src/Session.php @@ -1159,7 +1159,7 @@ public static function stringToBoolean( - public const LOG_STYLES = [ + protected const LogStyles = [ 'debug' => ['β ', '#996300'], // @ignore-non-ascii 'info' => ['ℹ ', 'cyan'], // @ignore-non-ascii 'notice' => ['☛ ', 'cyan|bold'], // @ignore-non-ascii @@ -1347,12 +1347,12 @@ public function log( ): void { $message = $this->interpolate((string)$message, $context); - if (!isset(self::LOG_STYLES[$level])) { + if (!isset(self::LogStyles[$level])) { $this->writeLine($message); return; } - [$prefix, $style] = self::LOG_STYLES[$level]; + [$prefix, $style] = self::LogStyles[$level]; $message = $prefix . $message; $this->style('.' . $style, $message); @@ -1368,12 +1368,12 @@ public function inlineLog( ): void { $message = $this->interpolate((string)$message, $context); - if (!isset(self::LOG_STYLES[$level])) { + if (!isset(self::LogStyles[$level])) { $this->writeLine($message); return; } - [$prefix, $style] = self::LOG_STYLES[$level]; + [$prefix, $style] = self::LogStyles[$level]; $message = $prefix . $message; $this->style($style, $message); diff --git a/src/Widget/ProgressBar.php b/src/Widget/ProgressBar.php index 6e75621..7469911 100644 --- a/src/Widget/ProgressBar.php +++ b/src/Widget/ProgressBar.php @@ -13,8 +13,8 @@ class ProgressBar { - public const EMPTY = '░'; // @ignore-non-ascii - public const FULL = '▓'; // @ignore-non-ascii + protected const Empty = '░'; // @ignore-non-ascii + protected const Full = '▓'; // @ignore-non-ascii protected float $min = 0; protected float $max = 100; @@ -279,8 +279,8 @@ public function advance( $this->session->style('brightWhite', $maxVal . ' '); } - $this->session->style($color, str_repeat(self::FULL, (int)$chars)); - $this->session->style('dim', str_repeat(self::EMPTY, (int)($barSize - $chars))); + $this->session->style($color, str_repeat(self::Full, (int)$chars)); + $this->session->style('dim', str_repeat(self::Empty, (int)($barSize - $chars))); if ($this->showPercent) { $this->session->style('white|bold', str_pad(ceil($percent * 100) . '%', 5, ' ', STR_PAD_LEFT)); @@ -292,7 +292,7 @@ public function advance( } while ($chars > $this->written) { - $this->session->write(self::FULL); + $this->session->write(self::Full); $this->written++; } } diff --git a/src/Widget/Spinner.php b/src/Widget/Spinner.php index 229a607..1d364e1 100644 --- a/src/Widget/Spinner.php +++ b/src/Widget/Spinner.php @@ -14,8 +14,8 @@ class Spinner { - public const TICK = 0.08; - public const CHARS = ['-', '\\', '|', '/']; + protected const Tick = 0.08; + protected const Chars = ['-', '\\', '|', '/']; protected ?string $style = null; protected Session $session; @@ -65,7 +65,7 @@ public function advance(): static { $time = microtime(true); - if ($this->lastTime + self::TICK > $time) { + if ($this->lastTime + self::Tick > $time) { return $this; } @@ -74,10 +74,10 @@ public function advance(): static $this->session->backspace(); } - $char = self::CHARS[$this->char]; + $char = self::Chars[$this->char]; $this->char++; - if (!isset(self::CHARS[$this->char])) { + if (!isset(self::Chars[$this->char])) { $this->char = 0; } diff --git a/stubs/DecodeLabs/Terminus.php b/stubs/DecodeLabs/Terminus.php index 31b89a0..aa92b38 100644 --- a/stubs/DecodeLabs/Terminus.php +++ b/stubs/DecodeLabs/Terminus.php @@ -21,8 +21,8 @@ class Terminus implements Proxy { use ProxyTrait; - const VENEER = 'DecodeLabs\\Terminus'; - const VENEER_TARGET = Inst::class; + const Veneer = 'DecodeLabs\\Terminus'; + const VeneerTarget = Inst::class; public static Inst $instance; /** @var CommandPlugin|PluginWrapper $command */