This repository has been archived by the owner on May 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pretty formatter now prints in colour (at least mostly)
- Loading branch information
1 parent
eaa350f
commit da8e06a
Showing
22 changed files
with
271 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package gherkin.formatter; | ||
|
||
import java.io.FilterWriter; | ||
import java.io.IOException; | ||
import java.io.StringWriter; | ||
import java.io.Writer; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* This class filters away ANSI color codes | ||
*/ | ||
public class MonochromeIO extends FilterWriter { | ||
private static final Pattern COLOR_PATTERN = Pattern.compile(new String(new char[(char)27]) + "\\[(?:[34][0-7]|[0-9]|90)?m"); | ||
private static final String EMPTY_STRING = ""; | ||
|
||
public MonochromeIO(Writer w) { | ||
super(w); | ||
} | ||
|
||
@Override | ||
public void write(String str, int off, int len) throws IOException { | ||
String monochromeString = COLOR_PATTERN.matcher(str).replaceAll(EMPTY_STRING); | ||
super.write(monochromeString, off, monochromeString.length()); | ||
} | ||
|
||
/** | ||
* Convenience method for our ruby tests. | ||
* @return the String data in the underlying writer - if it is a StringWriter. | ||
*/ | ||
public String getString() { | ||
if(out instanceof StringWriter) { | ||
return out.toString(); | ||
} else { | ||
throw new UnsupportedOperationException("Can only getString() from StringWriter"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'gherkin/formatter/colors' | ||
require 'gherkin/native' | ||
|
||
module Gherkin | ||
module Formatter | ||
class MonochromeIO | ||
native_impl('gherkin') | ||
|
||
include Colors | ||
|
||
def initialize(io) | ||
@io = io | ||
end | ||
|
||
def write(*a) | ||
@io.write(*(a.map{|e| monochrome(e)})) | ||
end | ||
|
||
def puts(*a) | ||
@io.puts(*(a.map{|e| monochrome(e)})) | ||
end | ||
|
||
def string | ||
@io.string | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.