Skip to content
Open
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
55 changes: 55 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Bug Report
description: Report an issue with ConsoleColor
title: "[Bug]: "
labels: ["bug"]
body:
- type: markdown
attributes:
value: Thank you for taking the time to fill out this bug report!

- type: textarea
attributes:
label: Description
description: A brief description of the bug
validations:
required: true

- type: textarea
attributes:
label: Steps to Reproduce
description: What was the process that led to this bug?
value: |
1.
2.
3.
...
validations:
required: true

- type: textarea
attributes:
label: Expected Result
description: What did you expect to happen when following the steps to reproduce?
validations:
required: true

- type: textarea
attributes:
label: Actual Result
description: What actually happened?
validations:
required: true

- type: input
attributes:
label: ConsoleColor Version
placeholder: "1.2.3"
validations:
required: true

- type: input
attributes:
label: PHP Version
placeholder: "8.x.x"
validations:
required: true
34 changes: 34 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Feature Request
description: Propose a new feature for ConsoleColor
title: "[Feature]: "
labels: ["feature"]
body:
- type: markdown
attributes:
value: Thank you for taking the time to propose a new feature!

- type: textarea
attributes:
label: Description
description: A brief description of the feature you'd like to propose
validations:
required: true

- type: textarea
attributes:
label: Example Code
description: |
One or more examples of how you think the feature should work and what
its results would be
render: php

- type: dropdown
attributes:
label: Release Target
description: |
Would this feature be a major (breaking) change to existing
functionality or can it go into a minor release?
options:
- Unknown
- Minor
- Major
40 changes: 40 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!--
Thank you for your contribution to ConsoleColor!

Complete this description and the project maintainers will do
their best to review your pull request in a timely manner.
-->

<!--
Make sure you are targeting the correct branch with this pull request.
Changes to the current release version should go into the `develop` branch.
If this is a fix for a prior version make sure to target the correct version branch.
-->

<!-- Please give this pull request a meaningful title that briefly summarizes its content -->

## Description

<!--
Describe the contents of this change in as much detail as possible.
Please include *why* this change is important and what benefit it provides.

If this change relates to an open issue be sure to reference it here as well.
-->

## Contribution Checklist

- [ ] The contents of this pull request are my own work and may be distributed under the terms of the project license
- [ ] I have read and agree to the [Contributing](CONTRIBUTING.md) guidelines and the [Code of Conduct](CODE_OF_CONDUCT.md)
- [ ] All new changes are covered by appropriate tests
- [ ] All changes pass code style checks and static analysis
- [ ] All previous tests and checks are passing
- [ ] I have included documentation about this change
- [ ] The details of this change have been added to the `Unreleased` section of the [changelog](CHANGELOG.md)

**This pull request includes:**

- [ ] Breaking changes to existing functionality (major release)
- [ ] New functionality (minor release)
- [ ] Fixes for existing functionality (patch release)
- [ ] Fixes to a previous major or minor release version
9 changes: 6 additions & 3 deletions .github/workflows/acceptance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
- php: "8.2"
- php: "8.3"
- php: "8.4"
# - php: "8.5"
- php: "8.5"

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v6
- name: Setup PHP ${{ matrix.versions.php }}
uses: shivammathur/setup-php@v2
with:
Expand All @@ -38,7 +38,7 @@ jobs:
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache Dependencies
uses: actions/cache@v3
uses: actions/cache@v5
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ matrix.versions.php }}-${{ hashFiles('**/composer.json') }}
Expand All @@ -49,6 +49,9 @@ jobs:
- name: Install Dependencies
run: composer install --no-interaction --prefer-dist --no-progress

- name: Check composer.json Format
run: composer normalize --diff --dry-run --no-interaction --ansi

- name: Check Code Style
run: composer style:check

Expand Down
74 changes: 71 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- omit in toc -->
# Console Color

