ansispan 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ansispan.rb +14 -12
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 256c250ef391542f6d40195ef756ee97cedd808df6cceb15b9dc27d5ce478c66
|
4
|
+
data.tar.gz: 6edb0c7e98ee62a5079ddf0c1d6d2d7250e22669d804610fbb57dbcf0e956c21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d485bd528a298e3e71a3ae8dbf6cace1410de9ab95f92b6673bfccd98524faf61e4b74e911cb4660bc05e3b6846774a18ad22a4140b68f4c3433eca33b4e5928
|
7
|
+
data.tar.gz: b1a58971b0699a8450e75965d7bfb6c41ee9573afe1b289c457ba2b66afb93f8a6a289a7cf696d378759338a7745237df742c72824e47e55535edd93c2fc0bf7
|
data/lib/ansispan.rb
CHANGED
@@ -10,43 +10,45 @@ class Ansispan
|
|
10
10
|
'37': 'white'
|
11
11
|
}
|
12
12
|
|
13
|
-
def self.convert(str)
|
13
|
+
def self.convert(str, escape_character: '\033')
|
14
|
+
escape_character = Regexp.escape(escape_character)
|
15
|
+
|
14
16
|
@foreground_colors.keys.each do |ansi|
|
15
17
|
span = '<span style="color: ' + @foreground_colors[ansi] + '">'
|
16
18
|
#
|
17
19
|
# `\033[Xm` == `\033[0;Xm` sets foreground color to `X`.
|
18
20
|
#
|
19
21
|
|
20
|
-
str = str.gsub(
|
21
|
-
.gsub(
|
22
|
+
str = str.gsub(/#{escape_character}\[#{ansi}m/, span)
|
23
|
+
.gsub(/#{escape_character}\[#{ansi}m/, span)
|
22
24
|
end
|
23
25
|
|
24
26
|
#
|
25
27
|
# `\033[1m` enables bold font, `\033[22m` disables it
|
26
28
|
#
|
27
|
-
str = str.gsub(
|
28
|
-
.gsub(
|
29
|
+
str = str.gsub(/#{escape_character}\[1m/, '<b>')
|
30
|
+
.gsub(/#{escape_character}\[22m/, '</b>')
|
29
31
|
|
30
32
|
|
31
33
|
# Bold colors
|
32
34
|
@foreground_colors.keys.each do |ansi|
|
33
35
|
span = '<span style="font-weight: bold; color: ' + @foreground_colors[ansi] + '">'
|
34
|
-
str = str.gsub(
|
36
|
+
str = str.gsub(/#{escape_character}\[1;#{ansi}m/, span)
|
35
37
|
end
|
36
38
|
|
37
39
|
# Underline colors
|
38
40
|
@foreground_colors.keys.each do |ansi|
|
39
41
|
span = '<span style="text-decoration: underline; color: ' + @foreground_colors[ansi] + '">'
|
40
|
-
str = str.gsub(
|
42
|
+
str = str.gsub(/#{escape_character}\[4;#{ansi}m/, span)
|
41
43
|
end
|
42
44
|
#
|
43
45
|
# `\033[3m` enables italics font, `\033[23m` disables it
|
44
46
|
#
|
45
|
-
str = str.gsub(
|
46
|
-
.gsub(
|
47
|
+
str = str.gsub(/#{escape_character}\[3m/, '<i>')
|
48
|
+
.gsub(/#{escape_character}\[23m/, '</i>')
|
47
49
|
|
48
|
-
str = str.gsub(
|
49
|
-
str = str.gsub(
|
50
|
-
return str.gsub(
|
50
|
+
str = str.gsub(/#{escape_character}\[m/, '</span>');
|
51
|
+
str = str.gsub(/#{escape_character}\[0m/, '</span>');
|
52
|
+
return str.gsub(/#{escape_character}\[39m/, '</span>');
|
51
53
|
end
|
52
54
|
end
|
metadata
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ansispan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jelani Woods
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2021-07-01 00:00:00.000000000 Z
|
@@ -21,7 +21,7 @@ homepage: http://github.com/jelaniwoods/ansispan
|
|
21
21
|
licenses:
|
22
22
|
- MIT
|
23
23
|
metadata: {}
|
24
|
-
post_install_message:
|
24
|
+
post_install_message:
|
25
25
|
rdoc_options: []
|
26
26
|
require_paths:
|
27
27
|
- lib
|
@@ -36,8 +36,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
36
36
|
- !ruby/object:Gem::Version
|
37
37
|
version: '0'
|
38
38
|
requirements: []
|
39
|
-
rubygems_version: 3.
|
40
|
-
signing_key:
|
39
|
+
rubygems_version: 3.2.3
|
40
|
+
signing_key:
|
41
41
|
specification_version: 4
|
42
42
|
summary: Convert Terminal ansi colors to <span> tags with inline color styles.
|
43
43
|
test_files: []
|