Sha256: ced1014a94d0a9c886d23a20120101d2eda6ba5db5fc55610025f6f8b64c6e94

Contents?: true

Size: 1.89 KB

Versions: 139

Compression:

Stored size: 1.89 KB

Contents

# frozen-string-literal: true
require('cli/ui')

module CLI
  module UI
    module Widgets
      class Status < Widgets::Base
        ARGPARSE_PATTERN = %r{
          \A (?<succeeded> \d+)
          :  (?<failed>    \d+)
          :  (?<working>   \d+)
          :  (?<pending>   \d+) \z
        }x # e.g. "1:23:3:404"
        OPEN  = Color::RESET.code + Color::BOLD.code + '[' + Color::RESET.code
        CLOSE = Color::RESET.code + Color::BOLD.code + ']' + Color::RESET.code
        ARROW = Color::RESET.code + Color::GRAY.code + '◂' + Color::RESET.code
        COMMA = Color::RESET.code + Color::GRAY.code + ',' + Color::RESET.code

        SPINNER_STOPPED = '⠿'
        EMPTY_SET = '∅'

        def render
          if zero?(@succeeded) && zero?(@failed) && zero?(@working) && zero?(@pending)
            Color::RESET.code + Color::BOLD.code + EMPTY_SET + Color::RESET.code
          else
            #   [          0✓            ,         2✗          ◂         3⠼           ◂         4⌛︎           ]
            "#{OPEN}#{succeeded_part}#{COMMA}#{failed_part}#{ARROW}#{working_part}#{ARROW}#{pending_part}#{CLOSE}"
          end
        end

        private

        def zero?(num_str)
          num_str == '0'
        end

        def colorize_if_nonzero(num_str, rune, color)
          color = Color::GRAY if zero?(num_str)
          color.code + num_str + rune
        end

        def succeeded_part
          colorize_if_nonzero(@succeeded, Glyph::CHECK.char, Color::GREEN)
        end

        def failed_part
          colorize_if_nonzero(@failed, Glyph::X.char, Color::RED)
        end

        def working_part
          rune = zero?(@working) ? SPINNER_STOPPED : Spinner.current_rune
          colorize_if_nonzero(@working, rune, Color::BLUE)
        end

        def pending_part
          colorize_if_nonzero(@pending, Glyph::HOURGLASS.char, Color::WHITE)
        end
      end
    end
  end
end

Version data entries

139 entries across 139 versions & 3 rubygems

Version Path
shopify-cli-2.2.1 vendor/deps/cli-ui/lib/cli/ui/widgets/status.rb
shopify-cli-2.2.0 vendor/deps/cli-ui/lib/cli/ui/widgets/status.rb
shopify-cli-2.1.0 vendor/deps/cli-ui/lib/cli/ui/widgets/status.rb
shopify-cli-2.0.2 vendor/deps/cli-ui/lib/cli/ui/widgets/status.rb
shopify-cli-2.0.1 vendor/deps/cli-ui/lib/cli/ui/widgets/status.rb
shopify-cli-2.0.0 vendor/deps/cli-ui/lib/cli/ui/widgets/status.rb
shopify-cli-1.14.0 vendor/deps/cli-ui/lib/cli/ui/widgets/status.rb
shopify-cli-1.13.1 vendor/deps/cli-ui/lib/cli/ui/widgets/status.rb
shopify-cli-1.13.0 vendor/deps/cli-ui/lib/cli/ui/widgets/status.rb
shopify-cli-1.12.0 vendor/deps/cli-ui/lib/cli/ui/widgets/status.rb
rfix-3.0.1 vendor/cli-ui/lib/cli/ui/widgets/status.rb
rfix-3.0.0 vendor/cli-ui/lib/cli/ui/widgets/status.rb
shopify-cli-1.11.0 vendor/deps/cli-ui/lib/cli/ui/widgets/status.rb
shopify-cli-1.10.0 vendor/deps/cli-ui/lib/cli/ui/widgets/status.rb
shopify-cli-1.9.1 vendor/deps/cli-ui/lib/cli/ui/widgets/status.rb
shopify-cli-1.9.0 vendor/deps/cli-ui/lib/cli/ui/widgets/status.rb
cli-ui-1.5.1 lib/cli/ui/widgets/status.rb
cli-ui-1.5.0 lib/cli/ui/widgets/status.rb
shopify-cli-1.8.0 vendor/deps/cli-ui/lib/cli/ui/widgets/status.rb
shopify-cli-1.7.1 vendor/deps/cli-ui/lib/cli/ui/widgets/status.rb