From b31b23d45fe868a06271575bbdf06bf61f6e9f0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=C5=9Fk=C4=B1n=20Gedik?= Date: Wed, 30 Dec 2015 16:21:42 +0200 Subject: [PATCH] charset --- README.md | 4 +-- examples/all.cr | 2 +- examples/color.cr | 2 +- examples/simple.cr | 4 +-- src/spinner.cr | 2 +- src/spinner/charset.cr | 66 ++++++++++++++++++++++-------------------- 6 files changed, 41 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 4b4fe54..cd49a57 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ sp.stop `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 @@ -38,7 +38,7 @@ sp.stop require "spinner" require "colorize" -chars = CHARSET[:arrow].map do |c| +chars = Spinner::Charset[:arrow].map do |c| c.colorize(:light_green) end diff --git a/examples/all.cr b/examples/all.cr index e843557..f16f0c4 100644 --- a/examples/all.cr +++ b/examples/all.cr @@ -1,6 +1,6 @@ require "../src/spinner" -CHARSET.values.each do |chars| +Spinner::Charset.values.each do |chars| sp = Spin.new(0.1, chars) sp.start sleep 2 diff --git a/examples/color.cr b/examples/color.cr index 76583bd..5387e67 100644 --- a/examples/color.cr +++ b/examples/color.cr @@ -1,7 +1,7 @@ require "../src/spinner" require "colorize" -chars = CHARSET[:arrow].map do |c| +chars = Spinner::Charset[:arrow].map do |c| c.colorize(:light_green) end diff --git a/examples/simple.cr b/examples/simple.cr index 1a43138..b01383d 100644 --- a/examples/simple.cr +++ b/examples/simple.cr @@ -7,13 +7,13 @@ sleep 3 sp.stop puts "end!" -sp1 = Spin.new(0.1, CHARSET[:three_dots]) +sp1 = Spin.new(0.1, Spinner::Charset[:three_dots]) sp1.start sleep 3 sp1.stop sp1 = Spin.new(0.1) -sp1.chars = CHARSET[:arrow] +sp1.chars = Spinner::Charset[:arrow] sp1.start sleep 3 sp1.stop diff --git a/src/spinner.cr b/src/spinner.cr index d2811e3..2e003a6 100644 --- a/src/spinner.cr +++ b/src/spinner.cr @@ -6,7 +6,7 @@ class Spin CL = STDOUT.tty? ? "\u001b[0G" : "\u000d \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 end diff --git a/src/spinner/charset.cr b/src/spinner/charset.cr index 5bce012..501c466 100644 --- a/src/spinner/charset.cr +++ b/src/spinner/charset.cr @@ -1,32 +1,34 @@ -CHARSET = { - arrow: {"←", "↖", "↑", "↗", "→", "↘", "↓", "↙"}, - fan: {"┤", "┘", "┴", "└", "├", "┌", "┬", "┐"}, - fan1: {"+", "x"}, - fan2: {"v", "<", "^", ">"}, - triangle: {"◢", "◣", "◤", "◥"}, - square: {"◰", "◳", "◲", "◱"}, - circle: {"◴", "◷", "◶", "◵"}, - big_circle: {"◐", "◓", "◑", "◒"}, - boom: {".", "o", "O", "@", "*"}, - pipe: {"|", "/", "-", "\\"}, - 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"}, - three_dots: {". ", ".. ", "..."}, - eyes: {"◡◡", "⊙⊙", "◠◠"}, - dots: {"⠁", "⠂", "⠄", "⡀", "⢀", "⠠", "⠐", "⠈"}, - snake: {"⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷"}, - snake1: {"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}, - snake2: {"⠋", "⠙", "⠚", "⠒", "⠂", "⠂", "⠒", "⠲", "⠴", "⠦", "⠖", "⠒", "⠐", "⠐", "⠒", "⠓", "⠋"}, - square1: {"■", "□", "▪", "▫"}, - square2: {"▖", "▘", "▝", "▗"}, - square3: {"▁", "▃", "▄", "▅", "▆", "▇", "█", "▇", "▆", "▅", "▄", "▃", "▁"}, - square4: {"▉", "▊", "▋", "▌", "▍", "▎", "▏", "▎", "▍", "▌", "▋", "▊", "▉"}, - square5: {"▁", "▂", "▃", "▄", "▅", "▆", "▇", "█", "▉", "▊", "▋", "▌", "▍", "▎", "▏", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█", "▇", "▆", "▅", "▄", "▃", "▂", "▁"}, - thin_arrow: {"←", "↑", "→", "↓"}, - big_arraw: {"⇐", "⇖", "⇑", "⇗", "⇒", "⇘", "⇓", "⇙"}, - baloon: {".", "o", "O", "°", "O", "o", "."}, - progress: {"[ ]", "[= ]", "[== ]", "[=== ]", "[==== ]", "[===== ]", "[====== ]", "[======= ]", "[======== ]", "[========= ]", "[==========]"}, - progress1: {"(*---------)", "(-*--------)", "(--*-------)", "(---*------)", "(----*-----)", "(-----*----)", "(------*---)", "(-------*--)", "(--------*-)", "(---------*)"}, - progress2: {"█▒▒▒▒▒▒▒▒▒", "███▒▒▒▒▒▒▒", "█████▒▒▒▒▒", "███████▒▒▒", "██████████"}, - progress3: {"[ ]", "[=> ]", "[===> ]", "[=====> ]", "[======> ]", "[========> ]", "[==========> ]", "[============> ]", "[==============> ]", "[================> ]", "[==================> ]", "[===================>]"}, - fish: {">))'> ", " >))'> ", " >))'> ", " >))'> ", " >))'>", " <'((<", " <'((< ", " <'((< ", " <'((< ", "<'((< "}, -} +module Spinner + Charset = { + arrow: {"←", "↖", "↑", "↗", "→", "↘", "↓", "↙"}, + fan: {"┤", "┘", "┴", "└", "├", "┌", "┬", "┐"}, + fan1: {"+", "x"}, + fan2: {"v", "<", "^", ">"}, + triangle: {"◢", "◣", "◤", "◥"}, + square: {"◰", "◳", "◲", "◱"}, + circle: {"◴", "◷", "◶", "◵"}, + big_circle: {"◐", "◓", "◑", "◒"}, + boom: {".", "o", "O", "@", "*"}, + pipe: {"|", "/", "-", "\\"}, + 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"}, + three_dots: {". ", ".. ", "..."}, + eyes: {"◡◡", "⊙⊙", "◠◠"}, + dots: {"⠁", "⠂", "⠄", "⡀", "⢀", "⠠", "⠐", "⠈"}, + snake: {"⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷"}, + snake1: {"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}, + snake2: {"⠋", "⠙", "⠚", "⠒", "⠂", "⠂", "⠒", "⠲", "⠴", "⠦", "⠖", "⠒", "⠐", "⠐", "⠒", "⠓", "⠋"}, + square1: {"■", "□", "▪", "▫"}, + square2: {"▖", "▘", "▝", "▗"}, + square3: {"▁", "▃", "▄", "▅", "▆", "▇", "█", "▇", "▆", "▅", "▄", "▃", "▁"}, + square4: {"▉", "▊", "▋", "▌", "▍", "▎", "▏", "▎", "▍", "▌", "▋", "▊", "▉"}, + square5: {"▁", "▂", "▃", "▄", "▅", "▆", "▇", "█", "▉", "▊", "▋", "▌", "▍", "▎", "▏", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█", "▇", "▆", "▅", "▄", "▃", "▂", "▁"}, + thin_arrow: {"←", "↑", "→", "↓"}, + big_arraw: {"⇐", "⇖", "⇑", "⇗", "⇒", "⇘", "⇓", "⇙"}, + baloon: {".", "o", "O", "°", "O", "o", "."}, + progress: {"[ ]", "[= ]", "[== ]", "[=== ]", "[==== ]", "[===== ]", "[====== ]", "[======= ]", "[======== ]", "[========= ]", "[==========]"}, + progress1: {"(*---------)", "(-*--------)", "(--*-------)", "(---*------)", "(----*-----)", "(-----*----)", "(------*---)", "(-------*--)", "(--------*-)", "(---------*)"}, + progress2: {"█▒▒▒▒▒▒▒▒▒", "███▒▒▒▒▒▒▒", "█████▒▒▒▒▒", "███████▒▒▒", "██████████"}, + progress3: {"[ ]", "[=> ]", "[===> ]", "[=====> ]", "[======> ]", "[========> ]", "[==========> ]", "[============> ]", "[==============> ]", "[================> ]", "[==================> ]", "[===================>]"}, + fish: {">))'> ", " >))'> ", " >))'> ", " >))'> ", " >))'>", " <'((<", " <'((< ", " <'((< ", " <'((< ", "<'((< "}, + } +end