diff --git a/examples/clear.rb b/examples/clear.rb index 6a068ff..7063e50 100644 --- a/examples/clear.rb +++ b/examples/clear.rb @@ -2,7 +2,12 @@ require_relative "../lib/tty-spinner" -spinner = TTY::Spinner.new("[:spinner] Task name", format: :bouncing_ball) +spinner = TTY::Spinner.new( + "[:spinner] Task name", + clear: true, + format: :bouncing_ball +) + 20.times do spinner.spin sleep(0.1) diff --git a/examples/multi/custom_style.rb b/examples/multi/custom_style.rb index bd16fe8..84dc578 100644 --- a/examples/multi/custom_style.rb +++ b/examples/multi/custom_style.rb @@ -4,9 +4,9 @@ opts = { style: { - top: ". ", - middle: "|-> ", - bottom: "|__ " + top: "╭─➤ ", + middle: "├──➤ ", + bottom: "╰──➤ " }, format: :bouncing_ball } diff --git a/examples/multi/threaded.rb b/examples/multi/threaded.rb index 71a3b1c..28f8c41 100644 --- a/examples/multi/threaded.rb +++ b/examples/multi/threaded.rb @@ -1,22 +1,29 @@ # frozen_string_literal: true require_relative "../../lib/tty-spinner" +require "pastel" + +@pastel = Pastel.new + +def spinner_text + ":spinner #{@pastel.bold('No')} :number \t #{@pastel.bold('Row')} :line" +end def spinner_options - [ - ":spinner \e[1mNo\e[0m :number Row :line", + { format: :dots, - error_mark: "✖", - success_mark: "\e[1m\e[32m✓\e[0m\e[0m" - ] + hide_cursor: true, + error_mark: @pastel.red.bold("✖"), + success_mark: @pastel.green.bold("✓") + } end -spinners = TTY::Spinner::Multi.new(*spinner_options) +spinners = TTY::Spinner::Multi.new(spinner_text, **spinner_options) threads = [] 20.times do |i| threads << Thread.new do - spinner = spinners.register(*spinner_options) + spinner = spinners.register(spinner_text, **spinner_options) sleep Random.rand(0.1..0.3) 10.times do @@ -24,6 +31,10 @@ def spinner_options spinner.update(number: "(#{i})", line: spinner.row) spinner.spin end + + # Randomize conclusion + conclusion = %i[success error].sample + spinner.send(conclusion) end end