hr 0.0.1 → 0.0.2

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.
Files changed (6) hide show
  1. checksums.yaml +5 -13
  2. data/README.md +0 -3
  3. data/bin/hr +15 -5
  4. data/lib/hr.rb +25 -3
  5. data/lib/hr/version.rb +1 -1
  6. metadata +16 -17
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MTM2YjA0MTg3MjkwNDUzODMzZTMwMjc1N2UwZTAyZDFhYWNjNjFiMA==
5
- data.tar.gz: !binary |-
6
- YzhhYTE3MzA5ZTc4MmRiYzFlMWU4NDQzNTMyMzhmNjRjMjQ5YWYwMw==
2
+ SHA1:
3
+ metadata.gz: 06a46e52a822aa039b4d61b3b22e9e1dc3419bda
4
+ data.tar.gz: 516e9615b22d19e2e424b7b55c8c7af88dec5700
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YmE1N2MyNDVmNDMyZDlkMjgxYmMwMmFkYWM2MTA1Mzg1YTdiMzkxMGZkOWNj
10
- ZTIxOGFhODMzMjNmZjg1YmFlYjI2Yzc2ZmJjYjJkOTEzMzljOWE1ZTYwMzVh
11
- OGU3MTcyZDI3MDI2OWQzZjUyYmU0MTJlOTgwY2E1NTc5NDUwNWM=
12
- data.tar.gz: !binary |-
13
- NzRkZTY2NTI2ZDc5NDBkZTgxOWVmNWMzMmY2YTU3YjdhMzhlMGJkOGIzOGM3
14
- Mjc2ZGFmMmYwOGIwMGRiMzkwM2U4NjU5ODAyMzZjMWU5OGExNTM2ZmYyMzg1
15
- YWU1NzI1NWRlZDgxN2I1ZDZmNjZiZTMwY2EwOTg0MDNjY2UwZTg=
6
+ metadata.gz: 4945223d0acfa894904c9065a31124f0666ffe62df10ad0a86178adb7695fba7f9ae758920982ca20bb8d2aa1939781cc11f6da09a3b5dba9d926bb4feef1379
7
+ data.tar.gz: 0392c2acd4a06f594e370bdf2e03e4ae13bd771395ad00aae259592d2d6a1f3b9ea2a2c12f5f647cbebb82e10dab65edf8133d58f222d7f46b92f0f470fa97d4
data/README.md CHANGED
@@ -34,7 +34,6 @@ You can use `hr` by itself:
34
34
  ====================================== # ... to the end of your terminal window
35
35
  -------------------------------------- # ... to the end of your terminal window
36
36
  ...................................... # ... to the end of your terminal window
37
-
38
37
  ```
39
38
 
40
39
  You can use it in your projects:
@@ -42,7 +41,6 @@ You can use it in your projects:
42
41
  ```
43
42
  [1] pry(main)> Hr.print "="
44
43
  ====================================== # ... to the end of your terminal window
45
-
46
44
  ```
47
45
 
48
46
  `hr` uses the `colorize` gem so you can pass options to color your output.
@@ -51,7 +49,6 @@ Also, use `string` method to get the string itself.
51
49
  ```
52
50
  [1] pry(main)> Hr.string "=", :color => :red, :background => :green, :mode => :bold
53
51
  => "\e[1;31;42m=================================\e[0m"
