Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Common/Command/Run.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Symfony\Component\Console\Output\OutputInterface;
use Testo\Render\StdoutRenderer;
use Testo\Render\TeamcityInterceptor;
use Testo\Render\TerminalInterceptor;

#[AsCommand(
name: 'run',
Expand All @@ -20,7 +21,8 @@ public function __invoke(
InputInterface $input,
OutputInterface $output,
): int {
$this->container->bind(StdoutRenderer::class, TeamcityInterceptor::class);
// $this->container->bind(StdoutRenderer::class, TeamcityInterceptor::class);
$this->container->bind(StdoutRenderer::class, TerminalInterceptor::class);

$result = $this->application->run();

Expand Down
28 changes: 28 additions & 0 deletions src/Render/Terminal/Color.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Testo\Render\Terminal;

/**
* ANSI color codes for terminal styling.
*/
enum Color: string
{
case Green = "\033[32m";
case Red = "\033[31m";
case Yellow = "\033[33m";
case Blue = "\033[34m";
case Cyan = "\033[36m";
case Gray = "\033[90m";
case White = "\033[97m";

// Styles
case Reset = "\033[0m";
case Bold = "\033[1m";
case Dim = "\033[2m";

// Backgrounds
case BgRed = "\033[41m";
case BgGreen = "\033[42m";
}
97 changes: 97 additions & 0 deletions src/Render/Terminal/ColorMode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

declare(strict_types=1);

namespace Testo\Render\Terminal;

/**
* Color mode for terminal output.
*/
enum ColorMode
{
/**
* Auto-detect color support based on terminal capabilities and environment.
* Checks for:
* - TERM environment variable
* - NO_COLOR environment variable
* - CI environment detection
* - TTY detection
*/
case Auto;

/**
* Always use colors regardless of terminal capabilities.
*/
case Always;

/**
* Never use colors, plain text output only.
*/
case Never;

/**
* Determines if colors should be enabled based on the mode.
*/
public function shouldUseColors(): bool
{
return match ($this) {
self::Always => true,
self::Never => false,
self::Auto => self::detectColorSupport(),
};
}

/**
* Auto-detects if terminal supports colors.
*/
private static function detectColorSupport(): bool
{
// Respect NO_COLOR environment variable (https://no-color.org/)
if (isset($_SERVER['NO_COLOR']) || isset($_ENV['NO_COLOR'])) {
return false;
}

// Check if running in CI without TTY
if (self::isCI() && !self::isTTY()) {
return false;
}

// Check TERM environment variable
$term = $_SERVER['TERM'] ?? $_ENV['TERM'] ?? '';
if ($term === 'dumb') {
return false;
}

// Check if output is to a TTY
if (self::isTTY()) {
return true;
}

// Default to no colors if can't detect
return false;
}

/**
* Checks if running in CI environment.
*/
private static function isCI(): bool
{
$ciEnvVars = ['CI', 'CONTINUOUS_INTEGRATION', 'GITHUB_ACTIONS', 'GITLAB_CI', 'CIRCLECI'];

foreach ($ciEnvVars as $var) {
if (isset($_SERVER[$var]) || isset($_ENV[$var])) {
return true;
}
}

return false;
}

/**
* Checks if output is to a TTY (terminal).
*/
private static function isTTY(): bool
{
return \function_exists('posix_isatty') && @posix_isatty(\STDOUT);
}
}
17 changes: 17 additions & 0 deletions src/Render/Terminal/DotSymbol.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Testo\Render\Terminal;

/**
* Symbols for test status representation in dots mode.
*/
enum DotSymbol: string
{
case Passed = '.';
case Failed = 'F';
case Skipped = '-';
case Risky = 'R';
case Error = 'E';
}
Loading