Commit 0779989

mo khan <mo.khan@gmail.com>
2020-06-12 21:38:56
Move spinner into Table printer
1 parent 50437b8
Changed files (9)
.github/licensed/bundler/nanospinner.dep.yml → .github/licensed/bundler/tty-cursor.dep.yml
@@ -1,14 +1,16 @@
 ---
-name: nanospinner
-version: 1.0.0
+name: tty-cursor
+version: 0.7.1
 type: bundler
-summary: A tiny commandline spinner
-homepage: http://github.com/julik/nanospinner
+summary: Terminal cursor positioning, visibility and text manipulation.
+homepage: https://ttytoolkit.org
 license: mit
 licenses:
 - sources: LICENSE.txt
   text: |
-    Copyright (c) 2014 Julik Tarkhanov
+    Copyright (c) 2015 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
.github/licensed/bundler/tty-screen.dep.yml → .github/licensed/bundler/tty-spinner.dep.yml
@@ -1,9 +1,8 @@
 ---
-name: tty-screen
-version: 0.8.0
+name: tty-spinner
+version: 0.9.3
 type: bundler
-summary: Terminal screen size detection which works on Linux, OS X and Windows/Cygwin
-  platforms and supports MRI, JRuby, TruffleRuby and Rubinius interpreters.
+summary: A terminal spinner for tasks that have non-deterministic time frame.
 homepage: https://ttytoolkit.org
 license: mit
 licenses:
lib/spandx/cli/commands/scan.rb
@@ -35,16 +35,13 @@ module Spandx
         end
 
         def each_dependency
-          spinner = @options[:show_progress] ? Spinner.new : Spinner::NULL
           with_thread_pool(size: thread_count) do |thread|
             each_file do |file|
-              spinner.spin(file.to_s)
               Parser.parse(file).each do |dependency|
                 thread.run { yield dependency }
               end
             end
           end
-          spinner.stop
         end
 
         def format(output)
lib/spandx/cli/printers/table.rb
@@ -6,12 +6,17 @@ module Spandx
       class Table < Printer
         HEADINGS = ['Name', 'Version', 'Licenses', 'Location'].freeze
 
+        def initialize
+          @spinner = TTY::Spinner.new(output: $stderr)
+        end
+
         def match?(format)
           format.to_sym == :table
         end
 
         def print_header(_io)
           @dependencies = SortedSet.new
+          @spinner.auto_spin
         end
 
         def print_line(dependency, _io)
@@ -19,6 +24,7 @@ module Spandx
         end
 
         def print_footer(io)
+          @spinner.stop
           io.puts(to_table(@dependencies.map(&:to_a)))
         end
 
lib/spandx/core/spinner.rb
@@ -1,51 +0,0 @@
-# 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
lib/spandx/cli.rb
@@ -1,8 +1,7 @@
 # frozen_string_literal: true
 
-require 'nanospinner'
 require 'thor'
-require 'tty-screen'
+require 'tty-spinner'
 require 'terminal-table'
 
 module Spandx
