-
Notifications
You must be signed in to change notification settings - Fork 35
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
Experimental: refactor Airbrussh::Colors to be class, rather than module #64
Conversation
eb48313
to
f526937
Compare
Looks good to me. I like the pattern of constructing a no-op How do you feel about it? |
I feel like it is not quite as elegant as applying colors everywhere and then deferring the color/no color decision until the final output in Also, this refactor is a slight change in behavior: if SSH command output contains color, I might tinker with this some more to restore the original |
OK github just lost my comment here, but to summarise briefly, this change in behaviour was what I was trying to get at here: #63 (comment)
Since we haven't released a version of SSHKit with colors disabled for non tty outputs, I don't have a strong feeling for whether what we currently do in SSHKit is desirable for users. Ideally I think it would be good if SSHKit and Airbrussh could work the same. I think it would be fine to change the SSHKit behaviour to strip the colours at the end perhaps by moving the console class (or whatever is responsible for line length limiting and colors) to SSHKit. But I'd probably only look to do this if we were going to merge the projects (in fact I would merge them first). I'm aware that this is all probably going in a direction you're not very happy with, so please don't feel like you have to do this refactor on my account. I think it has been useful to throw up these differences between Airbrussh / SSHKit, we can refer here if support requests are raised about coloring differences once Airbrussh is the default formatter. |
Yes, this is quite tricky, because perfectly aligning how Airbrussh and the other formatters work will require a lot of subtle changes. There are also concepts that don't really line up at all, like And I agree that this is probably not worth the effort unless we merge the code bases. However, I want to experiment with the idea just to see what's involved. One more idea is to not perfectly unify the logging configuration for all formatters. Instead, take a declarative, middleware-style approach where each formatter can be given its own config. Something like this: SSHKit.configure do |config|
config.use_format :pretty, :color => false, :verbosity => :debug
end Or for Airbrussh: SSHKit.configure do |config|
config.use_format :airbrussh, :command_output => true, :truncate => :auto
end A symbol would be constantized e.g. SSHKit.configure do |config|
config.use_format MyCustomFormatter, :custom_option => true
end This would allow a lot of flexibility without having to unify the configuration. Thoughts? |
I think this is really nice. I think per-formatter options would be very helpful. An immediate example that springs to mind is that this would allow an easy path for removing the SSHKit.configure do |config|
config.use_format :pretty, :simple_text => true
end |
@leehambley I know this is a little off-topic, but what do you think of a new SSHKit formatter configuration system as outlined in my comment above? |
I need to get a release out today (Autodesk are relying on using the new
|
But I'm not opposed, no strong opinion, and anything I could argue would be
|
f526937
to
a113639
Compare
a113639
to
10acc77
Compare
@robd Would you agree this PR is good to merge? I've restored the color-stripping behavior to the |
@robd On second thought, I'm still not sure I want to go ahead with this refactor. I am going to let this simmer so more. |
Closing. See comment: #63 (comment) |
This refactor more closely aligns
Airbrussh::Colors
withSSHKit::Color
. Now they are both classes and their colorization behavior is toggled based on a flag (which is determined using:tty?
).This will bring us closer to consolidating the colors implementation across projects.
What do you think of this so far, @robd ?