Adding progress bars to the custom configuration
This commit is contained in:
+11
-5
@@ -1,6 +1,6 @@
|
||||
module Squib
|
||||
class Deck
|
||||
|
||||
|
||||
# Renders a png file at the given location.
|
||||
#
|
||||
# See {file:samples/image.rb samples/image.rb} and {file:samples/tgc-overlay.rb samples/tgc-overlay.rb} as examples.
|
||||
@@ -18,8 +18,11 @@ module Squib
|
||||
# @api public
|
||||
def png(opts = {})
|
||||
opts = needs(opts, [:range, :files, :x, :y, :alpha, :layout])
|
||||
opts[:range].each do |i|
|
||||
@cards[i].png(opts[:file][i], opts[:x], opts[:y], opts[:alpha])
|
||||
@progress_bar.start("Loading PNGs #{location(opts)}", opts[:range].size) do |bar|
|
||||
opts[:range].each do |i|
|
||||
@cards[i].png(opts[:file][i], opts[:x], opts[:y], opts[:alpha])
|
||||
bar.increment
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -40,8 +43,11 @@ module Squib
|
||||
# @api public
|
||||
def svg(opts = {})
|
||||
p = needs(opts,[:range, :files, :svgid, :x, :y, :width, :height, :layout])
|
||||
p[:range].each do |i|
|
||||
@cards[i].svg(p[:file][i], p[:id], p[:x], p[:y], p[:width], p[:height])
|
||||
@progress_bar.start("Loading SVGs #{location(opts)}", p[:range].size) do |bar|
|
||||
p[:range].each do |i|
|
||||
@cards[i].svg(p[:file][i], p[:id], p[:x], p[:y], p[:width], p[:height])
|
||||
bar.increment
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
+6
-11
@@ -24,20 +24,15 @@ module Squib
|
||||
# @option opts [Enumerable] range (:all) the range of cards over which this will be rendered. See {file:API.md#label-Specifying+Ranges Specifying Ranges}
|
||||
# @option opts [String] dir (_output) the directory for the output to be sent to. Will be created if it doesn't exist.
|
||||
# @option opts [String] prefix (card_) the prefix of the file name to be printed.
|
||||
# @option opts [Boolean] progress_bar (false) if true, show a progress bar on stdout while saving
|
||||
# @return [nil] Returns nothing
|
||||
# @api public
|
||||
def save_png(opts = {})
|
||||
opts = needs(opts,[:range, :creatable_dir, :prefix, :progress_bar])
|
||||
if opts[:progress_bar]
|
||||
require 'ruby-progressbar'
|
||||
bar = ProgressBar.create(title: "Saving to PNGs",
|
||||
starting_at: 0, total: opts[:range].size,
|
||||
format: '%t <%B> %p%% %a')
|
||||
end
|
||||
opts[:range].each do |i|
|
||||
@cards[i].save_png(i, opts[:dir], opts[:prefix])
|
||||
bar.increment if opts[:progress_bar]
|
||||
opts = needs(opts,[:range, :creatable_dir, :prefix])
|
||||
@progress_bar.start("Saving PNGs to #{opts[:dir]}/#{opts[:prefix]}*") do |bar|
|
||||
opts[:range].each do |i|
|
||||
@cards[i].save_png(i, opts[:dir], opts[:prefix])
|
||||
bar.increment
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -6,14 +6,17 @@ module Squib
|
||||
# Text hints are rectangles around where the text will be laid out. They are intended to be temporary.
|
||||
# Setting a hint to nil or to :off will disable hints. @see samples/text.rb
|
||||
# @example
|
||||
# hint text:cyan
|
||||
# hint text: :cyan
|
||||
# hint text: :cyan, progress_bar: true
|
||||
#
|
||||
# @param [String] text the color of the text hint. To turn off use nil or :off. @see API.md
|
||||
# @param [Boolean] progress_bar enable progress bars on long-running operations
|
||||
# @return [nil] Returns nothing
|
||||
# @api public
|
||||
def hint(text: nil)
|
||||
def hint(text: nil, progress_bar: false)
|
||||
text = nil if text == :off
|
||||
@text_hint = text
|
||||
@progress_bar.enabled = progress_bar
|
||||
end
|
||||
|
||||
# Sets various defaults for this deck. Defaults can be overriden by the commands themselves
|
||||
|
||||
Reference in New Issue
Block a user