hr 0.0.1
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.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +64 -0
- data/Rakefile +15 -0
- data/bin/hr +25 -0
- data/hr.gemspec +27 -0
- data/lib/hr.rb +29 -0
- data/lib/hr/version.rb +3 -0
- data/spec/hr_spec.rb +62 -0
- data/spec/spec_helper.rb +1 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MTM2YjA0MTg3MjkwNDUzODMzZTMwMjc1N2UwZTAyZDFhYWNjNjFiMA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YzhhYTE3MzA5ZTc4MmRiYzFlMWU4NDQzNTMyMzhmNjRjMjQ5YWYwMw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YmE1N2MyNDVmNDMyZDlkMjgxYmMwMmFkYWM2MTA1Mzg1YTdiMzkxMGZkOWNj
|
10
|
+
ZTIxOGFhODMzMjNmZjg1YmFlYjI2Yzc2ZmJjYjJkOTEzMzljOWE1ZTYwMzVh
|
11
|
+
OGU3MTcyZDI3MDI2OWQzZjUyYmU0MTJlOTgwY2E1NTc5NDUwNWM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NzRkZTY2NTI2ZDc5NDBkZTgxOWVmNWMzMmY2YTU3YjdhMzhlMGJkOGIzOGM3
|
14
|
+
Mjc2ZGFmMmYwOGIwMGRiMzkwM2U4NjU5ODAyMzZjMWU5OGExNTM2ZmYyMzg1
|
15
|
+
YWU1NzI1NWRlZDgxN2I1ZDZmNjZiZTMwY2EwOTg0MDNjY2UwZTg=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Ivan Tse
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Hr
|
2
|
+
|
3
|
+
A `<hr />` tag for your terminal
|
4
|
+
|
5
|
+
|
6
|
+
Use hr to delimit your output for a better separation visually.
|
7
|
+
This small project was inspired by the [bash `hr` script](https://github.com/LuRsT/hr)
|
8
|
+
created by [@LuRsT](https://github.com/LuRsT)
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'hr'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install hr
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
You can use `hr` by itself:
|
27
|
+
|
28
|
+
```
|
29
|
+
~$ hr =
|
30
|
+
====================================== # ... to the end of your terminal window
|
31
|
+
~$ hr -
|
32
|
+
-------------------------------------- # ... to the end of your terminal window
|
33
|
+
~$ hr = - .
|
34
|
+
====================================== # ... to the end of your terminal window
|
35
|
+
-------------------------------------- # ... to the end of your terminal window
|
36
|
+
...................................... # ... to the end of your terminal window
|
37
|
+
|
38
|
+
```
|
39
|
+
|
40
|
+
You can use it in your projects:
|
41
|
+
|
42
|
+
```
|
43
|
+
[1] pry(main)> Hr.print "="
|
44
|
+
====================================== # ... to the end of your terminal window
|
45
|
+
|
46
|
+
```
|
47
|
+
|
48
|
+
`hr` uses the `colorize` gem so you can pass options to color your output.
|
49
|
+
Also, use `string` method to get the string itself.
|
50
|
+
|
51
|
+
```
|
52
|
+
[1] pry(main)> Hr.string "=", :color => :red, :background => :green, :mode => :bold
|
53
|
+
=> "\e[1;31;42m=================================\e[0m"
|
54
|
+
|
55
|
+
```
|
56
|
+
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
1. Fork it
|
61
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
62
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
63
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
64
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
desc "Open a pry session preloaded with this library"
|
4
|
+
task :console do
|
5
|
+
require 'pry'
|
6
|
+
require 'hr'
|
7
|
+
ARGV.clear
|
8
|
+
Pry.start
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'rspec/core/rake_task'
|
12
|
+
|
13
|
+
RSpec::Core::RakeTask.new(:spec)
|
14
|
+
|
15
|
+
task :default => :spec
|
data/bin/hr
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), *%w{ .. lib })
|
4
|
+
|
5
|
+
require 'hr'
|
6
|
+
require 'optparse'
|
7
|
+
|
8
|
+
options = {}
|
9
|
+
option_parser = OptionParser.new do |opts|
|
10
|
+
|
11
|
+
opts.on("-c COLOR") do |color|
|
12
|
+
options[:color] = color
|
13
|
+
end
|
14
|
+
|
15
|
+
opts.on("-b BACKGROUND") do |color|
|
16
|
+
options[:background] = color
|
17
|
+
end
|
18
|
+
|
19
|
+
opts.on("-m MODE") do |mode|
|
20
|
+
options[:mode] = mode
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
option_parser.parse!
|
25
|
+
Hr.print(*ARGV, options)
|
data/hr.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'hr/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "hr"
|
8
|
+
spec.version = Hr::VERSION
|
9
|
+
spec.authors = ["Ivan Tse"]
|
10
|
+
spec.email = ["ivan.tse1@gmail.com"]
|
11
|
+
spec.description = %q{A <hr /> tag for your terminal}
|
12
|
+
spec.summary = %q{Use hr to delimit your output for a better separation visually}
|
13
|
+
spec.homepage = "https://github.com/ivantsepp/hr"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency('colorize', "~> 0.6")
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.1"
|
25
|
+
spec.add_development_dependency "pry", "~> 0.9"
|
26
|
+
spec.add_development_dependency "rspec", "~> 2.14"
|
27
|
+
end
|
data/lib/hr.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require "hr/version"
|
2
|
+
require "colorize"
|
3
|
+
|
4
|
+
module Hr
|
5
|
+
extend self
|
6
|
+
|
7
|
+
def get_column_width
|
8
|
+
column_width = `tput cols`.to_i
|
9
|
+
column_width = 80 if column_width <= 0
|
10
|
+
column_width
|
11
|
+
end
|
12
|
+
|
13
|
+
def print(*patterns)
|
14
|
+
puts string(*patterns)
|
15
|
+
end
|
16
|
+
|
17
|
+
def string(*patterns)
|
18
|
+
options = patterns.last.is_a?(Hash) ? patterns.pop : {}
|
19
|
+
column_width = get_column_width
|
20
|
+
output = patterns.map do |pattern|
|
21
|
+
pattern = pattern.to_s
|
22
|
+
times = (column_width / pattern.length) + 1
|
23
|
+
(pattern * times)[0..column_width - 1]
|
24
|
+
end.join("\n")
|
25
|
+
options = options.inject({}){|tmp,(k,v)| tmp[k.to_sym] = v.to_sym; tmp}
|
26
|
+
options.any? ? output.colorize(options) : output
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/lib/hr/version.rb
ADDED
data/spec/hr_spec.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Hr
|
4
|
+
describe Hr do
|
5
|
+
describe "#get_column_width" do
|
6
|
+
it "gets the console width" do
|
7
|
+
Hr.should_receive(:`).with("tput cols").and_return("200")
|
8
|
+
Hr.get_column_width.should == 200
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns 80 by default" do
|
12
|
+
Hr.should_receive(:`).with("tput cols").and_return(nil)
|
13
|
+
Hr.get_column_width.should == 80
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#string" do
|
18
|
+
before(:each) do
|
19
|
+
Hr.should_receive(:get_column_width).and_return(5)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns the string repeated" do
|
23
|
+
Hr.string("=").should == "====="
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns the string repeated as a pattern" do
|
27
|
+
Hr.string("=+").should == "=+=+="
|
28
|
+
end
|
29
|
+
|
30
|
+
it "returns the string with length equal to console width" do
|
31
|
+
Hr.string("=======").should == "====="
|
32
|
+
end
|
33
|
+
|
34
|
+
it "returns a string with color" do
|
35
|
+
Hr.string("=", :color => :blue).should == "\e[0;34;49m=====\e[0m"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "returns a string with background color" do
|
39
|
+
Hr.string("=", :background => :blue).should == "\e[0;39;44m=====\e[0m"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns a string with mode" do
|
43
|
+
Hr.string("=", :mode => :bold).should == "\e[1;39;49m=====\e[0m"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#print" do
|
48
|
+
before(:each) do
|
49
|
+
Hr.should_receive(:get_column_width).and_return(5)
|
50
|
+
$stdout.should_receive(:puts).with("=====").and_return(nil)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should print the string repeated" do
|
54
|
+
Hr.print("=")
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should not return anything" do
|
58
|
+
Hr.print("=").should == nil
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'hr'
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ivan Tse
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.9'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.14'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.14'
|
83
|
+
description: A <hr /> tag for your terminal
|
84
|
+
email:
|
85
|
+
- ivan.tse1@gmail.com
|
86
|
+
executables:
|
87
|
+
- hr
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- .gitignore
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/hr
|
97
|
+
- hr.gemspec
|
98
|
+
- lib/hr.rb
|
99
|
+
- lib/hr/version.rb
|
100
|
+
- spec/hr_spec.rb
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
homepage: https://github.com/ivantsepp/hr
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ! '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ! '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.1.10
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Use hr to delimit your output for a better separation visually
|
126
|
+
test_files:
|
127
|
+
- spec/hr_spec.rb
|
128
|
+
- spec/spec_helper.rb
|
129
|
+
has_rdoc:
|