module NHKore::CLI::FXCmd

@author Jonathan Bradley Whited @since 0.2.0

Public Instance Methods

build_fx_cmd() click to toggle source
# File lib/nhkore/cli/fx_cmd.rb, line 19
    def build_fx_cmd
      app = self

      @fx_cmd = @app_cmd.define_command do
        name    'fx'
        usage   'fx [OPTIONS] [COMMAND]...'
        summary 'Test spinner/progress special effects (for running long tasks)'

        description <<-DESC
          Test if the special effects work on your command line:\n
          - #{App::NAME} [-s/-X] fx
        DESC

        flag :a,:all,'test all special effects regardless of global options'

        run do |opts,args,cmd|
          app.refresh_cmd(opts,args,cmd)
          app.run_fx_cmd
        end
      end
    end
run_fx_cmd() click to toggle source
# File lib/nhkore/cli/fx_cmd.rb, line 41
def run_fx_cmd
  test_fx_progress_bar
  test_fx_spinner
end
test_fx_progress_bar() click to toggle source
# File lib/nhkore/cli/fx_cmd.rb, line 46
def test_fx_progress_bar
  bars = nil

  if @cmd_opts[:all]
    bars = {default: :default,classic: :classic,no: :no}
  else
    bars = {user: @progress_bar}
  end

  bars.each do |name,bar|
    name = name.to_s.capitalize
    bar = build_progress_bar("Testing #{name} progress",download: false,type: bar)

    bar.start

    0.upto(99) do
      sleep(0.05)
      bar.advance
    end

    bar.finish
  end
end
test_fx_spinner() click to toggle source
# File lib/nhkore/cli/fx_cmd.rb, line 70
def test_fx_spinner
  app_spinner = @spinner
  spinners = nil

  if @cmd_opts[:all]
    spinners = {
      default: App::DEFAULT_SPINNER,
      classic: App::CLASSIC_SPINNER,
      no: {},
    }
  else
    spinners = {
      user: app_spinner
    }
  end

  spinners.each do |name,spinner|
    @spinner = spinner

    start_spin("Testing #{name.to_s.capitalize} spinner")

    1.upto(3) do |i|
      sleep(1.1)
      update_spin_detail(" (#{i}/3)")
    end

    stop_spin
  end

  # Reset back to users'.
  @spinner = app_spinner
end