This commit is contained in:
Aşkın Gedik 2015-12-30 16:21:42 +02:00
parent 39b3f8680c
commit b31b23d45f
6 changed files with 41 additions and 39 deletions

View file

@ -30,7 +30,7 @@ sp.stop
`delay`: `default = 0.1` `delay`: `default = 0.1`
`chars`: you can choose charset from [CHARSET](src/spinner/charset.cr) `default = CHARSET[:pipe]` `chars`: you can choose charset from [CHARSET](src/spinner/charset.cr) `default = Spinner::Charset[:pipe]`
## Examples ## Examples
@ -38,7 +38,7 @@ sp.stop
require "spinner" require "spinner"
require "colorize" require "colorize"
chars = CHARSET[:arrow].map do |c| chars = Spinner::Charset[:arrow].map do |c|
c.colorize(:light_green) c.colorize(:light_green)
end end

View file

@ -1,6 +1,6 @@
require "../src/spinner" require "../src/spinner"
CHARSET.values.each do |chars| Spinner::Charset.values.each do |chars|
sp = Spin.new(0.1, chars) sp = Spin.new(0.1, chars)
sp.start sp.start
sleep 2 sleep 2

View file

@ -1,7 +1,7 @@
require "../src/spinner" require "../src/spinner"
require "colorize" require "colorize"
chars = CHARSET[:arrow].map do |c| chars = Spinner::Charset[:arrow].map do |c|
c.colorize(:light_green) c.colorize(:light_green)
end end

View file

@ -7,13 +7,13 @@ sleep 3
sp.stop sp.stop
puts "end!" puts "end!"
sp1 = Spin.new(0.1, CHARSET[:three_dots]) sp1 = Spin.new(0.1, Spinner::Charset[:three_dots])
sp1.start sp1.start
sleep 3 sleep 3
sp1.stop sp1.stop
sp1 = Spin.new(0.1) sp1 = Spin.new(0.1)
sp1.chars = CHARSET[:arrow] sp1.chars = Spinner::Charset[:arrow]
sp1.start sp1.start
sleep 3 sleep 3
sp1.stop sp1.stop

View file

@ -6,7 +6,7 @@ class Spin
CL = STDOUT.tty? ? "\u001b[0G" : "\u000d \u000d" CL = STDOUT.tty? ? "\u001b[0G" : "\u000d \u000d"
CLEAR = STDOUT.tty? ? "\u001b[2K" : "\u000d" CLEAR = STDOUT.tty? ? "\u001b[2K" : "\u000d"
def initialize(@delay = 0.1, @chars = CHARSET[:pipe]) def initialize(@delay = 0.1, @chars = Spinner::Charset[:pipe])
@state = true @state = true
end end

View file

@ -1,32 +1,34 @@
CHARSET = { module Spinner
arrow: {"", "", "", "", "", "", "", ""}, Charset = {
fan: {"", "", "", "", "", "", "", ""}, arrow: {"", "", "", "", "", "", "", ""},
fan1: {"+", "x"}, fan: {"", "", "", "", "", "", "", ""},
fan2: {"v", "<", "^", ">"}, fan1: {"+", "x"},
triangle: {"", "", "", ""}, fan2: {"v", "<", "^", ">"},
square: {"", "", "", ""}, triangle: {"", "", "", ""},
circle: {"", "", "", ""}, square: {"", "", "", ""},
big_circle: {"", "", "", ""}, circle: {"", "", "", ""},
boom: {".", "o", "O", "@", "*"}, big_circle: {"", "", "", ""},
pipe: {"|", "/", "-", "\\"}, boom: {".", "o", "O", "@", "*"},
alphabet: {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}, pipe: {"|", "/", "-", "\\"},
three_dots: {". ", ".. ", "..."}, alphabet: {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"},
eyes: {"◡◡", "⊙⊙", "◠◠"}, three_dots: {". ", ".. ", "..."},
dots: {"", "", "", "", "", "", "", ""}, eyes: {"◡◡", "⊙⊙", "◠◠"},
snake: {"", "", "", "", "", "", "", ""}, dots: {"", "", "", "", "", "", "", ""},
snake1: {"", "", "", "", "", "", "", "", "", ""}, snake: {"", "", "", "", "", "", "", ""},
snake2: {"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""}, snake1: {"", "", "", "", "", "", "", "", "", ""},
square1: {"", "", "", ""}, snake2: {"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
square2: {"", "", "", ""}, square1: {"", "", "", ""},
square3: {"", "", "", "", "", "", "", "", "", "", "", "", ""}, square2: {"", "", "", ""},
square4: {"", "", "", "", "", "", "", "", "", "", "", "", ""}, square3: {"", "", "", "", "", "", "", "", "", "", "", "", ""},
square5: {"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""}, square4: {"", "", "", "", "", "", "", "", "", "", "", "", ""},
thin_arrow: {"", "", "", ""}, square5: {"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
big_arraw: {"", "", "", "", "", "", "", ""}, thin_arrow: {"", "", "", ""},
baloon: {".", "o", "O", "°", "O", "o", "."}, big_arraw: {"", "", "", "", "", "", "", ""},
progress: {"[ ]", "[= ]", "[== ]", "[=== ]", "[==== ]", "[===== ]", "[====== ]", "[======= ]", "[======== ]", "[========= ]", "[==========]"}, baloon: {".", "o", "O", "°", "O", "o", "."},
progress1: {"(*---------)", "(-*--------)", "(--*-------)", "(---*------)", "(----*-----)", "(-----*----)", "(------*---)", "(-------*--)", "(--------*-)", "(---------*)"}, progress: {"[ ]", "[= ]", "[== ]", "[=== ]", "[==== ]", "[===== ]", "[====== ]", "[======= ]", "[======== ]", "[========= ]", "[==========]"},
progress2: {"█▒▒▒▒▒▒▒▒▒", "███▒▒▒▒▒▒▒", "█████▒▒▒▒▒", "███████▒▒▒", "██████████"}, progress1: {"(*---------)", "(-*--------)", "(--*-------)", "(---*------)", "(----*-----)", "(-----*----)", "(------*---)", "(-------*--)", "(--------*-)", "(---------*)"},
progress3: {"[ ]", "[=> ]", "[===> ]", "[=====> ]", "[======> ]", "[========> ]", "[==========> ]", "[============> ]", "[==============> ]", "[================> ]", "[==================> ]", "[===================>]"}, progress2: {"█▒▒▒▒▒▒▒▒▒", "███▒▒▒▒▒▒▒", "█████▒▒▒▒▒", "███████▒▒▒", "██████████"},
fish: {">))'> ", " >))'> ", " >))'> ", " >))'> ", " >))'>", " <'((<", " <'((< ", " <'((< ", " <'((< ", "<'((< "}, progress3: {"[ ]", "[=> ]", "[===> ]", "[=====> ]", "[======> ]", "[========> ]", "[==========> ]", "[============> ]", "[==============> ]", "[================> ]", "[==================> ]", "[===================>]"},
} fish: {">))'> ", " >))'> ", " >))'> ", " >))'> ", " >))'>", " <'((<", " <'((< ", " <'((< ", " <'((< ", "<'((< "},
}
end