lolcommits 0.17.2 → 0.17.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/{build.yml → ci.yml} +29 -24
- data/.gitignore +2 -0
- data/.quickhook/pre-commit/ruby-lint +3 -0
- data/.rubocop.yml +309 -9
- data/CHANGELOG.md +45 -234
- data/CODE_OF_CONDUCT.md +10 -12
- data/Gemfile +4 -2
- data/README.md +14 -26
- data/Rakefile +11 -48
- data/bin/cucumber +25 -0
- data/bin/lolcommits +2 -12
- data/bin/rubocop +25 -0
- data/features/step_definitions/lolcommits_steps.rb +0 -2
- data/features/support/env.rb +1 -3
- data/features/support/path_helpers.rb +2 -4
- data/lib/core_ext/mercurial-ruby/changed_file.rb +1 -3
- data/lib/core_ext/mercurial-ruby/command.rb +2 -4
- data/lib/core_ext/mercurial-ruby/config_file.rb +0 -2
- data/lib/core_ext/mercurial-ruby/repository.rb +0 -2
- data/lib/core_ext/mercurial-ruby/shell.rb +1 -3
- data/lib/lolcommits/animated_gif.rb +12 -7
- data/lib/lolcommits/backends/git_info.rb +6 -8
- data/lib/lolcommits/backends/installation_git.rb +8 -10
- data/lib/lolcommits/backends/installation_mercurial.rb +8 -10
- data/lib/lolcommits/backends/mercurial_info.rb +9 -11
- data/lib/lolcommits/capturer/capture_cygwin.rb +0 -2
- data/lib/lolcommits/capturer/capture_fake.rb +2 -4
- data/lib/lolcommits/capturer/capture_linux.rb +4 -6
- data/lib/lolcommits/capturer/capture_linux_video.rb +1 -3
- data/lib/lolcommits/capturer/capture_mac.rb +2 -4
- data/lib/lolcommits/capturer/capture_mac_video.rb +1 -3
- data/lib/lolcommits/capturer/capture_windows.rb +2 -4
- data/lib/lolcommits/capturer/capture_windows_video.rb +5 -7
- data/lib/lolcommits/capturer.rb +9 -12
- data/lib/lolcommits/cli/fatals.rb +11 -16
- data/lib/lolcommits/cli/launcher.rb +1 -3
- data/lib/lolcommits/cli/process_runner.rb +2 -4
- data/lib/lolcommits/cli/timelapse_gif.rb +7 -9
- data/lib/lolcommits/cli.rb +6 -6
- data/lib/lolcommits/configuration.rb +32 -36
- data/lib/lolcommits/gem_plugin.rb +5 -7
- data/lib/lolcommits/installation.rb +5 -7
- data/lib/lolcommits/platform.rb +14 -18
- data/lib/lolcommits/plugin/base.rb +4 -8
- data/lib/lolcommits/plugin/configuration_helper.rb +4 -6
- data/lib/lolcommits/plugin_manager.rb +1 -3
- data/lib/lolcommits/runner.rb +16 -21
- data/lib/lolcommits/test_helpers/fake_io.rb +0 -2
- data/lib/lolcommits/test_helpers/git_repo.rb +3 -5
- data/lib/lolcommits/vcs_info.rb +2 -4
- data/lib/lolcommits/version.rb +1 -3
- data/lib/lolcommits.rb +26 -30
- data/lolcommits.gemspec +23 -24
- data/test/permissions_test.rb +7 -9
- data/test/test_helper.rb +2 -4
- metadata +62 -53
- data/.gitattributes +0 -1
- data/.github/workflows/push_gem.yml +0 -25
- data/.rubocop_todo.yml +0 -97
- data/.travis.yml +0 -45
- data/bin/console +0 -12
@@ -1,7 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'lolcommits/platform'
|
4
|
-
require 'optparse_plus'
|
1
|
+
require "lolcommits/platform"
|
2
|
+
require "optparse_plus"
|
5
3
|
|
6
4
|
module Lolcommits
|
7
5
|
module CLI
|
@@ -16,15 +14,14 @@ module Lolcommits
|
|
16
14
|
def self.die_on_fatal_platform_conditions!
|
17
15
|
# make sure the capture binaries are in a good state
|
18
16
|
if Platform.platform_mac?
|
19
|
-
%w
|
20
|
-
next if File.executable? File.join(Configuration::LOLCOMMITS_ROOT,
|
17
|
+
%w[imagesnap videosnap].each do |executable|
|
18
|
+
next if File.executable? File.join(Configuration::LOLCOMMITS_ROOT, "vendor", "ext", executable, executable)
|
21
19
|
|
22
|
-
fatal "Couldn't properly execute #{executable} for some reason, "
|
23
|
-
'please file a bug?!'
|
20
|
+
fatal "Couldn't properly execute #{executable} for some reason, " + "please file a bug?!"
|
24
21
|
exit 1
|
25
22
|
end
|
26
23
|
elsif Platform.platform_linux?
|
27
|
-
unless Platform.command_which(
|
24
|
+
unless Platform.command_which("mplayer")
|
28
25
|
fatal "Couldn't find mplayer in your PATH!"
|
29
26
|
exit 1
|
30
27
|
end
|
@@ -32,16 +29,14 @@ module Lolcommits
|
|
32
29
|
|
33
30
|
# make sure imagemagick is around and good to go
|
34
31
|
unless Platform.valid_imagemagick_installed?
|
35
|
-
fatal
|
36
|
-
'(or version is too old)'
|
32
|
+
fatal "FATAL: ImageMagick does not appear to be properly installed!(or version is too old)"
|
37
33
|
exit 1
|
38
34
|
end
|
39
35
|
|
40
36
|
# check for a error condition with git config affecting ruby-git
|
41
37
|
return unless Platform.git_config_color_always?
|
42
38
|
|
43
|
-
fatal
|
44
|
-
"cannot be set to 'always'."
|
39
|
+
fatal "Due to a bug in the ruby-git library, git config for color.ui " + "cannot be set to 'always'."
|
45
40
|
fatal "Try setting it to 'auto' instead!"
|
46
41
|
exit 1
|
47
42
|
end
|
@@ -52,15 +47,15 @@ module Lolcommits
|
|
52
47
|
def self.die_if_no_valid_ffmpeg_installed!
|
53
48
|
return if Platform.valid_ffmpeg_installed?
|
54
49
|
|
55
|
-
fatal
|
50
|
+
fatal "FATAL: ffmpeg does not appear to be properly installed!"
|
56
51
|
exit 1
|
57
52
|
end
|
58
53
|
|
59
54
|
# If we are not in a git repo, we can't do git related things!
|
60
55
|
# Die with an informative error message in that case.
|
61
56
|
def self.die_if_not_vcs_repo!
|
62
|
-
debug
|
63
|
-
current = File.expand_path(
|
57
|
+
debug "Checking for valid VCS repo"
|
58
|
+
current = File.expand_path(".")
|
64
59
|
parent = File.dirname(current)
|
65
60
|
while current != parent
|
66
61
|
return if VCSInfo.repo_root?(current)
|
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'fileutils'
|
1
|
+
require "fileutils"
|
4
2
|
|
5
3
|
module Lolcommits
|
6
4
|
module CLI
|
@@ -43,7 +41,7 @@ module Lolcommits
|
|
43
41
|
end
|
44
42
|
|
45
43
|
def pid_file
|
46
|
-
File.join(@configuration.loldir,
|
44
|
+
File.join(@configuration.loldir, "lolcommits.pid")
|
47
45
|
end
|
48
46
|
end
|
49
47
|
end
|
@@ -1,7 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'lolcommits/cli/fatals'
|
4
|
-
require 'mini_magick'
|
1
|
+
require "lolcommits/cli/fatals"
|
2
|
+
require "mini_magick"
|
5
3
|
|
6
4
|
module Lolcommits
|
7
5
|
module CLI
|
@@ -16,7 +14,7 @@ module Lolcommits
|
|
16
14
|
# param args [String] the arg passed to the gif command on CLI (optional)
|
17
15
|
def run(args = nil)
|
18
16
|
case args
|
19
|
-
when
|
17
|
+
when "today"
|
20
18
|
lolimages = jpg_images_today
|
21
19
|
filename = Date.today.to_s
|
22
20
|
else
|
@@ -25,11 +23,11 @@ module Lolcommits
|
|
25
23
|
end
|
26
24
|
|
27
25
|
if lolimages.empty?
|
28
|
-
warn
|
26
|
+
warn "No lolcommits have been captured for this time yet."
|
29
27
|
exit 1
|
30
28
|
end
|
31
29
|
|
32
|
-
puts
|
30
|
+
puts "*** Generating animated timelapse gif."
|
33
31
|
|
34
32
|
MiniMagick.convert do |convert|
|
35
33
|
convert.delay 50
|
@@ -46,7 +44,7 @@ module Lolcommits
|
|
46
44
|
attr_accessor :loldir
|
47
45
|
|
48
46
|
def jpg_images
|
49
|
-
Dir.glob(File.join(loldir,
|
47
|
+
Dir.glob(File.join(loldir, "*.jpg")).sort_by { |f| File.mtime(f) }
|
50
48
|
end
|
51
49
|
|
52
50
|
def jpg_images_today
|
@@ -54,7 +52,7 @@ module Lolcommits
|
|
54
52
|
end
|
55
53
|
|
56
54
|
def timelapses_dir_path
|
57
|
-
dir = File.join(loldir,
|
55
|
+
dir = File.join(loldir, "timelapses")
|
58
56
|
FileUtils.mkdir_p(dir)
|
59
57
|
dir
|
60
58
|
end
|
data/lib/lolcommits/cli.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
1
|
+
require "optparse"
|
2
|
+
require "optparse_plus"
|
3
|
+
require "lolcommits/cli/fatals"
|
4
|
+
require "lolcommits/cli/launcher"
|
5
|
+
require "lolcommits/cli/process_runner"
|
6
|
+
require "lolcommits/cli/timelapse_gif"
|
@@ -1,24 +1,41 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Lolcommits
|
4
2
|
class Configuration
|
5
|
-
LOLCOMMITS_BASE = ENV[
|
6
|
-
LOLCOMMITS_ROOT = File.join(File.dirname(__FILE__),
|
3
|
+
LOLCOMMITS_BASE = ENV["LOLCOMMITS_DIR"] || File.join(Dir.home, ".lolcommits")
|
4
|
+
LOLCOMMITS_ROOT = File.join(File.dirname(__FILE__), "../..")
|
7
5
|
|
8
6
|
attr_accessor :plugin_manager
|
9
7
|
attr_writer :loldir
|
10
8
|
|
9
|
+
def self.loldir_for(basename)
|
10
|
+
loldir = File.join(LOLCOMMITS_BASE, basename)
|
11
|
+
|
12
|
+
if File.directory? loldir
|
13
|
+
begin
|
14
|
+
# ensure 755 permissions for loldir
|
15
|
+
File.chmod(0o755, loldir)
|
16
|
+
rescue Errno::EPERM
|
17
|
+
# abort if permissions cannot be met
|
18
|
+
puts "FATAL: directory '#{loldir}' should be present and writeable by user '#{ENV.fetch('USER', nil)}'"
|
19
|
+
puts "Try changing the directory permissions to 755"
|
20
|
+
exit 1
|
21
|
+
end
|
22
|
+
else
|
23
|
+
FileUtils.mkdir_p loldir
|
24
|
+
end
|
25
|
+
loldir
|
26
|
+
end
|
27
|
+
|
11
28
|
def initialize(plugin_manager, test_mode: false)
|
12
29
|
@plugin_manager = plugin_manager
|
13
|
-
@loldir = Configuration.loldir_for(
|
30
|
+
@loldir = Configuration.loldir_for("test") if test_mode
|
14
31
|
end
|
15
32
|
|
16
33
|
def yaml
|
17
34
|
@yaml ||= if File.exist?(configuration_file)
|
18
|
-
YAML.safe_load(File.open(configuration_file), permitted_classes: [Symbol]) || Hash.new({})
|
19
|
-
|
35
|
+
YAML.safe_load(File.open(configuration_file), permitted_classes: [ Symbol ]) || Hash.new({})
|
36
|
+
else
|
20
37
|
Hash.new({})
|
21
|
-
|
38
|
+
end
|
22
39
|
end
|
23
40
|
|
24
41
|
def configuration_file
|
@@ -30,11 +47,11 @@ module Lolcommits
|
|
30
47
|
|
31
48
|
basename ||= if VCSInfo.repo_root?
|
32
49
|
VCSInfo.local_name
|
33
|
-
|
50
|
+
else
|
34
51
|
File.basename(Dir.getwd)
|
35
|
-
|
36
|
-
basename.sub!(/^\./,
|
37
|
-
basename.sub!(/ /,
|
52
|
+
end
|
53
|
+
basename.sub!(/^\./, "dot")
|
54
|
+
basename.sub!(/ /, "-")
|
38
55
|
@loldir = Configuration.loldir_for(basename)
|
39
56
|
end
|
40
57
|
|
@@ -42,7 +59,7 @@ module Lolcommits
|
|
42
59
|
File.join loldir, "#{sha}.#{ext}"
|
43
60
|
end
|
44
61
|
|
45
|
-
def capture_path(ext =
|
62
|
+
def capture_path(ext = "jpg")
|
46
63
|
File.join loldir, "raw_capture.#{ext}"
|
47
64
|
end
|
48
65
|
|
@@ -68,7 +85,7 @@ module Lolcommits
|
|
68
85
|
|
69
86
|
def ask_for_plugin_name
|
70
87
|
list_plugins
|
71
|
-
print
|
88
|
+
print "Name of plugin to configure: "
|
72
89
|
gets.strip
|
73
90
|
end
|
74
91
|
|
@@ -94,7 +111,7 @@ module Lolcommits
|
|
94
111
|
ensure
|
95
112
|
if plugin
|
96
113
|
# clean away legacy enabled key, later we can remove this
|
97
|
-
plugin_config.delete(
|
114
|
+
plugin_config.delete("enabled")
|
98
115
|
# save plugin config (if we have anything in the hash)
|
99
116
|
save(plugin.name, plugin_config) unless plugin_config.empty?
|
100
117
|
|
@@ -114,26 +131,5 @@ module Lolcommits
|
|
114
131
|
def to_s
|
115
132
|
yaml.to_yaml.to_s
|
116
133
|
end
|
117
|
-
|
118
|
-
# class methods
|
119
|
-
|
120
|
-
def self.loldir_for(basename)
|
121
|
-
loldir = File.join(LOLCOMMITS_BASE, basename)
|
122
|
-
|
123
|
-
if File.directory? loldir
|
124
|
-
begin
|
125
|
-
# ensure 755 permissions for loldir
|
126
|
-
File.chmod(0o755, loldir)
|
127
|
-
rescue Errno::EPERM
|
128
|
-
# abort if permissions cannot be met
|
129
|
-
puts "FATAL: directory '#{loldir}' should be present and writeable by user '#{ENV.fetch('USER', nil)}'"
|
130
|
-
puts 'Try changing the directory permissions to 755'
|
131
|
-
exit 1
|
132
|
-
end
|
133
|
-
else
|
134
|
-
FileUtils.mkdir_p loldir
|
135
|
-
end
|
136
|
-
loldir
|
137
|
-
end
|
138
134
|
end
|
139
135
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Lolcommits
|
4
2
|
class GemPlugin
|
5
3
|
attr_accessor :gem_spec, :required
|
@@ -51,22 +49,22 @@ module Lolcommits
|
|
51
49
|
end
|
52
50
|
|
53
51
|
def name
|
54
|
-
gem_name.split(
|
52
|
+
gem_name.split("-", 2).last
|
55
53
|
end
|
56
54
|
|
57
55
|
private
|
58
56
|
|
59
57
|
def gem_path
|
60
|
-
gem_name.tr(
|
58
|
+
gem_name.tr("-", "/")
|
61
59
|
end
|
62
60
|
|
63
61
|
def plugin_klass_name
|
64
62
|
# convert gem paths to plugin classes e.g.
|
65
63
|
# lolcommits/loltext --> Lolcommits::Plugin::Loltext
|
66
64
|
# lolcommits/term_output --> Lolcommits::Plugin::TermOutput
|
67
|
-
gem_path.split(
|
68
|
-
c.split(
|
69
|
-
end.join(
|
65
|
+
gem_path.split("/").insert(1, "plugin").collect do |c|
|
66
|
+
c.split("_").collect(&:capitalize).join
|
67
|
+
end.join("::")
|
70
68
|
end
|
71
69
|
end
|
72
70
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Lolcommits
|
4
2
|
#
|
5
3
|
# Methods to handle enabling and disabling of lolcommits
|
@@ -23,9 +21,9 @@ module Lolcommits
|
|
23
21
|
capture_args = extract_capture_args(options)
|
24
22
|
path = backend.do_enable(capture_args)
|
25
23
|
|
26
|
-
info
|
24
|
+
info "installed lolcommit hook to:"
|
27
25
|
info " -> #{File.expand_path(path)}"
|
28
|
-
info
|
26
|
+
info "(to remove later, you can use: lolcommits --disable)"
|
29
27
|
# we dont symlink, but rather install a small stub that calls the one from path
|
30
28
|
# that way, as gem version changes, script updates even if new file thus breaking symlink
|
31
29
|
end
|
@@ -43,14 +41,14 @@ module Lolcommits
|
|
43
41
|
# @return [String]
|
44
42
|
def self.extract_capture_args(options)
|
45
43
|
options.map do |k, v|
|
46
|
-
next unless %w
|
44
|
+
next unless %w[device animate delay stealth fork].include?(k)
|
47
45
|
|
48
|
-
if k ==
|
46
|
+
if k == "device"
|
49
47
|
"--device '#{v}'"
|
50
48
|
else
|
51
49
|
"--#{k}#{v == true ? '' : " #{v}"}"
|
52
50
|
end
|
53
|
-
end.compact.join(
|
51
|
+
end.compact.join(" ")
|
54
52
|
end
|
55
53
|
end
|
56
54
|
end
|
data/lib/lolcommits/platform.rb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'mini_magick'
|
4
|
-
require 'rbconfig'
|
1
|
+
require "mini_magick"
|
2
|
+
require "rbconfig"
|
5
3
|
|
6
4
|
module Lolcommits
|
7
5
|
class Platform
|
8
6
|
# The capturer class constant to use
|
9
7
|
# @return Class
|
10
8
|
def self.capturer_class(animate: false)
|
11
|
-
if ENV[
|
12
|
-
const_get(ENV[
|
9
|
+
if ENV["LOLCOMMITS_CAPTURER"]
|
10
|
+
const_get(ENV["LOLCOMMITS_CAPTURER"])
|
13
11
|
elsif platform_mac?
|
14
12
|
animate ? CaptureMacVideo : CaptureMac
|
15
13
|
elsif platform_linux?
|
@@ -19,20 +17,20 @@ module Lolcommits
|
|
19
17
|
elsif platform_cygwin?
|
20
18
|
CaptureCygwin
|
21
19
|
else
|
22
|
-
raise
|
20
|
+
raise "Unknown / Unsupported Platform."
|
23
21
|
end
|
24
22
|
end
|
25
23
|
|
26
24
|
# Are we on a Mac platform?
|
27
25
|
# @return Boolean
|
28
26
|
def self.platform_mac?
|
29
|
-
host_os.include?(
|
27
|
+
host_os.include?("darwin")
|
30
28
|
end
|
31
29
|
|
32
30
|
# Are we on a Linux platform?
|
33
31
|
# @return Boolean
|
34
32
|
def self.platform_linux?
|
35
|
-
host_os.include?(
|
33
|
+
host_os.include?("linux")
|
36
34
|
end
|
37
35
|
|
38
36
|
# Are we on a Windows platform?
|
@@ -44,13 +42,13 @@ module Lolcommits
|
|
44
42
|
# Are we on a Cygwin platform?
|
45
43
|
# @return Boolean
|
46
44
|
def self.platform_cygwin?
|
47
|
-
host_os.include?(
|
45
|
+
host_os.include?("cygwin")
|
48
46
|
end
|
49
47
|
|
50
48
|
# return host_os identifier from the RbConfig::CONFIG constant
|
51
49
|
# @return String
|
52
50
|
def self.host_os
|
53
|
-
ENV[
|
51
|
+
ENV["LOLCOMMITS_FAKE_HOST_OS"] || RbConfig::CONFIG["host_os"].downcase
|
54
52
|
end
|
55
53
|
|
56
54
|
# Is the platform capable of capturing animated GIFs from webcam?
|
@@ -62,9 +60,7 @@ module Lolcommits
|
|
62
60
|
# Is a valid install of imagemagick present on the system?
|
63
61
|
# @return Boolean
|
64
62
|
def self.valid_imagemagick_installed?
|
65
|
-
return false unless command_which(
|
66
|
-
|
67
|
-
return false unless command_which('mogrify')
|
63
|
+
return false unless command_which("magick")
|
68
64
|
|
69
65
|
# cli_version check will throw a MiniMagick::Error exception if IM is not
|
70
66
|
# installed in PATH, since it attempts to parse output from `identify`
|
@@ -78,7 +74,7 @@ module Lolcommits
|
|
78
74
|
# @note For now, this just checks for presence, any version should work.
|
79
75
|
# @return Boolean
|
80
76
|
def self.valid_ffmpeg_installed?
|
81
|
-
command_which(
|
77
|
+
command_which("ffmpeg")
|
82
78
|
end
|
83
79
|
|
84
80
|
# Cross-platform way of finding an executable in the $PATH.
|
@@ -91,8 +87,8 @@ module Lolcommits
|
|
91
87
|
#
|
92
88
|
# @return Boolean
|
93
89
|
def self.command_which(cmd, only_path: false)
|
94
|
-
exts = ENV[
|
95
|
-
ENV[
|
90
|
+
exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [ "" ]
|
91
|
+
ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
|
96
92
|
exts.each do |ext|
|
97
93
|
exe = "#{path}/#{cmd}#{ext}"
|
98
94
|
return only_path ? path : exe if File.executable? exe
|
@@ -123,7 +119,7 @@ module Lolcommits
|
|
123
119
|
# TODO: handle other platforms here (linux/windows) e.g with ffmpeg -list_devices
|
124
120
|
return unless Platform.platform_mac?
|
125
121
|
|
126
|
-
videosnap = File.join(Configuration::LOLCOMMITS_ROOT,
|
122
|
+
videosnap = File.join(Configuration::LOLCOMMITS_ROOT, "vendor", "ext", "videosnap", "videosnap")
|
127
123
|
`#{videosnap} -l`
|
128
124
|
end
|
129
125
|
end
|
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'lolcommits/plugin/configuration_helper'
|
1
|
+
require "lolcommits/plugin/configuration_helper"
|
4
2
|
|
5
3
|
module Lolcommits
|
6
4
|
module Plugin
|
@@ -13,7 +11,7 @@ module Lolcommits
|
|
13
11
|
self.runner = runner
|
14
12
|
self.name = name || self.class.to_s
|
15
13
|
self.configuration = config || {}
|
16
|
-
self.options = [:enabled]
|
14
|
+
self.options = [ :enabled ]
|
17
15
|
end
|
18
16
|
|
19
17
|
def run_pre_capture; end
|
@@ -51,9 +49,7 @@ module Lolcommits
|
|
51
49
|
#
|
52
50
|
# @return [Hash] the configured plugin options
|
53
51
|
def configure_options!
|
54
|
-
configure_option_hash(
|
55
|
-
options.map { |option| [option, nil] }.to_h.merge(default_options)
|
56
|
-
)
|
52
|
+
configure_option_hash(options.map { |option| [ option, nil ] }.to_h.merge(default_options))
|
57
53
|
end
|
58
54
|
|
59
55
|
def default_options
|
@@ -103,7 +99,7 @@ module Lolcommits
|
|
103
99
|
def configure_option_hash(option_hash, spacing_count = 0)
|
104
100
|
option_hash.keys.reduce({}) do |acc, option|
|
105
101
|
option_value = option_hash[option]
|
106
|
-
prefix =
|
102
|
+
prefix = " " * spacing_count
|
107
103
|
if option_value.is_a?(Hash)
|
108
104
|
puts "#{prefix}#{option}:\n"
|
109
105
|
acc.merge(option => configure_option_hash(option_value, (spacing_count + 1)))
|
@@ -1,13 +1,11 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Lolcommits
|
4
2
|
module Plugin
|
5
3
|
module ConfigurationHelper
|
6
4
|
# handle for bools, strings, ints and blanks from user input
|
7
5
|
def parse_user_input(str)
|
8
|
-
if
|
6
|
+
if "true".casecmp(str).zero?
|
9
7
|
true
|
10
|
-
elsif
|
8
|
+
elsif "false".casecmp(str).zero?
|
11
9
|
false
|
12
10
|
elsif str =~ /^[0-9]+$/
|
13
11
|
str.to_i
|
@@ -29,7 +27,7 @@ module Lolcommits
|
|
29
27
|
# ]
|
30
28
|
# User will be asked for Organization, can tab to autocomplete, and chosen
|
31
29
|
# value is returned.
|
32
|
-
def prompt_autocomplete_hash(prompt, items, name:
|
30
|
+
def prompt_autocomplete_hash(prompt, items, name: "name", value: "value", suggest_words: 5)
|
33
31
|
words = items.map { |item| item[name] }.sort
|
34
32
|
puts "e.g. #{words.take(suggest_words).join(', ')}" if suggest_words.positive?
|
35
33
|
completed_input = gets_autocomplete(prompt, words)
|
@@ -40,7 +38,7 @@ module Lolcommits
|
|
40
38
|
|
41
39
|
def gets_autocomplete(prompt, words)
|
42
40
|
completion_handler = proc { |s| words.grep(/^#{Regexp.escape(s)}/) }
|
43
|
-
Readline.completion_append_character =
|
41
|
+
Readline.completion_append_character = ""
|
44
42
|
Readline.completion_proc = completion_handler
|
45
43
|
|
46
44
|
while (line = Readline.readline(prompt, true).strip)
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Lolcommits
|
4
2
|
class PluginManager
|
5
3
|
GEM_NAME_PREFIX = /^#{Lolcommits::GEM_NAME}-/
|
@@ -62,7 +60,7 @@ module Lolcommits
|
|
62
60
|
|
63
61
|
def gem_list
|
64
62
|
Gem.refresh
|
65
|
-
Gem::Specification.respond_to?(:each) ? Gem::Specification : Gem.source_index.find_name(
|
63
|
+
Gem::Specification.respond_to?(:each) ? Gem::Specification : Gem.source_index.find_name("")
|
66
64
|
end
|
67
65
|
end
|
68
66
|
end
|
data/lib/lolcommits/runner.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'lolcommits/platform'
|
4
|
-
require 'lolcommits/animated_gif'
|
1
|
+
require "lolcommits/platform"
|
2
|
+
require "lolcommits/animated_gif"
|
5
3
|
|
6
4
|
module Lolcommits
|
7
5
|
class Runner
|
@@ -30,7 +28,7 @@ module Lolcommits
|
|
30
28
|
|
31
29
|
self.capture_path = config.capture_path(lolcommit_ext)
|
32
30
|
self.lolcommit_path = config.sha_path(sha, lolcommit_ext)
|
33
|
-
self.lolcommit_gif_path = config.sha_path(sha,
|
31
|
+
self.lolcommit_gif_path = config.sha_path(sha, "gif") if capture_gif
|
34
32
|
end
|
35
33
|
|
36
34
|
def run
|
@@ -41,7 +39,7 @@ module Lolcommits
|
|
41
39
|
|
42
40
|
# capture must exist to run post capture methods
|
43
41
|
unless File.exist?(capture_path)
|
44
|
-
raise
|
42
|
+
raise "failed to capture any image or video!"
|
45
43
|
end
|
46
44
|
|
47
45
|
run_post_capture
|
@@ -50,7 +48,7 @@ module Lolcommits
|
|
50
48
|
debug("#{e.class}: #{e.message}")
|
51
49
|
exit 1
|
52
50
|
ensure
|
53
|
-
debug
|
51
|
+
debug "running cleanup"
|
54
52
|
FileUtils.rm_f(capture_path)
|
55
53
|
end
|
56
54
|
|
@@ -63,12 +61,12 @@ module Lolcommits
|
|
63
61
|
end
|
64
62
|
|
65
63
|
base = MiniMagick::Image.open(source_path)
|
66
|
-
png_tempfile = MiniMagick::Utilities.tempfile(
|
64
|
+
png_tempfile = MiniMagick::Utilities.tempfile(".png")
|
67
65
|
debug("creating a new empty overlay png for lolcommit (#{base.dimensions.join('x')})")
|
68
66
|
|
69
67
|
MiniMagick::Tool::Convert.new do |i|
|
70
68
|
i.size "#{base.width}x#{base.height}"
|
71
|
-
i.xc
|
69
|
+
i.xc "transparent"
|
72
70
|
i << png_tempfile.path
|
73
71
|
end
|
74
72
|
|
@@ -94,7 +92,7 @@ module Lolcommits
|
|
94
92
|
end
|
95
93
|
|
96
94
|
def run_capture
|
97
|
-
puts
|
95
|
+
puts "*** Preserving this moment in history." unless capture_stealth
|
98
96
|
capturer = Platform.capturer_class(animate: !capture_image?).new(
|
99
97
|
capture_path: capture_path,
|
100
98
|
capture_device: capture_device,
|
@@ -119,10 +117,7 @@ module Lolcommits
|
|
119
117
|
# optionally create animated gif
|
120
118
|
return unless capture_gif
|
121
119
|
|
122
|
-
AnimatedGif.new.create(
|
123
|
-
video_path: lolcommit_path,
|
124
|
-
output_path: lolcommit_gif_path
|
125
|
-
)
|
120
|
+
AnimatedGif.new.create(video_path: lolcommit_path, output_path: lolcommit_gif_path)
|
126
121
|
|
127
122
|
# done if we are capturing both video and gif
|
128
123
|
return if capture_video
|
@@ -145,9 +140,9 @@ module Lolcommits
|
|
145
140
|
debug "resizing raw image (#{image.dimensions.join('x')}) to #{lolcommit_path} (640x480)"
|
146
141
|
# hacky resize to fill bounds
|
147
142
|
image.combine_options do |c|
|
148
|
-
c.resize
|
149
|
-
c.gravity
|
150
|
-
c.extent
|
143
|
+
c.resize "640x480^"
|
144
|
+
c.gravity "center"
|
145
|
+
c.extent "640x480"
|
151
146
|
end
|
152
147
|
image.write(lolcommit_path)
|
153
148
|
else
|
@@ -157,10 +152,10 @@ module Lolcommits
|
|
157
152
|
end
|
158
153
|
|
159
154
|
def apply_overlay
|
160
|
-
debug
|
155
|
+
debug "applying overlay to lolcommit"
|
161
156
|
if capture_image?
|
162
157
|
MiniMagick::Image.open(lolcommit_path).composite(overlay) do |c|
|
163
|
-
c.gravity
|
158
|
+
c.gravity "center"
|
164
159
|
end.write(lolcommit_path)
|
165
160
|
else
|
166
161
|
system_call "ffmpeg -v quiet -nostats -i #{capture_path} -i #{overlay.path} \
|
@@ -171,9 +166,9 @@ module Lolcommits
|
|
171
166
|
|
172
167
|
def lolcommit_ext
|
173
168
|
if capture_image?
|
174
|
-
|
169
|
+
"jpg"
|
175
170
|
else
|
176
|
-
|
171
|
+
"mp4"
|
177
172
|
end
|
178
173
|
end
|
179
174
|
|