ansi_text_styles 1.0.0

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/ansi_text_styles.rb +51 -0
  3. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aed6d3739fa4c771809a72dec79d896a93dd405c
4
+ data.tar.gz: 5665e88349cc2b1ad2e372faea083034fa10e49e
5
+ SHA512:
6
+ metadata.gz: 110e80f80b2d9d54b9521ad8d2d4e762b9ba3a943eb820dc8368c1e75e4b51817e5035c91e1029d1e259a019732e753da77346a9926d97ae0d41b07ba11166fc
7
+ data.tar.gz: 925fe64c3795c2aea5f4f5bbbf7e82a2e8bb950548e0430a19bf5ebd03104ead8b2c56ba777b1ae81f7969ea5b6389276cbaaff2fce988093be5a42ac8a0d2a6
@@ -0,0 +1,51 @@
1
+ module AnsiTextStyles
2
+
3
+ VERSION = '1.0.0'
4
+
5
+ STYLES = {
6
+ # text properties
7
+ none: 0, # turn off all attributes
8
+ bold: 1, bright: 1, # these do the same thing really
9
+ italic: 3, underline: 4, blink: 5,
10
+ reverse: 7, # swap foreground and background colours
11
+ hide: 8, # foreground color same as background
12
+
13
+ # foreground colours
14
+ black: 30, grey: 90, lt_grey: 37, :white => 97,
15
+ red: 31, lt_red: 91,
16
+ green: 32, lt_green: 92,
17
+ dk_yellow: 33, brown: 33, yellow: 93,
18
+ blue: 34, lt_blue: 94,
19
+ magenta: 35, pink: 95, lt_magenta: 95,
20
+ cyan: 36, lt_cyan: 96,
21
+ default: 39,
22
+
23
+ # background colours
24
+ bg_black: 40, bg_grey: 100, bg_lt_grey: 47, bg_white: 107,
25
+ bg_red: 41, bg_lt_red: 101,
26
+ bg_green: 42, bg_lt_green: 102,
27
+ bg_dk_yellow: 43, bg_brown: 43, bg_yellow: 103,
28
+ bg_blue: 44, bg_lt_blue: 104,
29
+ bg_magenta: 45, bg_pink: 105, bg_lt_magenta: 105,
30
+ bg_cyan: 46, bg_lt_cyan: 106,
31
+ }
32
+
33
+ def self.styles
34
+ STYLES.keys
35
+ end
36
+
37
+ refine String do
38
+ # applies the text attributes to the current string
39
+ def style(*styles)
40
+ codes = STYLES.values_at(*styles.flatten).compact
41
+ "\e[%sm%s\e[m" % [codes.join(';'), self.to_s]
42
+ end
43
+
44
+ # create instance methods for each text attribute (chainable)
45
+ STYLES.each do |attr, _|
46
+ define_method(attr) { self.style(attr) }
47
+ end
48
+ end
49
+
50
+ end
51
+
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ansi_text_styles
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Brent Jacobs
8
+ - br3nt
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2017-10-06 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email:
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/ansi_text_styles.rb
21
+ homepage: https://github.com/br3nt/ansi_text_styles
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.4.5.1
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Adds methods to apply ANSI colour codes and text styles to strings.
45
+ test_files: []