Add various APIs#213
Conversation
fpseverino
commented
Jun 1, 2025
- Add a lot of various APIs (mainly APIs that Vapor Toolbox would need)
- Add a lot of tests
ptoffy
left a comment
There was a problem hiding this comment.
We should also add test coverage
| /// - Parameter style: The ``ConsoleStyle`` to use for styling. | ||
| /// | ||
| /// - Returns: The string wrapped in ANSI codes. | ||
| public func stylized(_ style: ConsoleStyle) -> String { |
There was a problem hiding this comment.
This is a bad idea, we should not extend standard types with public API as it pollutes all of the {Sub}String namespace. String doesn't care about this.
Also it's just way too general of a method (name) to add and it could likely conflict with any string manipulation library, even just with an internal stylized method
There was a problem hiding this comment.
In my opinion this is a very useful API, which cannot be recreated by end users as it uses private methods.
It comes in very handy when you want to integrate ConsoleKit with swift-argument-parser, as the latter has APIs that accept simple strings (obviously), but could benefit from ANSI stylisation.
Maybe if I change the function name to emphasise that it's from ConsoleKit is better?
Perhaps something like terminalStylized() or consoleStylized()?
There was a problem hiding this comment.
Personally I'd be happier with something like
let stylizedString = ConsoleStyle.style(myString, with: myStyle)but happy to let others chime in for other ideas (or to prove me wrong 🙂)
(Having something like consoleStylized() is definitely more defensible than styled)
There was a problem hiding this comment.
I disagree - I think this is fine if given a less generic name.
| /// - isBold: If `true`, the text will be bold. | ||
| /// | ||
| /// - Returns: The string wrapped in ANSI codes. | ||
| public func stylized( |
There was a problem hiding this comment.
Same as above. I'd make it internal
I think it's enabled only for the main branch(?) |