gif 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/gif +30 -6
  3. data/lib/gif.rb +16 -10
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: df5d965daf0cea888b9da100118187b87bd980ec
4
- data.tar.gz: 805756859d4201846f0f2d2428e9d057e30663f8
3
+ metadata.gz: 4cf12a705f56c94b790ae5ee8ae7683f456a2b6d
4
+ data.tar.gz: 7f155b9efeb3f9e3678280f9693e759fff63aa0b
5
5
  SHA512:
6
- metadata.gz: ab46624bba473846903c1c7e5bb6fffe2582cc2566d1a333ba179808aea89f055598d12286474ee163087def7a56acdd569384219de26262fc25eb88dabd0e64
7
- data.tar.gz: 4fe68766d1f212926c95979d4cc4a0bf10e5031e478009558fca4424b4634dc9949995b4eeb7c8f03ecb828b76105ff5aaaba115423689a435bb19878338aebd
6
+ metadata.gz: 643ab592725b541e6d249e3d22268df0e1e6c921367a9e81ffa429415442168276b253e15274734d85679c2174c45899ed15f1ff4942c5ce168dcce28eaf670a
7
+ data.tar.gz: 1bff06b5daf63cc3476bd0c47f465626396b2317f01ee6601586390a5d42fb54f5c89f9820ce710404df2383fc6e7a598e90d0f68d9d4b8bc374b86ca9a0a8d0
data/bin/gif CHANGED
@@ -1,13 +1,37 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'gif'
4
+ require 'optparse'
4
5
 
5
- if ARGV.join.include? "--setup"
6
- `brew install gifsicle`
7
- `brew tap eddieantonio/eddieantonio`
8
- `brew install imgcat`
9
- else
6
+ loops = 1
7
+
8
+ options = {}
9
+ OptionParser.new do |parser|
10
+ parser.on("--l", "--loops") do |times|
11
+ loops = ARGV.find { |arg| /\A\d+\z/.match(arg).to_s.to_i > 0 }
12
+ end
13
+
14
+ parser.on("--setup", "--s") do |_|
15
+ options[:setup] = true
16
+ puts "Installing dependencies (gifsicle, imgcat) now..."
17
+ `brew install gifsicle`
18
+ `brew tap eddieantonio/eddieantonio`
19
+ `brew install imgcat`
20
+ puts "Finished installing dependencies!"
21
+ end
22
+
23
+ parser.on("--h", "--help", "man") do
24
+ puts [
25
+ "`gif` will play a random gif in your terminal",
26
+ "`gif [search_terms]` will filter by search terms. for example, `gif cute pikachu` will cause you to immediately feel 100% happier.",
27
+ "`--loops` or `--l` will let you loop the gif. for example, `gif cute pikachu --loops 10` will cause you to immediately feel 1000% happier.",
28
+ "`--help`, `--h`, or `man` will print this paragraph."
29
+ ]
30
+ end
31
+ end.parse!
32
+
33
+ if options[:setup].nil?
10
34
  tags = ARGV.join "+"
11
- gif = Gif::CLI.new tags
35
+ gif = Gif::CLI.new tags, loops
12
36
  gif.fetch
13
37
  end
data/lib/gif.rb CHANGED
@@ -1,19 +1,24 @@
1
1
  require 'json'
2
+ require 'tmpdir'
2
3
  require 'digest/sha1'
3
4
 
4
5
  module Gif
5
6
  class CLI
6
- def initialize tags
7
+ def initialize tags, loops
7
8
  @tags = tags
9
+ @loops = loops.to_i
8
10
  end
9
11
 
10
12
  def fetch
11
- generate_url
12
- create_images
13
- rename_files
14
- gif_to_terminal
15
- `rm #{@gif_sha}.gif`
16
- `rm #{@resized_sha}`
13
+ Dir.mktmpdir do |tmp|
14
+ Dir.chdir(tmp)
15
+ generate_url
16
+ create_images
17
+ rename_files
18
+ @loops.times { gif_to_terminal }
19
+ `rm #{@gif_sha}.gif`
20
+ `rm #{@resized_sha}`
21
+ end
17
22
  end
18
23
 
19
24
  private
@@ -48,9 +53,10 @@ module Gif
48
53
  frames.times do |n|
49
54
  system "imgcat -R frames-#{n}"
50
55
  sleep 1.0/24
51
- `rm frames-#{n}`
56
+ `rm frames-#{n}` if @loops < 1
52
57
  system "⌘ k"
53
58
  end
59
+ @loops -= 1
54
60
  end
55
61
 
56
62
  def fix_colors
@@ -63,8 +69,8 @@ module Gif
63
69
  begin
64
70
  original_stderr = $stderr.clone
65
71
  original_stdout = $stdout.clone
66
- $stderr.reopen(File.new('/dev/null', 'w'))
67
- $stdout.reopen(File.new('/dev/null', 'w'))
72
+ $stderr.reopen(File.new("/dev/null", "w"))
73
+ $stdout.reopen(File.new("/dev/null", "w"))
68
74
  retval = yield
69
75
  rescue Exception => e
70
76
  $stdout.reopen(original_stdout)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gif
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lev Kravinsky
@@ -11,7 +11,7 @@ cert_chain: []
11
11
  date: 2016-04-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: running `gif` returns a random gif and `gif [search_term]` filters by
14
- tags. run `gif --setup` to install dependencies.
14
+ tags. run `gif --setup` to install dependencies, and `gif --help` for more info.
15
15
  email: kravinskylev@gmail.com
16
16
  executables:
17
17
  - gif