Sha256: f5a7d3aaf45aaa1c4c8359155be108f43fb0a78e77edd1fd288d0d6d67f56917

Contents?: true

Size: 979 Bytes

Versions: 5

Compression:

Stored size: 979 Bytes

Contents

# frozen_string_literal: true

# auto_register: false

require 'pg_export/import'
require 'tty-spinner'

class PgExport
  module Listeners
    class InteractiveListener
      def on_step_failed(event)
        @spinner.error([error, self.class.red(event[:value][:message])].join("\n"))
      end

      class << self
        def green(s)
          "\e[0;32;49m#{s}\e[0m"
        end

        def red(s)
          "\e[31m#{s}\e[0m"
        end
      end

      private

      SUCCESS_MARK = green("\u2713").freeze
      ERROR_MARK = red("\u00d7").freeze
      private_constant :SUCCESS_MARK, :ERROR_MARK

      def build_spinner(message)
        TTY::Spinner.new(
          "[:spinner] #{message}...",
          format: :dots,
          success_mark: SUCCESS_MARK,
          error_mark: ERROR_MARK
        ).tap(&:auto_spin)
      end

      def success
        self.class.green('(success)')
      end

      def error
        self.class.red('(error)')
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pg_export-1.0.0.rc5 lib/pg_export/lib/pg_export/listeners/interactive_listener.rb
pg_export-1.0.0.rc4 lib/pg_export/lib/pg_export/listeners/interactive_listener.rb
pg_export-1.0.0.rc3 lib/pg_export/lib/pg_export/listeners/interactive_listener.rb
pg_export-1.0.0.rc2 lib/pg_export/lib/pg_export/listeners/interactive_listener.rb
pg_export-1.0.0.rc1 lib/pg_export/lib/pg_export/listeners/interactive_listener.rb