summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-05-20 20:28:31 -0600
committermo khan <mo.khan@gmail.com>2020-05-20 20:28:31 -0600
commit77489f0239fca9bcabd0cd556ab1619bbb723521 (patch)
treee8a9233419ac9b308dbab2dfbe67d11793e045bd
parent5ce1a4bb47592d33f725b7586f8e767bedd54129 (diff)
switch to a nanospinner with less dependencies
-rw-r--r--.github/licensed/bundler/nanospinner.dep.yml (renamed from .github/licensed/bundler/tty-cursor.dep.yml)12
-rw-r--r--.github/licensed/bundler/strings-ansi.dep.yml34
-rw-r--r--.github/licensed/bundler/tty-progressbar.dep.yml33
-rw-r--r--.github/licensed/bundler/unicode-display_width.dep.yml33
-rw-r--r--Gemfile.lock11
-rw-r--r--lib/spandx/cli.rb3
-rw-r--r--lib/spandx/cli/commands/scan.rb32
-rw-r--r--lib/spandx/core/spinner.rb51
-rw-r--r--spandx.gemspec3
-rw-r--r--spec/unit/ruby/parsers/gemfile_lock_spec.rb2
10 files changed, 74 insertions, 140 deletions
diff --git a/.github/licensed/bundler/tty-cursor.dep.yml b/.github/licensed/bundler/nanospinner.dep.yml
index 177d1c6..cc6f56f 100644
--- a/.github/licensed/bundler/tty-cursor.dep.yml
+++ b/.github/licensed/bundler/nanospinner.dep.yml
@@ -1,16 +1,14 @@
---
-name: tty-cursor
-version: 0.7.1
+name: nanospinner
+version: 1.0.0
type: bundler
-summary: Terminal cursor positioning, visibility and text manipulation.
-homepage: https://ttytoolkit.org
+summary: A tiny commandline spinner
+homepage: http://github.com/julik/nanospinner
license: mit
licenses:
- sources: LICENSE.txt
text: |
- Copyright (c) 2015 Piotr Murach
-
- MIT License
+ Copyright (c) 2014 Julik Tarkhanov
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
diff --git a/.github/licensed/bundler/strings-ansi.dep.yml b/.github/licensed/bundler/strings-ansi.dep.yml
deleted file mode 100644
index 9d502e7..0000000
--- a/.github/licensed/bundler/strings-ansi.dep.yml
+++ /dev/null
@@ -1,34 +0,0 @@
----
-name: strings-ansi
-version: 0.1.0
-type: bundler
-summary: Methods for processing ANSI escape codes in strings.
-homepage: https://github.com/piotrmurach/strings
-license: mit
-licenses:
-- sources: LICENSE.txt
- text: |
- The MIT License (MIT)
-
- Copyright (c) 2018 Piotr Murach
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
-- sources: README.md
- text: The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
-notices: []
diff --git a/.github/licensed/bundler/tty-progressbar.dep.yml b/.github/licensed/bundler/tty-progressbar.dep.yml
deleted file mode 100644
index 006fabe..0000000
--- a/.github/licensed/bundler/tty-progressbar.dep.yml
+++ /dev/null
@@ -1,33 +0,0 @@
----
-name: tty-progressbar
-version: 0.17.0
-type: bundler
-summary: A flexible progress bars drawing in terminal emulators.
-homepage: https://piotrmurach.github.io/tty/
-license: mit
-licenses:
-- sources: LICENSE.txt
- text: |
- Copyright (c) 2014 Piotr Murach
-
- MIT License
-
- Permission is hereby granted, free of charge, to any person obtaining
- a copy of this software and associated documentation files (the
- "Software"), to deal in the Software without restriction, including
- without limitation the rights to use, copy, modify, merge, publish,
- distribute, sublicense, and/or sell copies of the Software, and to
- permit persons to whom the Software is furnished to do so, subject to
- the following conditions:
-
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-notices: []
diff --git a/.github/licensed/bundler/unicode-display_width.dep.yml b/.github/licensed/bundler/unicode-display_width.dep.yml
deleted file mode 100644
index 35422be..0000000
--- a/.github/licensed/bundler/unicode-display_width.dep.yml
+++ /dev/null
@@ -1,33 +0,0 @@
----
-name: unicode-display_width
-version: 1.7.0
-type: bundler
-summary: Determines the monospace display width of a string in Ruby.
-homepage: https://github.com/janlelis/unicode-display_width
-license: mit
-licenses:
-- sources: MIT-LICENSE.txt
- text: |
- The MIT LICENSE
-
- Copyright (c) 2011, 2015-2020 Jan Lelis
-
- Permission is hereby granted, free of charge, to any person obtaining
- a copy of this software and associated documentation files (the
- "Software"), to deal in the Software without restriction, including
- without limitation the rights to use, copy, modify, merge, publish,
- distribute, sublicense, and/or sell copies of the Software, and to
- permit persons to whom the Software is furnished to do so, subject to
- the following conditions:
-
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-notices: []
diff --git a/Gemfile.lock b/Gemfile.lock
index 25853b2..87f409e 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -4,11 +4,12 @@ PATH
spandx (0.13.3)
addressable (~> 2.7)
bundler (>= 1.16, < 3.0.0)
+ nanospinner (~> 1.0.0)
net-hippie (~> 0.3)
nokogiri (~> 1.10)
parslet (~> 2.0)
thor
- tty-progressbar (~> 0.17)
+ tty-screen (~> 0.7)
zeitwerk (~> 2.3)
GEM
@@ -49,6 +50,7 @@ GEM
thor (>= 0.19, < 2.0)
mini_portile2 (2.4.0)
multipart-post (2.1.1)
+ nanospinner (1.0.0)
net-hippie (0.3.2)
nokogiri (1.10.9)
mini_portile2 (~> 2.4.0)
@@ -103,15 +105,8 @@ GEM
sawyer (0.8.2)
addressable (>= 2.3.5)
faraday (> 0.8, < 2.0)
- strings-ansi (0.1.0)
thor (0.20.3)
tomlrb (1.3.0)
- tty-cursor (0.7.1)
- tty-progressbar (0.17.0)
- strings-ansi (~> 0.1.0)
- tty-cursor (~> 0.7)
- tty-screen (~> 0.7)
- unicode-display_width (~> 1.6)
tty-screen (0.7.1)
unicode-display_width (1.7.0)
vcr (5.1.0)
diff --git a/lib/spandx/cli.rb b/lib/spandx/cli.rb
index 9e3ad4d..817ff89 100644
--- a/lib/spandx/cli.rb
+++ b/lib/spandx/cli.rb
@@ -1,7 +1,8 @@
# frozen_string_literal: true
+require 'nanospinner'
require 'thor'
-require 'tty-progressbar'
+require 'tty-screen'
module Spandx
module Cli
diff --git a/lib/spandx/cli/commands/scan.rb b/lib/spandx/cli/commands/scan.rb
index aede23b..329063e 100644
--- a/lib/spandx/cli/commands/scan.rb
+++ b/lib/spandx/cli/commands/scan.rb
@@ -4,25 +4,25 @@ module Spandx
module Cli
module Commands
class Scan
- NULL_BAR = Class.new do
- def advance(*args); end
- end.new
-
- attr_reader :scan_path
+ attr_reader :scan_path, :spinner
def initialize(scan_path, options)
@scan_path = ::Pathname.new(scan_path)
@options = options
+ @spinner = options[:show_progress] ? ::Spandx::Core::Spinner.new : ::Spandx::Core::Spinner::NULL
require(options[:require]) if options[:require]
end
def execute(output: $stdout)
report = ::Spandx::Core::Report.new
each_file do |file|
+ spinner.spin(file)
each_dependency_from(file) do |dependency|
+ spinner.spin(file)
report.add(dependency)
end
end
+ spinner.stop
output.puts(format(report.to(@options[:format])))
end
@@ -35,15 +35,11 @@ module Spandx
end
def each_dependency_from(file)
- dependencies = ::Spandx::Core::Parser.for(file).parse(file)
- with_progress(title_for(file), dependencies.size) do |bar|
- dependencies
- .map { |x| enhance(x) }
- .each do |dependency|
- bar.advance(1)
- yield dependency
- end
- end
+ ::Spandx::Core::Parser
+ .for(file)
+ .parse(file)
+ .map { |x| enhance(x) }
+ .each { |dependency| yield dependency }
end
def format(output)
@@ -55,14 +51,6 @@ module Spandx
.all
.inject(dependency) { |memo, plugin| plugin.enhance(memo) }
end
-
- def title_for(file)
- "#{file} [:bar, :elapsed] :percent"
- end
-
- def with_progress(title, total)
- yield @options[:show_progress] ? TTY::ProgressBar.new(title, total: total) : NULL_BAR
- end
end
end
end
diff --git a/lib/spandx/core/spinner.rb b/lib/spandx/core/spinner.rb
new file mode 100644
index 0000000..af3c7a7
--- /dev/null
+++ b/lib/spandx/core/spinner.rb
@@ -0,0 +1,51 @@
+# frozen_string_literal: true
+
+module Spandx
+ module Core
+ class Spinner
+ NULL = Class.new do
+ def self.spin(*args); end
+
+ def self.stop(*args); end
+ end
+
+ attr_reader :columns, :spinner
+
+ def initialize(columns: TTY::Screen.columns, output: $stderr)
+ @columns = columns
+ @spinner = Nanospinner.new(output)
+ @queue = Queue.new
+ @thread = Thread.new { work }
+ end
+
+ def spin(message)
+ @queue.enq(justify(message))
+ yield if block_given?
+ end
+
+ def stop
+ @queue.clear
+ @queue.enq(:stop)
+ @thread.join
+ end
+
+ private
+
+ def justify(message)
+ message.to_s.ljust(columns - 3)
+ end
+
+ def work
+ last_message = justify('')
+ loop do
+ message = @queue.empty? ? last_message : @queue.deq
+ break if message == :stop
+
+ spinner.spin(message)
+ last_message = message
+ sleep 0.1
+ end
+ end
+ end
+ end
+end
diff --git a/spandx.gemspec b/spandx.gemspec
index 033c824..f4cf59f 100644
--- a/spandx.gemspec
+++ b/spandx.gemspec
@@ -34,11 +34,12 @@ Gem::Specification.new do |spec|
spec.add_dependency 'addressable', '~> 2.7'
spec.add_dependency 'bundler', '>= 1.16', '< 3.0.0'
+ spec.add_dependency 'nanospinner', '~> 1.0.0'
spec.add_dependency 'net-hippie', '~> 0.3'
spec.add_dependency 'nokogiri', '~> 1.10'
spec.add_dependency 'parslet', '~> 2.0'
spec.add_dependency 'thor'
- spec.add_dependency 'tty-progressbar', '~> 0.17'
+ spec.add_dependency 'tty-screen', '~> 0.7'
spec.add_dependency 'zeitwerk', '~> 2.3'
spec.add_development_dependency 'benchmark-ips', '~> 2.8'
diff --git a/spec/unit/ruby/parsers/gemfile_lock_spec.rb b/spec/unit/ruby/parsers/gemfile_lock_spec.rb
index 7160033..467fced 100644
--- a/spec/unit/ruby/parsers/gemfile_lock_spec.rb
+++ b/spec/unit/ruby/parsers/gemfile_lock_spec.rb
@@ -24,7 +24,7 @@ RSpec.describe Spandx::Ruby::Parsers::GemfileLock do
specify { expect(spandx.name).to eql('spandx') }
specify { expect(spandx.version).to eql(Spandx::VERSION) }
- specify { expect(spandx.meta[:dependencies].map(&:name)).to match_array(%w[addressable bundler net-hippie nokogiri parslet thor tty-progressbar zeitwerk]) }
+ specify { expect(spandx.meta[:dependencies].map(&:name)).to match_array(%w[addressable bundler nanospinner net-hippie nokogiri parslet thor tty-screen zeitwerk]) }
specify { expect(spandx.meta[:platform]).to eql('ruby') }
specify { expect(spandx.meta[:source]).to be_a_kind_of(Bundler::Source) }
end