boring 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 501d6772ed706a459f07dfacd62431999d84b895
4
+ data.tar.gz: 438dd560e08eab5e64489492966a2996f1d25ab0
5
+ SHA512:
6
+ metadata.gz: 223141196fc24c84918f8aa214447913305236aecff6edfdd93115fc9c96f1a9b301b0e2e1a6560f8311f45d540031e7df9b9a0912cb1c673a4ddb0596b9ea9a
7
+ data.tar.gz: 641ca8d373ca77f9ac357f94fe8a119fbaf59799b26475e3a52bec6c0be878ae2472bbb8c8ae2910c1b456ee1d7cd2cb5eb00ca9025e305cd0b67e370bd722d2
@@ -0,0 +1,46 @@
1
+ Boring
2
+ ======
3
+
4
+ Shake free the shackles of color; resist the tyranny of fun!
5
+
6
+ Boring will strip ANSI escape sequences. For instance some utilities may use ansi escapes to colorize their output, or make some particularly important thing blink. This is great great in your terminal, but looks pretty poor in an email, and can cause some log processors to choke up. The solution? Make the text boring!
7
+
8
+ Usage
9
+ -----
10
+
11
+ Assuming you have some test results that look like this:
12
+
13
+ ~~~
14
+ test_result.log:
15
+ Failure:
16
+ test_comments_generate_change_reports(ActivityStreamTest)
17
+ ~~~
18
+
19
+ You can strip escape sequences with `boring`:
20
+
21
+ ~~~
22
+ $ boring test_result.log
23
+ Failure:
24
+ test_comments_generate_change_reports(ActivityStreamTest)
25
+ ~~~
26
+
27
+ You can also use `boring` as a Ruby library:
28
+
29
+ ~~~ ruby
30
+ require 'boring'
31
+
32
+ boring = Boring.new
33
+ boring.scrub("Failure!")
34
+ #=> "Failure!"
35
+ ~~~
36
+
37
+ Installation
38
+ ------------
39
+
40
+ Install `boring` with rubygems:
41
+
42
+ gem install boring
43
+
44
+ -----
45
+
46
+ Adam Sanderson, http://www.monkeyandcrow.com
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+
4
+ require_relative '../lib/boring'
5
+
6
+ opts = OptionParser.new do |opts|
7
+ opts.banner = "Usage: #{$0} [options] file_1 ..."
8
+
9
+ opts.on("-E", "--encoding", "Set encoding, default: #{Encoding.default_external}") do |encoding|
10
+ Encoding.default_external = encoding
11
+ end
12
+
13
+ opts.on("--version", "Print version") do
14
+ puts Boring::VERSION
15
+ exit
16
+ end
17
+
18
+ opts.on_tail("-h", "--help", "Show this message") do
19
+ puts opts
20
+ exit
21
+ end
22
+ end
23
+
24
+ opts.parse! ARGV
25
+
26
+ boring = Boring.new
27
+ boring.pipe(ARGF, STDOUT)
@@ -0,0 +1,59 @@
1
+ require_relative './version'
2
+
3
+ class Boring
4
+ # ANSI Escape sequence byte ranges:
5
+ #
6
+ # CSI Parameter bytes: "0123456789:;<=>?"
7
+ # CSI Intermediate bytes: " !\"\#$%&'()*+,-./"
8
+ # CSI Finishing byte: "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
9
+ #
10
+ # References: http://en.wikipedia.org/wiki/ANSI_escape_code
11
+ # https://www.gnu.org/software/teseq/manual/html_node/Escape-Sequence-Recognition.html
12
+ #
13
+ ESCAPE_SEQUENCE = /
14
+ \x1B # Escape sequences start with an ESC char
15
+ (
16
+ [\x20-\x2F]*
17
+ [\x40-\x5A\x5C-\x7E]
18
+
19
+ |
20
+
21
+ \[ # Start CSI sequence
22
+ [\x30-\x3F]+ # CSI Parameter bytes
23
+ [\x20-\x2F]* # CSI Intermediate bytes
24
+ [\x40-\x7E] # CSI Finishing byte
25
+ )
26
+ /x
27
+
28
+ # Default escape replacement
29
+ REPLACEMENT = ""
30
+
31
+ attr_reader :replacement
32
+
33
+ # Create a new Boring string scrubber. An optional replacement string may be used
34
+ # for any ANSI escape sequences.
35
+ def initialize(replacement=REPLACEMENT)
36
+ @replacement = replacement
37
+ end
38
+
39
+ # Pipe data from io_in to io_out and scrub it along the way.
40
+ def pipe(io_in, io_out)
41
+ # Since we know that an escape may not contain a newline, we can process
42
+ # this line by line.
43
+ io_in.each_line do |line|
44
+ io_out << scrub(line)
45
+ end
46
+ end
47
+
48
+ # Removes escape sequences from str.
49
+ def scrub(str)
50
+ str.gsub(ESCAPE_SEQUENCE, replacement)
51
+ end
52
+
53
+ # Removes escape sequences from str in place.
54
+ def scrub!(str)
55
+ str.gsub!(ESCAPE_SEQUENCE, replacement)
56
+ str
57
+ end
58
+
59
+ end
@@ -0,0 +1,3 @@
1
+ class Boring
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: boring
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam Sanderson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-11 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Shake free the shackles of color; resist the tyranny of fun! Easily strips
14
+ ANSI escape sequences.
15
+ email:
16
+ - netghost@gmail.com
17
+ executables:
18
+ - boring
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - README.markdown
23
+ - bin/boring
24
+ - lib/boring.rb
25
+ - lib/version.rb
26
+ homepage: https://github.com/adamsanderson/boring
27
+ licenses: []
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.2.1
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Strip ANSI escape sequences.
49
+ test_files: []