From: "Shot (Piotr Szotkowski)" Date: 2008-11-24T09:00:25+09:00 Subject: Re: Printing right arrow vs. a sane progressbar library --6sX45UoQRIJXqkqR Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Rob Biedenharn: > On Nov 23, 2008, at 12:30 PM, Shot (Piotr Szotkowski) wrote: >> A very good idea, but unfortunately it doesn=E2=80=99t work in a forkoff= =E2=80=99d >> block; every block gets its own copy of the original status and so >> generates a line with 24 dots and one o [=E2=80=A6] >> Hence my need for a right arrow, or for printing a =E2=80=98transparent= =E2=80=99 >> character that doesn=E2=80=99t overwrite what=E2=80=99s already under th= e cursor. > I took a quick look at the code for forkoff and unless you're > increasing the processes (or just looking for one that is "slow"), > this doesn't seem to help much. Erm, I=E2=80=99m not sure what doesn=E2=80=99t seem to help much. :) Using = the right arrow trick works as expected (as opposed to editing a string that=E2=80=99s unfortunately not the same object across the processes): shot@devielle:~$ irb -rubygems >> require 'forkoff' =3D> true >> print '.' * 25; (0...25).sort_by{rand}.forkoff { |n| print "\r"; print "= \c[[C" * n; print 'o'; sleep 0.5 }; print "\n" ooooooooooooooooooooooooo =3D> nil (Although it=E2=80=99s more prone to race conditions than your solutions be= low.) In my actual case, I want a general mechanism that runs parallel processes in some way (forkoff for now, maybe DRb in the future) and report back some kind of a visual information on how much is being done over time. As I assume each of such parallel runs won=E2=80=99t be able to access the actual objects outside the forked-off block (only copies of them), I believe I can=E2=80=99t employ a simple, tick-based progressbar; the above was my idea to side-step the need of communication with the parent (although I could perhaps make the code that collects=C2=B9 the returned values trigger/tick the progressbar as soon as a result comes in=E2=80=A6). =C2=B9 forkoff has this nice feature that it handles the collecting of the returned values transparently, so I simply don=E2=80=99t *have* any code th= at collects the results at the moment=E2=80=A6 > That sequence and other ANSI control sequences can be found via the > web, for example, at: http://en.wikipedia.org/wiki/ANSI_escape_code Ah, thank you! I started this quest by recalling how \b and \r work, which led me to the ASCII control characters; I totally forgot to look at ANSI stuff, just recalled I can come up with the sequence for the right arrow by `cat`ing stdin to a file and then looking at it. I should=E2=80=99ve thought =E2=80=98ANSI!=E2=80=99 when I saw ^[[C.= :) > Perhaps a sequence of: > "\[[s\[[#{n+1}Go\[[u" > if your terminal supports the save/restore cursor position > Or manually go back to the "end" of the line each time: > "\033[#{n+1}Go\033[#{25+1}G" Actually, a simple "\033[#{n+1}Go" works well enough; thanks! The trick with going to the end of the line each time makes it easier on the eyes if the cursor is visible, so I=E2=80=99ll most probably end up using it. Th= anks again! (And just before sending this email I found out that "\033[?25l" makes the cursor disappear, and so seems to be the cleanest solution without any output-related race conditions whatsoever.) :) -- Shot --=20 And if you really want to find out what someone's made of, have him work through Loelliger's "Threaded Interpreted Languages". -- Peter da Silva --6sX45UoQRIJXqkqR Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) iD8DBQFJKfEZi/mCfdEo8UoRAjhcAJ4lCsncB/5/H/G5hxgsuffge6X1oQCfWi0N vTacLZ6DqClpYDNZXt2dhkA= =R+OY -----END PGP SIGNATURE----- --6sX45UoQRIJXqkqR--