Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] Updating examples #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion examples/clear.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions examples/multi/custom_style.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

opts = {
style: {
top: ". ",
middle: "|-> ",
bottom: "|__ "
top: "╭─➤ ",
middle: "├──➤ ",
bottom: "╰──➤ "
},
format: :bouncing_ball
}
Expand Down
25 changes: 18 additions & 7 deletions examples/multi/threaded.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
# 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
sleep Random.rand(0.1..0.3)
spinner.update(number: "(#{i})", line: spinner.row)
spinner.spin
end

# Randomize conclusion
conclusion = %i[success error].sample
spinner.send(conclusion)
end
end

Expand Down