textbubble 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -0
- data/Rakefile +8 -0
- data/bin/textbubble +120 -0
- data/example.png +0 -0
- data/lib/textbubble.rb +64 -0
- data/lib/textbubble/version.rb +5 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/textbubble_spec.rb +30 -0
- data/textbubble.gemspec +27 -0
- data/textbubble.png +0 -0
- metadata +146 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 02b93239dde00ea8d8c5cebf082c5a35bd133d81
|
4
|
+
data.tar.gz: 2169182602eea48393c0868f0799888a35957fd1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8274be6500b96e9fa5087cf465b5e41d0dd3d55f8f1de5ca4a4cde638c7c0127ebb10f7d4f7667240d92aec24efa8adaa9920894cd61b5dfdf9545696d0f35bd
|
7
|
+
data.tar.gz: 18e9d0cd286a6834b0ed0e672cfd37e7903fca1f04e30edd5324b01f8d23084d9a872ee8942c9726976078ba901e9194e535a98e9a9611e3c006a6c87692bc25
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Joseph Hallett
|
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,39 @@
|
|
1
|
+
# Textbubble
|
2
|
+
|
3
|
+
Creates little text bubbles for your command line.
|
4
|
+
|
5
|
+
<img src="https://raw.githubusercontent.com/bogwonch/textbubble/master/textbubble.png" alt="Demo">
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'textbubble'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install textbubble
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Use the string mixins `lbubble` and `rbubble` to create bubble on the left and right hand side.
|
26
|
+
|
27
|
+
`'Hello World!'.rbubble(margin: 80, width: 60, bg: :red, fg: '#ffffff')`
|
28
|
+
|
29
|
+
<img src="https://raw.githubusercontent.com/bogwonch/textbubble/master/example.png" alt="Example">
|
30
|
+
|
31
|
+
Checkout the command-line app for more options.
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it ( https://github.com/[my-github-username]/textbubble/fork )
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/textbubble
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'textbubble'
|
4
|
+
require 'optparse'
|
5
|
+
require 'terminfo'
|
6
|
+
|
7
|
+
options = { side: :left,
|
8
|
+
fg: :black,
|
9
|
+
bg: :white,
|
10
|
+
margin: TermInfo.screen_size[1],
|
11
|
+
width: (TermInfo.screen_size[1] * 0.6).to_i
|
12
|
+
}
|
13
|
+
|
14
|
+
optparse = OptionParser.new do |opts|
|
15
|
+
opts.banner = 'makes speech bubbles from piped text...'.lbubble
|
16
|
+
|
17
|
+
opts.on('-r',
|
18
|
+
'--right',
|
19
|
+
'bubble on the right'.rbubble(margin: 31, width: 39, bg: :red)
|
20
|
+
) do
|
21
|
+
options[:side] = :right
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.on('-l',
|
25
|
+
'--left',
|
26
|
+
'display bubble on the left (default)'.lbubble(bg: :yellow)
|
27
|
+
) do
|
28
|
+
options[:side] = :left
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on('-m',
|
32
|
+
'--margin WIDTH',
|
33
|
+
"distance to far edge of bubble (default #{options[:margin]})"
|
34
|
+
.lbubble(bg: :green)) \
|
35
|
+
do |width|
|
36
|
+
options[:margin] = width.to_i
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on('-w',
|
40
|
+
'--width WIDTH',
|
41
|
+
"width of bubble (default #{options[:width]})".lbubble(bg: :blue)
|
42
|
+
) do |width|
|
43
|
+
options[:width] = width.to_i
|
44
|
+
end
|
45
|
+
|
46
|
+
opts.on('-f',
|
47
|
+
'--fg COLOR',
|
48
|
+
'color of bubble text (default black or #ffffff)'.lbubble(bg: :cyan)
|
49
|
+
) do |color|
|
50
|
+
case color
|
51
|
+
when 'red'
|
52
|
+
color = :red
|
53
|
+
when 'yellow'
|
54
|
+
color = :yellow
|
55
|
+
when 'green'
|
56
|
+
color = :green
|
57
|
+
when 'blue'
|
58
|
+
color = :blue
|
59
|
+
when 'cyan'
|
60
|
+
color = :cyan
|
61
|
+
when 'magenta'
|
62
|
+
color = :magenta
|
63
|
+
when 'black'
|
64
|
+
color = :black
|
65
|
+
when 'white'
|
66
|
+
color = :white
|
67
|
+
when /#\h{6}/
|
68
|
+
color = color
|
69
|
+
else
|
70
|
+
$stderr.puts "I don't recognise the color: #{color}"
|
71
|
+
exit(1)
|
72
|
+
end
|
73
|
+
options[:fg] = color
|
74
|
+
end
|
75
|
+
|
76
|
+
opts.on('-b',
|
77
|
+
'--bg COLOR',
|
78
|
+
'color of bubble (default white or #000000)'.lbubble(bg: :magenta)
|
79
|
+
) do |color|
|
80
|
+
case color
|
81
|
+
when 'red'
|
82
|
+
color = :red
|
83
|
+
when 'yellow'
|
84
|
+
color = :yellow
|
85
|
+
when 'green'
|
86
|
+
color = :green
|
87
|
+
when 'blue'
|
88
|
+
color = :blue
|
89
|
+
when 'cyan'
|
90
|
+
color = :cyan
|
91
|
+
when 'magenta'
|
92
|
+
color = :magenta
|
93
|
+
when 'black'
|
94
|
+
color = :black
|
95
|
+
when 'wshite'
|
96
|
+
color = :white
|
97
|
+
when /#\h{6}/
|
98
|
+
color = color
|
99
|
+
else
|
100
|
+
$stderr.puts "I don't recognise the color: #{color}"
|
101
|
+
exit(1)
|
102
|
+
end
|
103
|
+
options[:bg] = color
|
104
|
+
end
|
105
|
+
end
|
106
|
+
optparse.parse!
|
107
|
+
|
108
|
+
text = $stdin.read
|
109
|
+
if options[:side] == :left
|
110
|
+
puts text.lbubble(width: options[:width],
|
111
|
+
fg: options[:fg],
|
112
|
+
bg: options[:bg]
|
113
|
+
)
|
114
|
+
else
|
115
|
+
puts text.rbubble(width: options[:width],
|
116
|
+
margin: options[:margin],
|
117
|
+
fg: options[:fg],
|
118
|
+
bg: options[:bg]
|
119
|
+
)
|
120
|
+
end
|
data/example.png
ADDED
Binary file
|
data/lib/textbubble.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'textbubble/version'
|
2
|
+
require 'rainbow/ext/string'
|
3
|
+
|
4
|
+
module Textbubble
|
5
|
+
module String
|
6
|
+
##
|
7
|
+
# Extra methods for Strings implementing Textbubbles
|
8
|
+
module InstanceMethods
|
9
|
+
##
|
10
|
+
# Creates a bubble on the right hand side
|
11
|
+
def rbubble(margin: 80, width: nil, fg: :black, bg: :white)
|
12
|
+
lines = wrap_and_split(width.nil? ? (margin * 0.6).to_i : width)
|
13
|
+
max = lines.map(&:length).max || 0
|
14
|
+
output = ''
|
15
|
+
pad = (margin - max - 3) > 0 ? margin - max - 3 : 0
|
16
|
+
0.upto(lines.length - 2) do |i|
|
17
|
+
output +=
|
18
|
+
' ' * pad + lines[i].pad(max).color(fg).background(bg) + "\n"
|
19
|
+
end if lines.length > 1
|
20
|
+
output += ' ' * pad + lines[-1].pad(max).color(fg).background(bg) +
|
21
|
+
'◣'.color(bg) + "\n"
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Creates a bubble on the left hand side
|
26
|
+
def lbubble(width: 60, fg: :black, bg: :white)
|
27
|
+
lines = wrap_and_split width
|
28
|
+
max = lines.map(&:length).max || 0
|
29
|
+
output = ''
|
30
|
+
0.upto(lines.length - 2) do |i|
|
31
|
+
output += ' ' + lines[i].pad(max).color(fg).background(bg) + "\n"
|
32
|
+
end if lines.length > 1
|
33
|
+
output += '◢'.color(bg) +
|
34
|
+
lines[-1].pad(max).color(fg).background(bg) + "\n"
|
35
|
+
end
|
36
|
+
|
37
|
+
##
|
38
|
+
# Add a space and left justify
|
39
|
+
def pad(max_length)
|
40
|
+
' ' + ljust(max_length) + ' '
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def wrap(margin)
|
46
|
+
margin = 40 if margin.nil? || margin < 2
|
47
|
+
split("\n").collect do |line|
|
48
|
+
if line.length > margin
|
49
|
+
line.gsub(/(.{1,#{margin}})(\s+|$)/, "\\1\n").strip \
|
50
|
+
else
|
51
|
+
line
|
52
|
+
end
|
53
|
+
end * "\n"
|
54
|
+
end
|
55
|
+
|
56
|
+
def wrap_and_split(width)
|
57
|
+
lines = wrap(width).split "\n"
|
58
|
+
lines == [] ? [''] : lines
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
::String.send(:include, Textbubble::String::InstanceMethods)
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'textbubble'
|
3
|
+
|
4
|
+
describe Textbubble do
|
5
|
+
it 'has a version number' do
|
6
|
+
expect(Textbubble::VERSION).not_to be nil
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'does something' do
|
10
|
+
expect('hello'.lbubble.length).to be > 5
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'does\'t crash on an empty input' do
|
14
|
+
expect(''.rbubble.length).to be > 0
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'rbubble does\'t exceed the margins' do
|
18
|
+
text = '1 2 3 4 5 6 7 8 9 0'
|
19
|
+
rbubble = text.rbubble margin: 10
|
20
|
+
rbubble.gsub!(/\e\[[^m]+m/, '')
|
21
|
+
expect(rbubble.split("\n").map(&:length).max).to be <= 10
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'lbubble does\'t exceed the width by too much' do
|
25
|
+
text = '1 2 3 4 5 6 7 8 9 0'
|
26
|
+
lbubble = text.lbubble width: 10
|
27
|
+
lbubble.gsub!(/\e\[[^m]+m/, '')
|
28
|
+
expect(lbubble.split("\n").map(&:length).max).to be <= 12
|
29
|
+
end
|
30
|
+
end
|
data/textbubble.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 'textbubble/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'textbubble'
|
8
|
+
spec.version = Textbubble::VERSION
|
9
|
+
spec.authors = ['bogwonch']
|
10
|
+
spec.email = ['bogwonch@bogwonch.net']
|
11
|
+
spec.summary = 'Turns strings into cute little text bubbles.'
|
12
|
+
spec.homepage = 'https://github.com/bogwonch/textbubble'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(/^(test|spec|features)\//)
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
21
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
22
|
+
spec.add_development_dependency 'rspec'
|
23
|
+
spec.add_development_dependency 'rubocop', '~> 0.29.1'
|
24
|
+
|
25
|
+
spec.add_runtime_dependency 'rainbow', '~> 2.0.0'
|
26
|
+
spec.add_runtime_dependency 'ruby-terminfo', '~> 0.1.1'
|
27
|
+
end
|
data/textbubble.png
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: textbubble
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- bogwonch
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.29.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.29.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rainbow
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.0.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.0.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: ruby-terminfo
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.1.1
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.1.1
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- bogwonch@bogwonch.net
|
100
|
+
executables:
|
101
|
+
- textbubble
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".travis.yml"
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/textbubble
|
113
|
+
- example.png
|
114
|
+
- lib/textbubble.rb
|
115
|
+
- lib/textbubble/version.rb
|
116
|
+
- spec/spec_helper.rb
|
117
|
+
- spec/textbubble_spec.rb
|
118
|
+
- textbubble.gemspec
|
119
|
+
- textbubble.png
|
120
|
+
homepage: https://github.com/bogwonch/textbubble
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.4.3
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: Turns strings into cute little text bubbles.
|
144
|
+
test_files:
|
145
|
+
- spec/spec_helper.rb
|
146
|
+
- spec/textbubble_spec.rb
|