On Nov 23, 2008, at 12:30 PM, Shot (Piotr Szotkowski) wrote:
> Rob Biedenharn:
>> On Nov 22, 2008, at 8:18 PM, Shot (Piotr Szotkowski) wrote:
>
>>> I want to track the progress of a set of
>>> (forkoff=92d) processes in a simple way. [=85]
>
>>> print '.' * 25; (0...25).sort_by{rand}.each { |n| print "\r"; =20
>>> print "\c[[C" * n; print 'o'; sleep 0.5 }; print "\n"
>
>> status=3D'.'*25; print status; (0...25).sort_by{rand}.each{|n| =20
>> status[n]=3D'o';
>> print "\r#{status}"; sleep(0.1+rand/10.0)};puts
>
> A very good idea, but unfortunately it doesn=92t work in a forkoff=92d
> block; every block gets its own copy of the original status and so
> generates a line with 24 dots and one o:
>
> shot@devielle:~$ irb -rubygems
>>> require 'forkoff'
> =3D> true
>>> status=3D'.'*25; print status; (0...25).sort_by{rand}.forkoff{|n| =20=

>>> status[n]=3D'o'; print "\r#{status}"; sleep(0.1+rand/10.0)};puts
> ..................o......
> =3D> nil
>
> Hence my need for a right arrow, or for printing a =91transparent=92
> character that doesn=92t overwrite what=92s already under the cursor.

I took a quick look at the code for forkoff and unless you're =20
increasing the processes (or just looking for one that is "slow"), =20
this doesn't seem to help much.

>
>
>> You could, perhaps, add a clear-to-EOL sequence, too.
>
> I=92m sorry, but I=92m a bit braindead today; where would I want to =
use
> this? (And, when we=92re at it, what=92s the escape sentence for it?)

That sequence and other ANSI control sequences can be found via the =20
web, for example, at:
	http://en.wikipedia.org/wiki/ANSI_escape_code

> Thanks a lot for your interest in this thread and your reply!
>
> -- Shot
> --=20
> A distributed system is one in which I cannot get something done =20
> because
> a machine I've never heard of is down.                 -- Leslie =20
> Lamport



Perhaps a sequence of:
     "\[[s\[[#{n+1}Go\[[u"
if your terminal supports the save/restore cursor position

print '.' * 25; (0...25).sort_by{rand}.forkoff { |n| sleep(0.25+rand/=20
10.0); print "\033[s\033[#{n+1}Go\033[u" }; print "\n"


Or manually go back to the "end" of the line each time:
     "\033[#{n+1}Go\033[#{25+1}G"

print '.' * 25; (0...25).sort_by{rand}.each { |n| sleep(0.2+rand/2.0); =20=

print "\033[#{n+1}Go\033[26G" }; print "\n"


Perhaps get the status via some other mechanism in another process =20
(but that's going to fly away from a "simple way" even faster).

-Rob

Rob Biedenharn		http://agileconsultingllc.com
Rob / AgileConsultingLLC.com=