-
Notifications
You must be signed in to change notification settings - Fork 255
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 - Replace SimpleText formatter with SSHKit.config.log_colors = false option #245
Comments
Absolutely
Maybe extending that check also to honour not just |
Doesn't SSHKit already honor Line 24 in db4d1d3
|
@mattbrictson It does, but the problem is that at the moment you can't force the coloring to be off if def colorize?
($stdout.tty? && ENV['SSHKIT_COLOR'] != false) || ENV['SSHKIT_COLOR']
end Alternatively, If I was to implement As I understand the ramifications would be as follows (are we happy with these?): The default behaviour of the If someone has colors who doesn't want them, they must have the I guess we should deprecate |
Agreed all round. I could even agree to keep SSHKIT_COLOR, for some
|
Hmm, I think it is more reasonable to just assume the user will want color output, as long as there is a tty. We shouldn't require a environment variable to be set to enable color. This is actually the first I've ever heard of It seems most tools these days default to color:
I think this problem is going to be widespread. Perhaps we could take the |
OK, I guess this will need rework tomorrow, but here is a branch with the changes necessary to support robd/sshkit@clarify-output-option...robd:remove-formatter-duplication I do agree though, if this isn't widely supported, then I think it will be a big support hassle to get everyone to add environment variables when they upgrade. If we're not going to go with a (semi) standard naming such as One thing that I discovered is that One change in the above branch is that I now use the If we can come to a consensus on how this should work, I'll rework the PR tomorrow. |
As I've seen it, let's take any given CI server, and suggest that it doesn't force a tty, or that it's something being scripted in a bash script, but driven with GNU I'm against the The I'd say a good default, respecting widely used env vars (I've also never heard of In pseudo code… ?
and, then later it can be forced by Capistrano since we might have done this init when setting up an SSHKit instance already? |
Hey all Thanks for your involvement and feedback here. I'm going to look at this again now and I'd like to start with solving a smaller part of the problem if that's OK. I'm getting a bit confused and the changeset is quite big, so I think splitting it down would help make more incremental progress. The first thing I'd like to change is that we respect the At the moment, for the following configuration, you get color codes in the output file: SSHKit.config.output = SSHKit::Formatter::Pretty.new(File.open('log/deploy.log', 'wb')) That is because the logic we've been talking about in the colorize? method checks I propose to rework things so that the tty of IO output stream being used is checked in @leehambley & @mattbrictson, can I check that this would be a desirable change and you are happy with this as a first step? |
Logical, good deductions
|
I agree this is a good first step. |
OK great. See what you think of #246. |
## 1.8.1 * Change license to MIT, thanks to all the patient contributors who gave their permissions. ## 1.8.0 * add SSHKit::Backend::ConnectionPool#close_connections [PR #285](capistrano/sshkit#285) @akm * Clean up rubocop lint warnings [PR #275](capistrano/sshkit#275) @cshaffer * Prepend unused parameter names with an underscore * Prefer “safe assignment in condition” * Disambiguate regexp literals with parens * Prefer `sprintf` over `String#%` * No longer shadow `caller_line` variable in `DeprecationLogger` * Rescue `StandardError` instead of `Exception` * Remove useless `private` access modifier in `TestAbstract` * Disambiguate block operator with parens * Disambiguate between grouped expression and method params * Remove assertion in `TestHost#test_assert_hosts_compare_equal` that compares something with itself * Export environment variables and execute command in a subshell. [PR #273](capistrano/sshkit#273) @kuon * Introduce `log_command_start`, `log_command_data`, `log_command_exit` methods on `Formatter` [PR #257](capistrano/sshkit#257) @robd * Deprecate `@stdout` and `@stderr` accessors on `Command` * Add support for deprecation logging options. [README](README.md#deprecation-warnings), [PR #258](capistrano/sshkit#258) @robd * Quote environment variable values. [PR #250](capistrano/sshkit#250) @Sinjo - Chris Sinjakli * Simplified formatter hierarchy. [PR #248](capistrano/sshkit#248) @robd * `SimpleText` formatter now extends `Pretty`, rather than duplicating. * Hide ANSI color escape sequences when outputting to a file. [README](README.md#output-colors), [Issue #245](capistrano/sshkit#245), [PR #246](capistrano/sshkit#246) @robd * Now only color the output if it is associated with a tty, or the `SSHKIT_COLOR` environment variable is set. * Removed broken support for assigning an `IO` to the `output` config option. [Issue #243](capistrano/sshkit#243), [PR #244](capistrano/sshkit#244) @robd * Use `SSHKit.config.output = SSHKit::Formatter::SimpleText.new($stdin)` instead * Added support for `:interaction_handler` option on commands. [PR #234](capistrano/sshkit#234), [PR #242](capistrano/sshkit#242) @robd * Removed partially supported `TRACE` log level. [2aa7890](capistrano/sshkit@2aa7890) @robd * Add support for the `:strip` option to the `capture` method and strip by default on the `Local` backend. [PR #239](capistrano/sshkit#239), [PR #249](capistrano/sshkit#249) @robd * The `Local` backend now strips by default to be consistent with the `Netssh` one. * This reverses change [7d15a9a](capistrano/sshkit@7d15a9a) to the `Local` capture API to remove stripping by default. * If you require the raw, unstripped output, pass the `strip: false` option: `capture(:ls, strip: false)` * Simplified backend hierarchy. [PR #235](capistrano/sshkit#235), [PR #237](capistrano/sshkit#237) @robd * Moved duplicate implementations of `make`, `rake`, `test`, `capture`, `background` on to `Abstract` backend. * Backend implementations now only need to implement `execute_command`, `upload!` and `download!` * Removed `Printer` from backend hierarchy for `Local` and `Netssh` backends (they now just extend `Abstract`) * Removed unused `Net::SSH:LogLevelShim` * Removed dependency on the `colorize` gem. SSHKit now implements its own ANSI color logic, with no external dependencies. Note that SSHKit now only supports the `:bold` or plain modes. Other modes will be gracefully ignored. [#263](capistrano/sshkit#263) * New API for setting the formatter: `use_format`. This differs from `format=` in that it accepts options or arguments that will be passed to the formatter's constructor. The `format=` syntax will be deprecated in a future release. [#295](capistrano/sshkit#295) * SSHKit now immediately raises a `NameError` if you try to set a formatter that does not exist. [#295](capistrano/sshkit#295)
## 1.8.1 * Change license to MIT, thanks to all the patient contributors who gave their permissions. ## 1.8.0 * add SSHKit::Backend::ConnectionPool#close_connections [PR #285](capistrano/sshkit#285) @akm * Clean up rubocop lint warnings [PR #275](capistrano/sshkit#275) @cshaffer * Prepend unused parameter names with an underscore * Prefer “safe assignment in condition” * Disambiguate regexp literals with parens * Prefer `sprintf` over `String#%` * No longer shadow `caller_line` variable in `DeprecationLogger` * Rescue `StandardError` instead of `Exception` * Remove useless `private` access modifier in `TestAbstract` * Disambiguate block operator with parens * Disambiguate between grouped expression and method params * Remove assertion in `TestHost#test_assert_hosts_compare_equal` that compares something with itself * Export environment variables and execute command in a subshell. [PR #273](capistrano/sshkit#273) @kuon * Introduce `log_command_start`, `log_command_data`, `log_command_exit` methods on `Formatter` [PR #257](capistrano/sshkit#257) @robd * Deprecate `@stdout` and `@stderr` accessors on `Command` * Add support for deprecation logging options. [README](README.md#deprecation-warnings), [PR #258](capistrano/sshkit#258) @robd * Quote environment variable values. [PR #250](capistrano/sshkit#250) @Sinjo - Chris Sinjakli * Simplified formatter hierarchy. [PR #248](capistrano/sshkit#248) @robd * `SimpleText` formatter now extends `Pretty`, rather than duplicating. * Hide ANSI color escape sequences when outputting to a file. [README](README.md#output-colors), [Issue #245](capistrano/sshkit#245), [PR #246](capistrano/sshkit#246) @robd * Now only color the output if it is associated with a tty, or the `SSHKIT_COLOR` environment variable is set. * Removed broken support for assigning an `IO` to the `output` config option. [Issue #243](capistrano/sshkit#243), [PR #244](capistrano/sshkit#244) @robd * Use `SSHKit.config.output = SSHKit::Formatter::SimpleText.new($stdin)` instead * Added support for `:interaction_handler` option on commands. [PR #234](capistrano/sshkit#234), [PR #242](capistrano/sshkit#242) @robd * Removed partially supported `TRACE` log level. [2aa7890](capistrano/sshkit@2aa7890) @robd * Add support for the `:strip` option to the `capture` method and strip by default on the `Local` backend. [PR #239](capistrano/sshkit#239), [PR #249](capistrano/sshkit#249) @robd * The `Local` backend now strips by default to be consistent with the `Netssh` one. * This reverses change [7d15a9a](capistrano/sshkit@7d15a9a) to the `Local` capture API to remove stripping by default. * If you require the raw, unstripped output, pass the `strip: false` option: `capture(:ls, strip: false)` * Simplified backend hierarchy. [PR #235](capistrano/sshkit#235), [PR #237](capistrano/sshkit#237) @robd * Moved duplicate implementations of `make`, `rake`, `test`, `capture`, `background` on to `Abstract` backend. * Backend implementations now only need to implement `execute_command`, `upload!` and `download!` * Removed `Printer` from backend hierarchy for `Local` and `Netssh` backends (they now just extend `Abstract`) * Removed unused `Net::SSH:LogLevelShim` * Removed dependency on the `colorize` gem. SSHKit now implements its own ANSI color logic, with no external dependencies. Note that SSHKit now only supports the `:bold` or plain modes. Other modes will be gracefully ignored. [#263](capistrano/sshkit#263) * New API for setting the formatter: `use_format`. This differs from `format=` in that it accepts options or arguments that will be passed to the formatter's constructor. The `format=` syntax will be deprecated in a future release. [#295](capistrano/sshkit#295) * SSHKit now immediately raises a `NameError` if you try to set a formatter that does not exist. [#295](capistrano/sshkit#295)
@leehambley I didn't want to push a PR on you, but looking at the discussion in #120, you mentioned that you thought is was bit of a shame to add more formatter logic when the SimpleText formatter was added, and I agree. That PR is a bit out of date now that
term-ansicolor
was replaced withcolorize
, but if I understand correctly, theSimpleText
formatter is just thePretty
formatter with colors turned off.It seems to me that whether or not you want coloring could be orthogonal to which formatter you use. Certainly, there seems to be a lot of duplication between
SimpleText
andPretty
, which makes refactoring in this area harder.I was wondering if you would be in favour of deprecating the
SimpleText
formatter and introducing aSSHKit.config.log_colors
(or similar) option.The implementation for this seems simple - we could just include a check for
SSHKit.config.log_colors
here. For the moment, we could keep theSimpleText
class but delete the duplicatedwrite
andwrite_command
methods. Then we could add a new constructor like this:This would have the advantage of being able to disable colors on the
Dot
formatter.Of course I would update the docs, changelog and tests as usual.
The text was updated successfully, but these errors were encountered: