From: "Hal E. Fulton" Date: 2003-07-01T05:58:58+09:00 Subject: Re: OT: Status Display ----- Original Message ----- From: "Josef 'Jupp' Schugt" To: "ruby-talk ML" Sent: Monday, June 30, 2003 3:39 PM Subject: Re: OT: Status Display > Saluton! > > * Juergen Lang; 2003-06-30, 12:44 UTC: > > Now my Q: Is it possible with ruby to diplay the percentage of the > > current status always on the same position on the screen instead of > > seperated by newlines or something like that? > > A very portable way is this: > > rubout = 8.chr * 4 > 0.upto(100) {|i| > print rubout unless i == 0 > printf "%3d%%", i > $stdout.flush > sleep 1 > } > > rubout is backspace characters that remove the percentage text. At > first run it is not written. Afterwards it removes the text already > visible (you could output a dummy 0% so that the if statement is not > needed). printf does output a three digit percentage (see man 3 > printf for details on printf). The most important statement is the > flush statement. Someone pointed out to me that in some environments (perhaps in emacs, for example?) a backspace will actually be printed as a ^H. I've always preferred just to do a single carriage return at the end, and ensure that my output strings are all the same length (formatted output) so as not to leave any "trash" when a short line is printed over a longer one... Hal -- Hal Fulton hal9000@hypermetrics.com