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

--no-color is not available for crystal spec #1587

Closed
rhysd opened this issue Sep 24, 2015 · 10 comments
Closed

--no-color is not available for crystal spec #1587

rhysd opened this issue Sep 24, 2015 · 10 comments

Comments

@rhysd
Copy link
Contributor

rhysd commented Sep 24, 2015

I ran crystal spec --no-color but below was output.

Error: '--no-color' is not a file

I expected compiler to run specs and output result without ANSI colors.

I want --no-color because I want to run specs in Vim using vim-crystal. Is it possible to add --no-color to crystal spec or is there any other workaround for this?

@sdogruyol
Copy link
Member

Sorry for the noob question @rhysd doesn't vim support ANSI colors?

@keplersj
Copy link
Contributor

@sdogruyol I'm sure it's not an issue of vim supporting ANSI colors, rather I think @rhysd wants to be able to parse raw spec output without having to worry about coloring characters messing with output.

@rhysd
Copy link
Contributor Author

rhysd commented Sep 25, 2015

@sdogruyol @k2b6s9j

Vim doesn't support ANSI color sequences directly. As a workaround, it may be able to delete ANSI color sequence from the output. But it is not perfect because Vim can't know which color sequence is derived from compiler's output and derived from output of spec itself.

Many other subcommands have --no-color to disable ANSI color sequences, but crystal spec doesn't. I think compiler gets more consistency by crystal spec supporting --no-color.

I looked some compiler code. Color is controlled by instance variable @color of Compiler. So I think it is not hard to add --no-color to crystal spec then I suggested it. I think I can send PR for this.

@asterite
Copy link
Member

I like this. You'd need to support it in the spec.cr program, and then pass it from the compiler into that subprogram, in case you want to tackle this :)

@luislavena
Copy link
Contributor

@asterite adding the logic to disable colors is easy:

diff --git a/src/spec/spec.cr b/src/spec/spec.cr
index ed5b3d4..f58639c 100644
--- a/src/spec/spec.cr
+++ b/src/spec/spec.cr
@@ -84,7 +84,11 @@ module Spec

   # :nodoc:
   def self.color(str, status)
-    str.colorize(COLORS[status])
+    if color?
+      str.colorize(COLORS[status])
+    else
+      str
+    end
   end

   # :nodoc:
@@ -109,6 +113,17 @@ module Spec
     @@aborted
   end

+  @@color = true
+
+  # :nodoc:
+  def self.color=(@@color)
+  end
+
+  # :nodoc:
+  def self.color?
+    @@color
+  end
+
   @@pattern = nil

   # :nodoc:
@@ -191,6 +206,9 @@ OptionParser.parse! do |opts|
   opts.on("--fail-fast", "abort the run on first failure") do
     Spec.fail_fast = true
   end
+  opts.on("--no-color", "disable color output") do
+    Spec.color = false
+  end
   opts.on("--help", "show this help") do |pattern|
     puts opts
     exit

But having problems to adding support to run_specs (the code is too smart for me 😞)

rhysd added a commit to rhysd/crystal that referenced this issue Sep 26, 2015
rhysd added a commit to rhysd/crystal that referenced this issue Sep 27, 2015
@jhass jhass closed this as completed Sep 27, 2015
repomaa pushed a commit to repomaa/crystal that referenced this issue Sep 29, 2015
@martinos
Copy link

When I run

crystal spec --no-color

I get a colored output. Here is my crystal version:

crystal -v
Crystal 0.23.1 (2017-10-12) LLVM 4.0.1

I am on OSX 10.12.6

@luislavena
Copy link
Contributor

@martinos, please see comment here #4292 (comment)

@asterite
Copy link
Member

I think crystal spec --no-color should work

@martinos
Copy link

Here's a screenshot:
crystal spec

@straight-shoota
Copy link
Member

It seems that the --no-color flag is consumed by setup_simple_compiler_options but not added to the process args for the spec runner. So the output from the compiler itself doesn't use color, but the output from the spec runner does.

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

8 participants