54
-
55
52
  ```
56
53
 
57
54
 
data/bin/hr CHANGED
@@ -1,22 +1,32 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $:.unshift File.join(File.dirname(__FILE__), *%w{ .. lib })
4
-
5
3
  require 'hr'
6
4
  require 'optparse'
7
5
 
8
6
  options = {}
7
+ available_colors = []
8
+ String.colors.map(&:to_s)
9
+ .reject{ |a| a == "default" }
10
+ .each_slice(6) { |a| available_colors << a.join(' ') }
11
+ available_colors.map!{ |a| ' ' << a }
12
+
13
+ available_modes = String.modes.map(&:to_s)
14
+ available_modes.delete("default")
9
15
  option_parser = OptionParser.new do |opts|
16
+ executable_name = File.basename($PROGRAM_NAME)
17
+ opts.banner = "<hr /> for your terminal
18
+
19
+ Usage: #{executable_name} [options] pattern"
10
20
 
11
- opts.on("-c COLOR") do |color|
21
+ opts.on("-c COLOR", "color of the text", *available_colors) do |color|
12
22
  options[:color] = color
13
23
  end
14
24
 
15
- opts.on("-b BACKGROUND") do |color|
25
+ opts.on("-b BACKGROUND", "color of the background", *available_colors) do |color|
16
26
  options[:background] = color
17
27
  end
18
28
 
19
- opts.on("-m MODE") do |mode|
29
+ opts.on("-m MODE", "the text mode", ' ' << available_modes.join(' ')) do |mode|
20
30
  options[:mode] = mode
21
31
  end
22
32
  end
data/lib/hr.rb CHANGED
@@ -5,9 +5,23 @@ module Hr
5
5
  extend self
6
6
 
7
7
  def get_column_width
8
- column_width = `tput cols`.to_i
9
- column_width = 80 if column_width <= 0
10
- column_width
8
+ column_width = 0
9
+
10
+ if command_exists?('tput')
11
+ column_width = `tput cols`.to_i
12
+ elsif command_exists?('stty')
13
+ column_width = `stty size`.split.last.to_i
14
+ elsif command_exists?('mode')
15
+ mode_output = `mode`.split
16
+ column_width = mode_output[mode_output.index('Columns:')+1].to_i
17
+ end
18
+
19
+ case
20
+ when column_width.nil?, column_width <= 0
21
+ return 80
22
+ else
23
+ return column_width
24
+ end
11
25
  end
12
26
 
13
27
  def print(*patterns)
@@ -25,5 +39,13 @@ module Hr
25
39
  options = options.inject({}){|tmp,(k,v)| tmp[k.to_sym] = v.to_sym; tmp}
26
40
  options.any? ? output.colorize(options) : output
27
41
  end
42
+
43
+ private
44
+
45
+ def command_exists?(command)
46
+ ENV['PATH'].split(File::PATH_SEPARATOR).any? { |path|
47
+ (File.exist? File.join(path, "#{command}")) || (File.exist? File.join(path, "#{command}.com")) || (File.exist? File.join(path, "#{command}.exe"))
48
+ }
49
+ end
28
50
 
29
51
  end
data/lib/hr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hr
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Tse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-12 00:00:00.000000000 Z
11
+ date: 2015-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0.6'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '10.1'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0.9'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.9'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '2.14'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '2.14'
83
83
  description: A <hr /> tag for your terminal
@@ -88,7 +88,7 @@ executables:
88
88
  extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
- - .gitignore
91
+ - ".gitignore"
92
92
  - Gemfile
93
93
  - LICENSE.txt
94
94
  - README.md
@@ -109,21 +109,20 @@ require_paths:
109
109
  - lib
110
110
  required_ruby_version: !ruby/object:Gem::Requirement
111
111
  requirements:
112
- - - ! '>='
112
+ - - ">="
113
113
  - !ruby/object:Gem::Version
114
114
  version: '0'
115
115
  required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  requirements:
117
- - - ! '>='
117
+ - - ">="
118
118
  - !ruby/object:Gem::Version
119
119
  version: '0'
120
120
  requirements: []
121
121
  rubyforge_project:
122
- rubygems_version: 2.1.10
122
+ rubygems_version: 2.2.2
123
123
  signing_key:
124
124
  specification_version: 4
125
125
  summary: Use hr to delimit your output for a better separation visually
126
126
  test_files:
127
127
  - spec/hr_spec.rb
128
128
  - spec/spec_helper.rb
129
- has_rdoc: