climate icon indicating copy to clipboard operation
climate copied to clipboard

Proposal: Create static methods for easier usage when formatting

Open deanc opened this issue 4 years ago • 2 comments

It's a little inconvenient having to instantiate an object to call methods for formatting each time, particularly for colours. The existing API is:

$climate = new \League\CLImate\CLImate;
$climate->red('Whoa now this text is red.');

I propose adding some static utility methods to make usage easier and more concise, especially as there's not a great need for state.

CLImate::redStatic('Whoa now this text is red.');

Method name can adjusted, of course, but I guess it's important to maintain backwards compatibility so it can't just be ::red

I don't mind working on this if a PR would be accepted.

deanc avatar Mar 07 '21 07:03 deanc

Hi @deanc, due to the way CLImate was originally built I think it actually would be possible to use the same method names.

There is a lot of state involved within CLImate, so if you were doing lots of calls it would probably get expensive, and I'm concerned it could be confusing to newbies. But I'll give it some thought to see if this can be supported cleanly and easily

duncan3dc avatar Mar 07 '21 08:03 duncan3dc

Hi @duncan3dc - thanks for the quick reply. That sounds great. I think when you deal with complex combinations then it makes sense to keep it as is, but perhaps for the most basic of use cases we could have some static methods. Perhaps something like:

::bold ::italic ::underline ::red ::backgroundRed and then ::colorAndBackground($foreground, $background, $string)

deanc avatar Mar 07 '21 09:03 deanc