"puts" without line feed

B

Bob Miner

Hi,
Is there a way to show output on a single line in the command prompt,
overwriting each time instead of linefeeding everytime I puts 'my data'
?

I want the appearance of progress thru numerous iterations without
scrollin off into oblivion.
 
P

Patrick Li

it's "print"

print "line without line-feed"

or was it "prints" i don't remember.

-Patrick
 
M

Michael Guterl

Hi,
Is there a way to show output on a single line in the command prompt,
overwriting each time instead of linefeeding everytime I puts 'my data'
?

I want the appearance of progress thru numerous iterations without
scrollin off into oblivion.

try print instead of puts
 
T

Thomas Wieczorek

Heya!

Hi,
Is there a way to show output on a single line in the command prompt,
overwriting each time instead of linefeeding everytime I puts 'my data'
?

You can use print() instead of puts() which doesn't add a linefeed.
 
S

Sebastian Hungerecker

Bob said:
Is there a way to show output on a single line in the command prompt,
overwriting each time instead of linefeeding everytime I puts 'my data'
?

$stdout.sync = true
5.times do |i|
print "\r#{i}"
sleep 1
end

HTH,
Sebastian
 
B

Bob Miner

uze guyz are SO close.

Print gives me

123456.......*to a new line*.......*to another new line*.....

I'm tryin for

1

then

2 (where 1 was)

then

3 (where 1, then 2 were)

so it rolls along "in place"

Kinda silly, I know.....I guess I should be happy the darn thing runs &
does what I want at all, eh?
Thanks for kind & timely responses.
 
T

Tim Hunter

Bob said:
uze guyz are SO close.

Print gives me

123456.......*to a new line*.......*to another new line*.....

I'm tryin for

1

then

2 (where 1 was)

then

3 (where 1, then 2 were)

so it rolls along "in place"

Kinda silly, I know.....I guess I should be happy the darn thing runs &
does what I want at all, eh?
Thanks for kind & timely responses.

Try Sebastian's example. It does what you want.
 
F

F. Senault

Le 10 août 2008 à 21:27, Bob Miner a écrit :
so it rolls along "in place"

Try writing a "backspace" control caracter (ctrl-h, ascii code 8) ; for
example :

print "Countdown : 9"
9.downto(0) do |x|
print "\C-h#{x}"
sleep 1
end
puts

(I'm not entirely sure it's completely cross-platform, but this simple
example works well with Windows and Unixoïds.)

Fred
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top