[![Latest Stable Version](https://img.shields.io/packagist/v/bebat/console-color.svg?style=flat-square)](https://packagist.org/packages/bebat/console-color)
Expand All @@ -11,12 +12,13 @@ Console Color is a lightweight PHP 8.1+ library for adding color & other styles
- [Installation](#installation)
- [Basic Usage](#basic-usage)
- [Environment Variables](#environment-variables)
- [Auto Termination](#auto-termination)
- [Included Styles](#included-styles)
- [Basic Styles](#basic-styles)
- [Text](#text)
- [Underline](#underline)
- [Foreground & Background Color](#foreground--background-color)
- [256 & True Color](#256--true-color)
- [Foreground \& Background Color](#foreground--background-color)
- [256 \& True Color](#256--true-color)
- [Composite Styles](#composite-styles)

## Installation
Expand Down Expand Up @@ -77,6 +79,72 @@ In addition to checking if `STDOUT` is a TTY, `Style` will look at several envir
* `TERM` - `Style` will check `TERM` to see if it supports 256 colors.
* `COLORTERM` - If `COLORTERM` is set to `truecolor` then `Style` will apply RGB based colors.

### Auto Termination

By default, Console Color will "terminate" each style by appending `Style\Text::None` after the text you are applying styles to. This is helpful so you don't accidentally make all the text in the terminal bright red, for example. However, if you are outputting many styles to the screen and would like more control on when they are terminated this can be disabled globally or at call time.

To disable termination globally, pass `false` to `autoTerminate()` like so:

```php
use BeBat\ConsoleColor\Style;

$style = new Style();
$style->autoTerminate(false);

echo $style->apply("Didn't I just warn you about this?\n", Style\Color::BrightRed);
```

Auto termination can be re-enabled simply by calling `autoTerminate()` as well.

Auto termination can also be disabled at call time by passing `false` as the third parameter to `apply()`:

```php
use BeBat\ConsoleColor\Style;

$style = new Style();

echo $style->apply("This style wont't stop!\n", Style\Color::Yellow, false);
echo $style->apply("Now we're mixing and matching styles?\n", Style\BackgroundColor::BrightRed, false);
echo $style->apply("Let's stop things before they get too out of hand\n", Style\Text::Underline, true);
```

The `Style` instance keeps track of whether the previous style was terminated or not. You can use `willAutoTerminate()` and `isActive()` to determine whether auto termination is enabled and if there are styles currently active on the output stream.

To manually end styling, you can output `terminate()`:

```php
use BeBat\ConsoleColor\Style;

$style = new Style();
$style->autoTerminate(false);

try {
echo $style->apply("We're about to attempt something that could fail!\n", Style\BackgroundColor::BrightYellow);

// ...
} catch (\Throwable $e) {
if ($style->isActive()) {
// Previously applied style(s) weren't stopped
echo $style->terminate();
}
}
```

Lastly, the `apply()` method will also check to see if styles were terminated by being passed `Style\Text::None`:

```php
use BeBat\ConsoleColor\Style;

$style = new Style();
$style->autoTerminate(false);

echo $style->apply("Let's keep styling forever!\n", Style\Color::Blue);
$style->isActive(); // => true

echo $style->apply("Never mind, I've grown bored of such things.\n", Style\Text::None);
$style->isActive(); // => false
```

## Included Styles

`Style::apply()` accepts an instance of [`StyleInterface`](src/StyleInterface.php), and Console Color includes a number of styles that implement this interface.
Expand Down Expand Up @@ -174,7 +242,7 @@ echo $style->apply(
) . PHP_EOL;
```

`Style\Composite()` can actually take as many styles as you need to apply:
`Style\Composite()` can take as many styles as you need to apply at once:

```php
use BeBat\ConsoleColor\Style;
Expand Down
3 changes: 3 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Security Policy

Because of their sensitive nature, security issues should **not** be discussed in public forums. If you believe you have found an issue that exposes sensitive information or that could be leveraged in accessing such information, please email it directly to the project maintainer at <ben.batschelet@gmail.com>. We will respond promptly and do our utmost to resolve any security issues in a timely manner.
2 changes: 1 addition & 1 deletion captainhook.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"conditions": []
},
{
"action": "composer test:phpunit -- --colors=never",
"action": "vendor/bin/phpunit --colors=never",
"options": [],
"conditions": []
}
Expand Down
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@
"bebat/verify": "~3.2.0",
"captainhook/captainhook": "~5.25.11",
"captainhook/plugin-composer": "~5.3.3",
"ergebnis/composer-normalize": "~2.33",
"friendsofphp/php-cs-fixer": "^3.89.2",
"maglnet/composer-require-checker": "~4.6",
"ergebnis/composer-normalize": "~2.48.2",
"friendsofphp/php-cs-fixer": "~3.91.3",
"maglnet/composer-require-checker": "^4.6",
"mockery/mockery": "~1.6.2",
"phpstan/extension-installer": "~1.4.3",
"phpstan/phpstan": "~1.12.32",
"phpstan/phpstan-deprecation-rules": "~1.2.1",
"phpstan/phpstan-mockery": "~1.1.1",
"phpstan/phpstan-phpunit": "~1.4.2",
"phpstan/phpstan-strict-rules": "~1.6.2",
"phpstan/phpstan": "~2.1.32",
"phpstan/phpstan-deprecation-rules": "~2.0.3",
"phpstan/phpstan-mockery": "~2.0.0",
"phpstan/phpstan-phpunit": "~2.0.8",
"phpstan/phpstan-strict-rules": "~2.0.7",
"phpunit/phpunit": "~10.5.58",
"zalas/phpunit-globals": "~4.0.1"
},
Expand Down Expand Up @@ -74,7 +74,7 @@
"@test:phpunit"
],
"test:coverage": "phpunit --coverage-clover=coverage.xml",
"test:phpunit": "phpunit",
"test:phpunit": "phpunit --colors=always",
"test:static": "phpstan analyze --ansi"
},
"scripts-descriptions": {
Expand Down
2 changes: 0 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ parameters:
paths:
- src
- test
checkMissingIterableValueType: true
ignoreErrors:
- '/Readonly property BeBat\\ConsoleColor\\Style::.+ is assigned outside of the constructor/'
- '/Call to an undefined method BeBat\\Verify\\API\\Value::/'
- '/Access to an undefined property BeBat\\Verify\\API\\Value::/'
Loading