spec/unit/ruby/parsers/gemfile_lock_spec.rb
@@ -39,7 +39,7 @@ RSpec.describe Spandx::Ruby::Parsers::GemfileLock do
       specify do
         expect(subject).to match_array([
           build('addressable', '2.7.0', path),
-          build('ast', '2.4.0', path),
+          build('ast', '2.4.1', path),
           build('benchmark-ips', '2.8.2', path),
           build('benchmark-malloc', '0.2.0', path),
           build('benchmark-perf', '0.6.0', path),
@@ -51,11 +51,10 @@ RSpec.describe Spandx::Ruby::Parsers::GemfileLock do
           build('dotenv', '2.7.5', path),
           build('faraday', '1.0.1', path),
           build('hashdiff', '1.0.1', path),
-          build('licensed', '2.11.0', path),
+          build('licensed', '2.11.1', path),
           build('licensee', '9.14.0', path),
           build('mini_portile2', '2.4.0', path),
           build('multipart-post', '2.1.1', path),
-          build('nanospinner', '1.0.0', path),
           build('net-hippie', '0.3.2', path),
           build('nokogiri', '1.10.9', path),
           build('octokit', '4.18.0', path),
@@ -79,7 +78,7 @@ RSpec.describe Spandx::Ruby::Parsers::GemfileLock do
           build('rspec-support', '3.9.3', path),
           build('rubocop', '0.85.1', path),
           build('rubocop-ast', '0.0.3', path),
-          build('rubocop-rspec', '1.39.0', path),
+          build('rubocop-rspec', '1.40.0', path),
           build('ruby-prof', '1.4.1', path),
           build('ruby-progressbar', '1.10.1', path),
           build('ruby-xxHash', '0.4.0.1', path),
@@ -90,7 +89,8 @@ RSpec.describe Spandx::Ruby::Parsers::GemfileLock do
           build('terminal-table', '1.8.0', path),
           build('thor', '0.20.3', path),
           build('tomlrb', '1.3.0', path),
-          build('tty-screen', '0.8.0', path),
+          build('tty-cursor', '0.7.1', path),
+          build('tty-spinner', '0.9.3', path),
           build('unicode-display_width', '1.7.0', path),
           build('vcr', '6.0.0', path),
           build('webmock', '3.8.3', path),
Gemfile.lock
@@ -4,14 +4,13 @@ PATH
     spandx (0.13.4)
       addressable (~> 2.7)
       bundler (>= 1.16, < 3.0.0)
-      nanospinner (~> 1.0.0)
       net-hippie (~> 0.3)
       nokogiri (~> 1.10)
       oj (~> 3.10)
       parslet (~> 2.0)
       terminal-table (~> 1.8)
       thor
-      tty-screen (~> 0.7)
+      tty-spinner (~> 0.9)
       zeitwerk (~> 2.3)
 
 GEM
@@ -19,7 +18,7 @@ GEM
   specs:
     addressable (2.7.0)
       public_suffix (>= 2.0.2, < 5.0)
-    ast (2.4.0)
+    ast (2.4.1)
     benchmark-ips (2.8.2)
     benchmark-malloc (0.2.0)
     benchmark-perf (0.6.0)
@@ -35,7 +34,7 @@ GEM
     faraday (1.0.1)
       multipart-post (>= 1.2, < 3)
     hashdiff (1.0.1)
-    licensed (2.11.0)
+    licensed (2.11.1)
       bundler (>= 1.10)
       licensee (>= 9.14.0, < 10.0.0)
       parallel (>= 0.18.0)
@@ -52,7 +51,6 @@ 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,7 +101,7 @@ GEM
       unicode-display_width (>= 1.4.0, < 2.0)
     rubocop-ast (0.0.3)
       parser (>= 2.7.0.1)
-    rubocop-rspec (1.39.0)
+    rubocop-rspec (1.40.0)
       rubocop (>= 0.68.1)
     ruby-prof (1.4.1)
     ruby-progressbar (1.10.1)
@@ -117,7 +115,9 @@ GEM
       unicode-display_width (~> 1.1, >= 1.1.1)
     thor (0.20.3)
     tomlrb (1.3.0)
-    tty-screen (0.8.0)
+    tty-cursor (0.7.1)
+    tty-spinner (0.9.3)
+      tty-cursor (~> 0.7)
     unicode-display_width (1.7.0)
     vcr (6.0.0)
     webmock (3.8.3)
spandx.gemspec
@@ -34,14 +34,13 @@ 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 'oj', '~> 3.10'
   spec.add_dependency 'parslet', '~> 2.0'
   spec.add_dependency 'terminal-table', '~> 1.8'
   spec.add_dependency 'thor'
-  spec.add_dependency 'tty-screen', '~> 0.7'
+  spec.add_dependency 'tty-spinner', '~> 0.9'
   spec.add_dependency 'zeitwerk', '~> 2.3'
 
   spec.add_development_dependency 'benchmark-ips', '~> 2.8'