Creating a pacifier in command line program

J

Jerry Mr

I am trying to create a program that, at one part, replaces already
displayed on the line with another.

For example:

Lets say the program is recursing directories.

It should display:

checking c:\Program Files\

then when it is done with that directory replace that line with the
next, not create another below it.

I have been unable to locate information about this, though I don't
really know what to call it.

Thank you.
 
T

Tim Hunter

Jerry said:
I am trying to create a program that, at one part, replaces already
displayed on the line with another.

For example:

Lets say the program is recursing directories.

It should display:

checking c:\Program Files\

then when it is done with that directory replace that line with the
next, not create another below it.

I have been unable to locate information about this, though I don't
really know what to call it.

Thank you.

I think this will work in Windows but I don't have it to test. It works
in OS X and Linux terminal windows.

Instead of terminating the output line with a \n (or allowing it to
default to a \n), use \r instead. "\r" is a carriage return, so the
cursor will return to the start of the same line and overprint it.

For example,

10.times { |n| printf("Hello %d\r", n);sleep 1 }

Will print

Hello 0
Hello 1
Hello 2

etc., except each new "Hello" line overprints the previous one so you
only see 1 line.
 
J

Jerry Piazza

Well, now I am trying to impliment this into a program.

Example:

def spinner spin_trigger
while (spin_trigger == true)
print "\\\r"
sleep 1
print "|\r"
sleep 1
print "/\r"
sleep 1
print "-\r"
sleep 1
end
end

spin = true
Thread.new do
spinner spin
end
files = Dir.glob("c/**/*.txt)
spin = false


All I am getting is "\" until the Dir command is complete.
The method works perfectly when not running inside another program.

It must have something to do with the new thread I am creating, but I
cannot figure out what...hrm.
 
J

Jerry Piazza

files = Dir.glob("c/**/*.txt)
--> files = Dir.glob("c/**/*.txt")
Yes, I realize there is a typo after the .txt.
That typo is not in the program.
 

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

Forum statistics

Threads
474,167
Messages
2,570,910
Members
47,453
Latest member
MadelinePh

Latest Threads

Top