Reputation: 55
I can't find how to refresh a single line of output with Elixir.
In Ruby we can do this :
n = 0
loop do
print n
$stdout.flush
n += 1
end
But what should I use to do the same with Elixir ?
Upvotes: 1
Views: 708
Reputation: 222348
Use IO.write/1
. There's no need to manually flush stdout as far as I can see. The following code writes 1 to 10 in a single line with a 1 second delay between each number. stdout is flushed automatically after each write.
for i <- 1..10 do
IO.write i
:timer.sleep(1000)
end
Output:
12345678910
(With a 1 second delay between each number.)
Upvotes: 3