I
I
iMa3str02015-02-04 19:20:44
ruby
iMa3str0, 2015-02-04 19:20:44

How to animate input line?

In general, I want to make a line animation so that during the input by a person (gets) in place of the letter "the wand is spinning"
The cycle for turning the wand is here:

def ss
  while true
    print "|\r"
    sleep 0.2
    print "/\r"
    sleep 0.2
    print "-\r"
    sleep 0.2
    print "\\\r"
    sleep 0.2	
  end
end

And here's how to connect it with writing a line - it's not clear ... I
tried through streams, but nothing happened.
a = Thread.new { ss }
Can someone tell me?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Shetani, 2015-02-05
@Shetani

Can it be like this

def spinner
  chars = %w{ | / - \\ }
  thread = Thread.new { yield }
  while thread.alive?
    $stdout.print chars[0]
    sleep 0.5
    $stdout.print "\b"
    chars.push chars.shift
  end
  thread.join
end

Call for example like this:
spinner do
  name=gets
  puts name
end

But in place of the entered characters, there will most likely be dashes.

V
Viktor Vsk, 2015-02-05
@viktorvsk

If you want the wand to spin at the same time and you can enter text, then this is very unlikely.
If you just animate something:
https://github.com/prydonius/spinning_cursor
https://www.ruby-toolbox.com/categories/CLI_Progre...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question