ruby - Create the loading three little dots -
hello how can make 3 dot loading (...), except without making new line everytime:
loading
loading.
loading...
loading..
loading.
and on:
this came with, problem can't remove dots 1 one if loading continues more 1.5 seconds.
puts "sending" sleep(0.5) print "." sleep(0.5) print "." sleep(0.5) print "."
hopefully clear enough.
thank help.
10.times |i| print "sending." + ("." * (i % 3)) + " \r" $stdout.flush sleep(0.5) end
so, how work?
10.times |i|
repeat following code 10 times, variable i
indicating current iteration (0, 1, 2, 3, 4...)
print "sending." + ("." * (i % 3)) + " \r"
print phrase "sending." followed couple of things:
("." * (i % 3))
repeats ("multiplies") string"."
several times,i % 3
, remainder ofi
when it's divided 3. wheni
7,i % 3
1."\r"
moves cursor beginning of line without making new line. if think of typewriter, it's returning carriage (the bit types) beginning of line can type on same line again. it's carriage return.$stdout.flush
make sure data prints.
sleep(0.5)
sleep half sec.
Comments
Post a Comment