amazing_print 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
- # Copyright (c) 2010-2016 Michael Dvorkin and contributors
3
- #
4
- # AmazingPrint is freely distributable under the terms of MIT license.
5
- # See LICENSE file or http://www.opensource.org/licenses/mit-license.php
6
- #------------------------------------------------------------------------------
7
-
8
- # frozen_string_literal: true
9
-
10
- class String
11
- #
12
- # ANSI color codes:
13
- # \e => escape
14
- # 30 => color base
15
- # 1 => bright
16
- # 0 => normal
17
- #
18
- # For HTML coloring we use <kbd> tag instead of <span> to require monospace
19
- # font. Note that beloved <tt> has been removed from HTML5.
20
- #
21
- %w[gray red green yellow blue purple cyan white].zip(
22
- %w[black darkred darkgreen brown navy darkmagenta darkcyan slategray]
23
- ).each_with_index do |(color, shade), i|
24
- # NOTE: Format strings are created once only, for performance, and remembered by closures.
25
-
26
- term_bright_seq = "\e[1;#{30 + i}m%s\e[0m"
27
- html_bright_seq = %(<kbd style="color:#{color}">%s</kbd>)
28
-
29
- define_method color do |html = false, *|
30
- (html ? html_bright_seq : term_bright_seq) % self
31
- end
32
-
33
- term_normal_seq = "\e[0;#{30 + i}m%s\e[0m"
34
- html_normal_seq = %(<kbd style="color:#{shade}">%s</kbd>)
35
-
36
- define_method "#{color}ish" do |html = false, *|
37
- (html ? html_normal_seq : term_normal_seq) % self
38
- end
39
- end
40
-
41
- # Remove ANSI color codes.
42
- def uncolor
43
- gsub(/\e\[[0-9;]*m/, '')
44
- end
45
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'String extensions' do
6
- %i[gray red green yellow blue purple cyan white].each_with_index do |color, i|
7
- it "has #{color} color" do
8
- expect(color.to_s.send(color)).to eq("\e[1;#{30 + i}m#{color}\e[0m")
9
- end
10
-
11
- it "has #{color}ish color" do
12
- expect(color.to_s.send(:"#{color}ish")).to eq("\e[0;#{30 + i}m#{color}\e[0m")
13
- end
14
- end
15
- end