Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Create static methods for easier usage when formatting #169

Open
deanc opened this issue Mar 7, 2021 · 2 comments
Open

Proposal: Create static methods for easier usage when formatting #169

deanc opened this issue Mar 7, 2021 · 2 comments

Comments

@deanc
Copy link

deanc commented Mar 7, 2021

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.

@duncan3dc
Copy link
Member

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

@deanc
Copy link
Author

deanc commented Mar 7, 2021

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants