ansispan 0.0.1

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