funny_terminal 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/funny_terminal +6 -0
- data/bin/setup +7 -0
- data/funny_terminal-0.1.0.gem +0 -0
- data/funny_terminal-0.1.1.gem +0 -0
- data/funny_terminal.gemspec +37 -0
- data/lib/funny_terminal/catpix/private.rb +229 -0
- data/lib/funny_terminal/catpix.rb +99 -0
- data/lib/funny_terminal/constant.rb +3 -0
- data/lib/funny_terminal/quote.rb +24 -0
- data/lib/funny_terminal/version.rb +3 -0
- data/lib/funny_terminal.rb +6 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d27b210f906af9e26c3c7f86d15431d743e013f1
|
4
|
+
data.tar.gz: 8437ba47c08d06756cba840c5530d6d0e9491415
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dbc5c26ce0df70535371bb970d19683e710fd5400a343461b5163361ce8ae7c586a9ab1f3c2c47df301725296019e13b4bfac9ce27b4f87a65dd9212bd246a28
|
7
|
+
data.tar.gz: 3b26b2788788d111cd61b199a473fe05700250d3cae5771aa4b2b60b506f1999c8c7a01b9a072a6a929ee6e3aa3a65154cf12e279598c15363ab3032f267c5fd
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Luu Tuan Anh
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# FunnyTerminal
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/funny_terminal`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'funny_terminal'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install funny_terminal
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/funny_terminal. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "funny_terminal"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/funny_terminal
ADDED
data/bin/setup
ADDED
Binary file
|
Binary file
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'funny_terminal/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "funny_terminal"
|
8
|
+
spec.version = FunnyTerminal::VERSION
|
9
|
+
spec.authors = ["Luu Tuan Anh"]
|
10
|
+
spec.email = ["anhlt@asiantech.vn"]
|
11
|
+
|
12
|
+
spec.summary = %q{Create funny terminal}
|
13
|
+
# spec.description = %q{TODO: Write a longer description or delete this line.}
|
14
|
+
spec.homepage = "http://asiantech.vn"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "bin"
|
27
|
+
# spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.executables = ["funny_terminal"]
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
32
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
33
|
+
|
34
|
+
spec.add_dependency "tco", "~> 0.1", ">= 0.1.8"
|
35
|
+
spec.add_dependency "rmagick", "~> 2.15", ">= 2.15.2"
|
36
|
+
spec.add_dependency "ruby-terminfo", "~> 0.1", ">= 0.1.1"
|
37
|
+
end
|
@@ -0,0 +1,229 @@
|
|
1
|
+
# Copyright (c) 2015 Radek Pazdera <me@radek.io>
|
2
|
+
# Distributed under the MIT License (see LICENSE.txt)
|
3
|
+
|
4
|
+
require "rmagick"
|
5
|
+
require "tco"
|
6
|
+
require "terminfo"
|
7
|
+
require "open-uri"
|
8
|
+
|
9
|
+
module Catpix
|
10
|
+
private
|
11
|
+
MAX_OPACITY = 65535
|
12
|
+
|
13
|
+
def self.default_options
|
14
|
+
{
|
15
|
+
limit_x: 1.0,
|
16
|
+
limit_y: 0,
|
17
|
+
center_x: false,
|
18
|
+
center_y: false,
|
19
|
+
bg: nil,
|
20
|
+
bg_fill: false,
|
21
|
+
resolution: 'auto'
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
@@resolution = nil
|
26
|
+
|
27
|
+
def self.high_res?
|
28
|
+
@@resolution == 'high'
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.can_use_utf8?
|
32
|
+
ENV.values_at("LC_ALL", "LC_CTYPE", "LANG").compact.first.include?("UTF-8")
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.prep_lr_pixel(colour)
|
36
|
+
colour ? " ".bg(colour) : " "
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.print_lr_pixel(colour)
|
40
|
+
print prep_lr_pixel colour
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.prep_hr_pixel(colour_top, colour_bottom)
|
44
|
+
upper = "\u2580"
|
45
|
+
lower = "\u2584"
|
46
|
+
|
47
|
+
return " " if colour_bottom.nil? and colour_top.nil?
|
48
|
+
return lower.fg colour_bottom if colour_top.nil?
|
49
|
+
return upper.fg colour_top if colour_bottom.nil?
|
50
|
+
|
51
|
+
c_top = Tco::match_colour colour_top
|
52
|
+
c_bottom = Tco::match_colour colour_bottom
|
53
|
+
if c_top == c_bottom
|
54
|
+
return " ".bg "@#{c_top}"
|
55
|
+
end
|
56
|
+
|
57
|
+
upper.fg("@#{c_top}").bg("@#{c_bottom}")
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.print_hr_pixel(colour_top, colour_bottom)
|
61
|
+
print prep_hr_pixel colour_top, colour_bottom
|
62
|
+
end
|
63
|
+
|
64
|
+
# Returns normalised size of the terminal window
|
65
|
+
#
|
66
|
+
# Catpix can use either two blank spaces to approximate a pixel in the
|
67
|
+
# temrinal or the 'upper half block' and 'bottom half block' characters.
|
68
|
+
#
|
69
|
+
# Depending on which of the above will be used, the screen size
|
70
|
+
# must be normalised accordingly.
|
71
|
+
def self.get_screen_size
|
72
|
+
th, tw = TermInfo.screen_size
|
73
|
+
if high_res? then [tw, th * 2] else [tw / 2, th] end
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.load_image(path)
|
77
|
+
Magick::Image::read(path).first
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.load_image_from_url(url)
|
81
|
+
img = Magick::ImageList.new
|
82
|
+
urlimg = open(url) # Image Remote URL
|
83
|
+
img.from_blob(urlimg.read)
|
84
|
+
end
|
85
|
+
# Scale the image down based on the limits while keeping the aspect ratio
|
86
|
+
def self.resize!(img, limit_x=0, limit_y=0)
|
87
|
+
tw, th = get_screen_size
|
88
|
+
iw = img.columns
|
89
|
+
ih = img.rows
|
90
|
+
|
91
|
+
width = if limit_x > 0
|
92
|
+
(tw * limit_x).to_i
|
93
|
+
else
|
94
|
+
iw
|
95
|
+
end
|
96
|
+
|
97
|
+
height = if limit_y > 0
|
98
|
+
(th * limit_y).to_i
|
99
|
+
else
|
100
|
+
ih
|
101
|
+
end
|
102
|
+
|
103
|
+
# Resize the image if it's bigger than the limited viewport
|
104
|
+
if iw > width or ih > height
|
105
|
+
img.change_geometry "#{width}x#{height}" do |cols, rows, img_handle|
|
106
|
+
img_handle.resize! (cols).to_i, (rows).to_i
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# Returns the normalised RGB of a ImageMagick's pixel
|
112
|
+
def self.get_normal_rgb(pixel)
|
113
|
+
[pixel.red, pixel.green, pixel.blue].map { |v| 255*(v/65535.0) }
|
114
|
+
end
|
115
|
+
|
116
|
+
# Determine the margins based on the centering options
|
117
|
+
def self.get_margins(img, center_x, center_y)
|
118
|
+
margins = {}
|
119
|
+
tw, th = get_screen_size
|
120
|
+
|
121
|
+
x_space = tw - img.columns
|
122
|
+
if center_x
|
123
|
+
margins[:left] = x_space / 2
|
124
|
+
margins[:right] = x_space / 2 + x_space % 2
|
125
|
+
else
|
126
|
+
margins[:left] = 0
|
127
|
+
margins[:right] = x_space
|
128
|
+
end
|
129
|
+
|
130
|
+
y_space = th - img.rows
|
131
|
+
if center_y
|
132
|
+
margins[:top] = y_space / 2
|
133
|
+
margins[:bottom] = y_space / 2 + y_space % 2
|
134
|
+
else
|
135
|
+
margins[:top] = 0
|
136
|
+
margins[:bottom] = 0
|
137
|
+
end
|
138
|
+
|
139
|
+
if high_res? and margins[:top] % 2 and margins[:bottom] % 2
|
140
|
+
margins[:top] -= 1
|
141
|
+
margins[:bottom] += 1
|
142
|
+
end
|
143
|
+
|
144
|
+
margins
|
145
|
+
end
|
146
|
+
|
147
|
+
def self.prep_vert_margin(size, colour)
|
148
|
+
tw, th = get_screen_size
|
149
|
+
|
150
|
+
buffer = ""
|
151
|
+
if high_res?
|
152
|
+
(size / 2).times do
|
153
|
+
sub_buffer = ""
|
154
|
+
tw.times { sub_buffer += prep_hr_pixel nil, nil }
|
155
|
+
buffer += sub_buffer.bg(colour) + "\n"
|
156
|
+
end
|
157
|
+
else
|
158
|
+
size.times do
|
159
|
+
sub_buffer = ""
|
160
|
+
tw.times { sub_buffer += prep_lr_pixel nil }
|
161
|
+
buffer += sub_buffer.bg(colour) + "\n"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
buffer
|
165
|
+
end
|
166
|
+
|
167
|
+
def self.prep_horiz_margin(size, colour)
|
168
|
+
buffer = ""
|
169
|
+
if high_res?
|
170
|
+
size.times { buffer += prep_hr_pixel nil, nil }
|
171
|
+
else
|
172
|
+
size.times { buffer += prep_lr_pixel nil }
|
173
|
+
end
|
174
|
+
buffer.bg colour
|
175
|
+
end
|
176
|
+
|
177
|
+
# Print the image in low resolution
|
178
|
+
def self.do_print_image_lr(img, margins, options)
|
179
|
+
print prep_vert_margin margins[:top], margins[:colour]
|
180
|
+
|
181
|
+
0.upto(img.rows - 1) do |row|
|
182
|
+
buffer = prep_horiz_margin margins[:left], margins[:colour]
|
183
|
+
0.upto(img.columns - 1) do |col|
|
184
|
+
pixel = img.pixel_color col, row
|
185
|
+
|
186
|
+
buffer += if pixel.opacity == MAX_OPACITY
|
187
|
+
prep_lr_pixel options[:bg]
|
188
|
+
else
|
189
|
+
prep_lr_pixel get_normal_rgb pixel
|
190
|
+
end
|
191
|
+
end
|
192
|
+
buffer += prep_horiz_margin margins[:right], margins[:colour]
|
193
|
+
puts buffer
|
194
|
+
end
|
195
|
+
|
196
|
+
print prep_vert_margin margins[:bottom], margins[:colour]
|
197
|
+
end
|
198
|
+
|
199
|
+
# Print the image in high resolution (using unicode's upper half block)
|
200
|
+
def self.do_print_image_hr(img, margins, options)
|
201
|
+
print prep_vert_margin margins[:top], margins[:colour]
|
202
|
+
|
203
|
+
0.step(img.rows - 1, 2) do |row|
|
204
|
+
# line buffering makes it about 20% faster
|
205
|
+
buffer = prep_horiz_margin margins[:left], margins[:colour]
|
206
|
+
0.upto(img.columns - 1) do |col|
|
207
|
+
top_pixel = img.pixel_color col, row
|
208
|
+
colour_top = if top_pixel.opacity < MAX_OPACITY
|
209
|
+
get_normal_rgb top_pixel
|
210
|
+
else
|
211
|
+
options[:bg]
|
212
|
+
end
|
213
|
+
|
214
|
+
bottom_pixel = img.pixel_color col, row + 1
|
215
|
+
colour_bottom = if bottom_pixel.opacity < MAX_OPACITY
|
216
|
+
get_normal_rgb bottom_pixel
|
217
|
+
else
|
218
|
+
options[:bg]
|
219
|
+
end
|
220
|
+
|
221
|
+
buffer += prep_hr_pixel colour_top, colour_bottom
|
222
|
+
end
|
223
|
+
buffer += prep_horiz_margin margins[:right], margins[:colour]
|
224
|
+
puts buffer
|
225
|
+
end
|
226
|
+
|
227
|
+
print prep_vert_margin margins[:bottom], margins[:colour]
|
228
|
+
end
|
229
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# Copyright (c) 2015 Radek Pazdera <me@radek.io>
|
2
|
+
# Distributed under the MIT License (see LICENSE.txt)
|
3
|
+
|
4
|
+
require "funny_terminal/catpix/private"
|
5
|
+
|
6
|
+
# Provides a function to print images in the terminal. A range of different
|
7
|
+
# formats is supported (check out what ImageMagick supports). Under the hood,
|
8
|
+
# this module uses two components:
|
9
|
+
#
|
10
|
+
# * [rmagick](https://rmagick.github.io/) to read and scale the images and
|
11
|
+
# * [tco](https://github.com/pazdera/tco) to map their pixels on the extended
|
12
|
+
# colour palette in the terminal.
|
13
|
+
#
|
14
|
+
# Some other minor features like centering and handling background colours
|
15
|
+
# are supplied directly by this module.
|
16
|
+
module Catpix
|
17
|
+
# Print an image to the terminal.
|
18
|
+
#
|
19
|
+
# All formats supported by ImageMagick are supported. The image's colours
|
20
|
+
# will be mapped onto the extended 256 colour palette. Also by default, it
|
21
|
+
# will be scaled down to fit the width of the terminal while keeping its
|
22
|
+
# proportions. This can be changed using the `options` parameter.
|
23
|
+
#
|
24
|
+
# @param [Hash] options Adjust some parameters of the image when printed.
|
25
|
+
# @option options [Float] :limit_x A factor of the terminal window's width.
|
26
|
+
# If present, the image will be scaled down
|
27
|
+
# to fit (proportions are kept). Using 0
|
28
|
+
# will disable the scaling. [default: 1.0]
|
29
|
+
# @option options [Float] :limit_y A factor of the terminal window's height.
|
30
|
+
# If present, the image will be scaled down
|
31
|
+
# to fit (proportions are kept). Using 0
|
32
|
+
# will disable the scaling. [default: 0]
|
33
|
+
# @option options [Boolean] :center_x Center the image horizontally in the
|
34
|
+
# terminal window. [default: false]
|
35
|
+
# @option options [Boolean] :center_y Center the image vertically in the
|
36
|
+
# terminal window. [default: false]
|
37
|
+
# @option options [String] :bg Background colour to use in case there are
|
38
|
+
# any fully transparent pixels in the image.
|
39
|
+
# This can be a RGB value '#c0ffee' or a tco
|
40
|
+
# alias 'red' or 'blue'. [default: nil]
|
41
|
+
# @option options [Boolean] :bg_fill Fill the margins around the image with
|
42
|
+
# background colour. [default: false]
|
43
|
+
# @option options [String] :resolution Determines the pixel size of the
|
44
|
+
# rendered image. Can be set to `high`,
|
45
|
+
# `low` or `auto` (default). If set to
|
46
|
+
# `auto` the resolution will be picked
|
47
|
+
# automatically based on your terminal's
|
48
|
+
# support of unicode.
|
49
|
+
def self.print_image(path, options={})
|
50
|
+
options = default_options.merge! options
|
51
|
+
|
52
|
+
if options[:resolution] == 'auto'
|
53
|
+
options[:resolution] = can_use_utf8? ? 'high' : 'low'
|
54
|
+
end
|
55
|
+
@@resolution = options[:resolution]
|
56
|
+
|
57
|
+
img = load_image path
|
58
|
+
resize! img, options[:limit_x], options[:limit_y]
|
59
|
+
|
60
|
+
margins = get_margins img, options[:center_x], options[:center_y]
|
61
|
+
margins[:colour] = options[:bg_fill] ? options[:bg] : nil
|
62
|
+
|
63
|
+
if high_res?
|
64
|
+
do_print_image_hr img, margins, options
|
65
|
+
else
|
66
|
+
do_print_image_lr img, margins, options
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.print_image_url(url)
|
71
|
+
options = {
|
72
|
+
resolution: 'auto',
|
73
|
+
limit_x: 0.5,
|
74
|
+
limit_y: 0,
|
75
|
+
center_x: true,
|
76
|
+
center_y: true,
|
77
|
+
bg: "white",
|
78
|
+
bg_fill: true,
|
79
|
+
}
|
80
|
+
|
81
|
+
if options[:resolution] == 'auto'
|
82
|
+
options[:resolution] = can_use_utf8? ? 'high' : 'low'
|
83
|
+
end
|
84
|
+
@@resolution = options[:resolution]
|
85
|
+
|
86
|
+
img = load_image_from_url url
|
87
|
+
|
88
|
+
resize! img, options[:limit_x], options[:limit_y]
|
89
|
+
|
90
|
+
margins = get_margins img, options[:center_x], options[:center_y]
|
91
|
+
margins[:colour] = options[:bg_fill] ? options[:bg] : nil
|
92
|
+
|
93
|
+
if high_res?
|
94
|
+
do_print_image_hr img, margins, options
|
95
|
+
else
|
96
|
+
do_print_image_lr img, margins, options
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "funny_terminal/catpix"
|
2
|
+
require "net/http"
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
module FunnyTerminal
|
6
|
+
class Quote
|
7
|
+
def self.request
|
8
|
+
url = API_SERVER + "quotes/random"
|
9
|
+
puts url
|
10
|
+
uri = URI(url)
|
11
|
+
response = Net::HTTP.get(uri)
|
12
|
+
json = JSON.parse(response)
|
13
|
+
|
14
|
+
print(json)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.print(json)
|
18
|
+
quote = json["quote"]
|
19
|
+
puts quote["message"]
|
20
|
+
puts quote["author"]
|
21
|
+
Catpix::print_image_url quote["image"]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: funny_terminal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Luu Tuan Anh
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-05 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.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
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: tco
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.1'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 0.1.8
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0.1'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.1.8
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rmagick
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '2.15'
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 2.15.2
|
71
|
+
type: :runtime
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '2.15'
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 2.15.2
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: ruby-terminfo
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0.1'
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 0.1.1
|
91
|
+
type: :runtime
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0.1'
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 0.1.1
|
101
|
+
description:
|
102
|
+
email:
|
103
|
+
- anhlt@asiantech.vn
|
104
|
+
executables:
|
105
|
+
- funny_terminal
|
106
|
+
extensions: []
|
107
|
+
extra_rdoc_files: []
|
108
|
+
files:
|
109
|
+
- ".gitignore"
|
110
|
+
- ".travis.yml"
|
111
|
+
- CODE_OF_CONDUCT.md
|
112
|
+
- Gemfile
|
113
|
+
- LICENSE.txt
|
114
|
+
- README.md
|
115
|
+
- Rakefile
|
116
|
+
- bin/console
|
117
|
+
- bin/funny_terminal
|
118
|
+
- bin/setup
|
119
|
+
- funny_terminal-0.1.0.gem
|
120
|
+
- funny_terminal-0.1.1.gem
|
121
|
+
- funny_terminal.gemspec
|
122
|
+
- lib/funny_terminal.rb
|
123
|
+
- lib/funny_terminal/catpix.rb
|
124
|
+
- lib/funny_terminal/catpix/private.rb
|
125
|
+
- lib/funny_terminal/constant.rb
|
126
|
+
- lib/funny_terminal/quote.rb
|
127
|
+
- lib/funny_terminal/version.rb
|
128
|
+
homepage: http://asiantech.vn
|
129
|
+
licenses:
|
130
|
+
- MIT
|
131
|
+
metadata:
|
132
|
+
allowed_push_host: https://rubygems.org
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
requirements: []
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 2.4.8
|
150
|
+
signing_key:
|
151
|
+
specification_version: 4
|
152
|
+
summary: Create funny terminal
|
153
|
+
test_files: []
|