ansi256 0.2.5 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 895f492a5984cb96d47fd0ba832e2ef911e6da13e3205a0be1efbb9d67042f05
4
+ data.tar.gz: ea8063500db6e69974b45b37ab0545fe6cdb316f2dba8fcdca507b6e6050d6e9
5
+ SHA512:
6
+ metadata.gz: 1202cbc808123db06151190557d6db5b30115337a295677a58176797a67eae0acf431459b0c9e2caf0a7b3e1c29325f2c89d4d7d175730eaba1a22355872ce08
7
+ data.tar.gz: 5fa74dfb02d803ed6230cf318f27111275e1f54c28b4de7533f39ec0bcbad41906062859a316d8f86eaad86e50f70e8d754574ef66af9b6ea57770f6a651cb40
data/README.md CHANGED
@@ -86,6 +86,8 @@ Ansi256.bg(226)
86
86
  Ansi256.green
87
87
  Ansi256.on_green
88
88
  Ansi256.bold
89
+ Ansi256.dim
90
+ Ansi256.italic
89
91
  Ansi256.underline
90
92
  Ansi256.reset
91
93
 
@@ -101,7 +103,8 @@ Disabling extended String methods
101
103
  Ansi256.enabled?
102
104
  # true
103
105
 
104
- Ansi256.enabled = false
106
+ # Print colored output only when STDOUT is tty
107
+ Ansi256.enabled = $stdout.tty?
105
108
 
106
109
  "Hello".fg(232)
107
110
  # Hello
@@ -113,7 +116,7 @@ ansi256 executable
113
116
  Ansi256 comes with `ansi256` script which can be used as follows
114
117
 
115
118
  ```bash
116
- usage: ansi256 [-u] <[fg][/bg]> [mesage]
119
+ usage: ansi256 [-b] [-d] [-i] [-u] <[fg][/bg]> [message]
117
120
 
118
121
  # Numeric color codes
119
122
  ansi256 232 "Hello world"
data/ansi256.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "bundler", ">= 2.2.33"
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "minitest"
24
24
  end
data/bin/ansi256 CHANGED
@@ -1,43 +1,45 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  require 'rubygems'
3
5
  require 'ansi256'
4
6
 
5
- bold = ARGV.delete '-b'
6
- underline = ARGV.delete '-u'
7
+ attrs = [
8
+ ARGV.delete('-b') && :bold,
9
+ ARGV.delete('-d') && :dim,
10
+ ARGV.delete('-i') && :italic,
11
+ ARGV.delete('-u') && :underline
12
+ ].compact
7
13
 
8
- if ARGV.length < 1
9
- puts 'usage: ansi256 [-b] [-u] <[fg][/bg]> [message]'
14
+ if ARGV.empty?
15
+ puts 'usage: ansi256 [-b] [-d] [-i] [-u] <[fg][/bg]> [message]'
10
16
  exit 1
11
17
  end
12
18
 
13
- fgbg, *msg = ARGV
14
- fg, bg = fgbg.split('/').map { |e|
15
- if !e.to_s.empty?
16
- case e
17
- when /^#?[0-9a-f]{6}$/i
18
- e
19
- when /^\d+$/
20
- e.to_i
21
- else
22
- e.downcase.to_sym
23
- end
19
+ fgbg, *rest = ARGV
20
+ fg, bg = fgbg.split('/').map do |e|
21
+ next if e.empty?
22
+
23
+ case e
24
+ when /^#?[0-9a-f]{6}$/i then e
25
+ when /^\d+$/ then e.to_i
26
+ else e.downcase.to_sym
24
27
  end
25
- }
28
+ end
26
29
 
27
- def output msg, fg, bg, ul, b
28
- msg = msg.fg(fg) if fg
29
- msg = msg.bg(bg) if bg
30
- msg = msg.underline if ul
31
- msg = msg.bold if b
30
+ output = lambda do |msg|
31
+ msg = msg.fg(fg) if fg
32
+ msg = msg.bg(bg) if bg
33
+ msg = attrs.reduce(msg) { |m, a| m.send(a) }
32
34
  puts msg
33
35
  end
34
36
 
35
- if !msg.empty?
36
- msg.each do |m|
37
- output m, fg, bg, underline, bold
37
+ if !rest.empty?
38
+ rest.each do |m|
39
+ output.call(m)
38
40
  end
39
41
  else
40
- while msg = $stdin.gets
41
- output msg.chomp, fg, bg, underline, bold
42
+ while (msg = $stdin.gets)
43
+ output.call(msg.chomp)
42
44
  end
43
45
  end
data/lib/ansi256/code.rb CHANGED
@@ -2,6 +2,8 @@ module Ansi256
2
2
  CODE = {
3
3
  :reset => 0,
4
4
  :bold => 1,
5
+ :dim => 2,
6
+ :italic => 3,
5
7
  :underline => 4,
6
8
 
7
9
  :black => 30,
@@ -1,3 +1,3 @@
1
1
  module Ansi256
2
- VERSION = "0.2.5"
2
+ VERSION = "0.3.0"
3
3
  end
data/test/test_ansi256.rb CHANGED
@@ -67,6 +67,8 @@ class TestAnsi256 < MiniTest::Unit::TestCase
67
67
  def test_just_code
68
68
  assert_equal "\e[0m", Ansi256.reset
69
69
  assert_equal "\e[1m", Ansi256.bold
70
+ assert_equal "\e[2m", Ansi256.dim
71
+ assert_equal "\e[3m", Ansi256.italic
70
72
  assert_equal "\e[4m", Ansi256.underline
71
73
 
72
74
  assert_equal "\e[30m", Ansi256.black
metadata CHANGED
@@ -1,62 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ansi256
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Junegunn Choi
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-29 00:00:00.000000000 Z
11
+ date: 2021-12-13 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
- version: '1.3'
19
+ version: 2.2.33
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
- version: '1.3'
26
+ version: 2.2.33
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: minitest
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  description: Colorize text using 256-color ANSI codes
@@ -67,7 +60,7 @@ executables:
67
60
  extensions: []
68
61
  extra_rdoc_files: []
69
62
  files:
70
- - .gitignore
63
+ - ".gitignore"
71
64
  - Gemfile
72
65
  - LICENSE.txt
73
66
  - README.md
@@ -82,27 +75,25 @@ files:
82
75
  homepage: https://github.com/junegunn/ansi256
83
76
  licenses:
84
77
  - MIT
85
- post_install_message:
78
+ metadata: {}
79
+ post_install_message:
86
80
  rdoc_options: []
87
81
  require_paths:
88
82
  - lib
89
83
  required_ruby_version: !ruby/object:Gem::Requirement
90
- none: false
91
84
  requirements:
92
- - - ! '>='
85
+ - - ">="
93
86
  - !ruby/object:Gem::Version
94
87
  version: '0'
95
88
  required_rubygems_version: !ruby/object:Gem::Requirement
96
- none: false
97
89
  requirements:
98
- - - ! '>='
90
+ - - ">="
99
91
  - !ruby/object:Gem::Version
100
92
  version: '0'
101
93
  requirements: []
102
- rubyforge_project:
103
- rubygems_version: 1.8.25
104
- signing_key:
105
- specification_version: 3
94
+ rubygems_version: 3.2.3
95
+ signing_key:
96
+ specification_version: 4
106
97
  summary: Colorize text using 256-color ANSI codes
107
98
  test_files:
108
99
  - test/test_ansi256.rb