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 of i when it's divided 3. when i 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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -