Skip to content

Commit

Permalink
Add ThemeStyle class, update Theming Engine to use it and fix static …
Browse files Browse the repository at this point in the history
…analysis issues
  • Loading branch information
WendellAdriel committed May 16, 2023
1 parent 07d78c8 commit 9e72e1f
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 55 deletions.
90 changes: 53 additions & 37 deletions src/Theme/Catalog/DefaultTheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,69 +5,85 @@
namespace Minicli\Framework\Theme\Catalog;

use Minicli\Framework\Theme\Enums\Background;
use Minicli\Framework\Theme\Enums\FontWeight;
use Minicli\Framework\Theme\Enums\Foreground;
use Minicli\Framework\Theme\ThemeContract;
use StringBackedEnum;
use Minicli\Framework\Theme\ThemeStyle;

final class DefaultTheme implements ThemeContract
{
public function default(): array
public function default(): ThemeStyle
{
return [
Foreground::WHITE,
];
return ThemeStyle::make(Foreground::WHITE);
}

public function alt(): array
public function alt(): ThemeStyle
{
return [
Foreground::BLACK,
Background::WHITE,
];
return ThemeStyle::make(Foreground::BLACK, Background::WHITE);
}

public function error(): array
public function error(): ThemeStyle
{
return [
Foreground::RED,
];
return ThemeStyle::make(Foreground::RED);
}

public function errorAlt(): array
public function errorAlt(): ThemeStyle
{
return [
Foreground::WHITE,
Background::RED,
];
return ThemeStyle::make(Foreground::WHITE, Background::RED);
}

public function success(): array
public function warning(): ThemeStyle
{
return [
Foreground::GREEN,
];
return ThemeStyle::make(Foreground::YELLOW);
}

public function successAlt(): array
public function warningAlt(): ThemeStyle
{
return [
Foreground::WHITE,
Background::GREEN,
];
return ThemeStyle::make(Foreground::WHITE, Background::YELLOW);
}

public function info(): array
public function success(): ThemeStyle
{
return [
Foreground::CYAN,
];
return ThemeStyle::make(Foreground::GREEN);
}

public function infoAlt(): array
public function successAlt(): ThemeStyle
{
return [
Foreground::WHITE,
Background::CYAN,
];
return ThemeStyle::make(Foreground::WHITE, Background::GREEN);
}

public function info(): ThemeStyle
{
return ThemeStyle::make(Foreground::CYAN);
}

public function infoAlt(): ThemeStyle
{
return ThemeStyle::make(Foreground::WHITE, Background::CYAN);
}

public function bold(): ThemeStyle
{
return ThemeStyle::make(FontWeight::BOLD);
}

public function dim(): ThemeStyle
{
return ThemeStyle::make(FontWeight::DIM);
}

public function italic(): ThemeStyle
{
return ThemeStyle::make(FontWeight::ITALIC);
}

public function underline(): ThemeStyle
{
return ThemeStyle::make(FontWeight::UNDERLINE);
}

public function invert(): ThemeStyle
{
return ThemeStyle::make(FontWeight::INVERT);
}
}
61 changes: 43 additions & 18 deletions src/Theme/ThemeContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,80 @@

namespace Minicli\Framework\Theme;

use StringBackedEnum;

interface ThemeContract
{
/**
* Default style
* @return array<int,StringBackedEnum>
*/
public function default(): array;
public function default(): ThemeStyle;

/**
* Alternative style for Default
* @return array<int,StringBackedEnum>
*/
public function alt(): array;
public function alt(): ThemeStyle;

/**
* Error style
* @return array<int,StringBackedEnum>
*/
public function error(): array;
public function error(): ThemeStyle;

/**
* Alternative style for Error
* @return array<int,StringBackedEnum>
*/
public function errorAlt(): array;
public function errorAlt(): ThemeStyle;

/**
* Warning style
*/
public function warning(): ThemeStyle;

/**
* Alternative style for Warning
*/
public function warningAlt(): ThemeStyle;

/**
* Success style
* @return array<int,StringBackedEnum>
*/
public function success(): array;
public function success(): ThemeStyle;

/**
* Alternative style for Success
* @return array<int,StringBackedEnum>
*/
public function successAlt(): array;
public function successAlt(): ThemeStyle;

/**
* Info style
* @return array<int,StringBackedEnum>
*/
public function info(): array;
public function info(): ThemeStyle;

/**
* Alternative style for Info
* @return array<int,StringBackedEnum>
*/
public function infoAlt(): array;
public function infoAlt(): ThemeStyle;

/**
* Bold style
*/
public function bold(): ThemeStyle;

/**
* Dim style
*/
public function dim(): ThemeStyle;

/**
* Italic style
*/
public function italic(): ThemeStyle;

/**
* Underline style
*/
public function underline(): ThemeStyle;

/**
* Invert style
*/
public function invert(): ThemeStyle;
}
23 changes: 23 additions & 0 deletions src/Theme/ThemeStyle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Minicli\Framework\Theme;

use Minicli\Framework\Theme\Enums\Background;
use Minicli\Framework\Theme\Enums\FontWeight;
use Minicli\Framework\Theme\Enums\Foreground;

final class ThemeStyle
{
public function __construct(
public readonly FontWeight|Foreground $foreground,
public readonly ?Background $background = null
) {
}

public static function make(FontWeight|Foreground $foreground, ?Background $background = null): self
{
return new self($foreground, $background);
}
}

0 comments on commit 9e72e1f

Please sign in to comment.