Repository navigation
feat: fluent colour, emoji and layout API on ConsoleUIFormatter - #65
Merged
Merged
Conversation
Adds txtColor<Name>()/bgColor<Name>() for 38 named colours, fg()/bg(), message() with emoji shortcodes via Support\Emoji, icon(), padding(), lineHeight(), addSpaceBefore()/addSpaceAfter(), markup(), capabilities(), write() and toAnsi(). A plain message renders exactly as before. Fixes found while building it, each reproduced first: - BRIGHT_* constants threw: the sanitiser stripped the hyphen - colorize() ignored BRIGHT_* (bright-red vs bright_red keys) - Color names such as orange threw at write time; now converted to hex - unknown colours and text styles now fail where they are set - a coloured link dropped its colour - message text is escaped, so </> in it cannot end the style early
Rewrites docs/tools/formatting.md around the builder, adds a runnable examples/tools/formatting.php to the composer examples script, and records the additions, fixes and the escaping change under [Unreleased].
message() and icon() resolved shortcodes when called, so a capabilities() call later in the chain was ignored: asking for ASCII after message() still printed the Unicode emoji. Both now resolve in render(). The formatter tests also cleared neither Capabilities::fake() nor EmojisBridge::fake(), which are process-wide, so they leaked into later tests; tearDown resets both. Adds a test proving names resolve through the laranail/emojis catalogue when it is installed.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A fluent API on
ConsoleUIFormatter, so a whole style is one chain:txtColor<Name>()/bgColor<Name>(): 38 names, each declared as an@method.fg()/bg()accept any colour thatSupport\Colorparses.message()resolves:shortcodes:throughSupport\Emoji, which useslaranail/emojiswhen it is installed and falls back to ASCII otherwise.icon()puts an emoji in front of the message.padding()works inside the background.lineHeight()adds blank background lines above and below.addSpaceBefore()/addSpaceAfter()add spaces or tabs outside the background; the count must be positive, and calls add up.markup(),capabilities(),write(),toAnsi(), and the style shortcuts.It extends the existing builder rather than adding a fourth one, and a plain message renders exactly as before.
Fixes (each reproduced first)
BRIGHT_*/BG_BRIGHT_*constants threw when written, because the sanitiser stripped the hyphen.colorize()emitted no colour forBRIGHT_*(bright-redvsbright_redkeys).Colornames such asorangethrew when written; they are now converted to hex.Behaviour change
Message text is now escaped.
</>inside a message used to end the style early; now it prints literally.markup()restores the old behaviour for trusted input.Verification
composer test: 533 passed, including 23 new formatter tests.composer pintpasses.phpstanreports no errors.composer examplesincludes the newexamples/tools/formatting.php.message()removed