To follow up a bit on the suggestion about just removing the useless output from the text:
# supposing the program output is all stored in $text: $text =~ s/.*\r//g;
Since "." won't match a "\n" (and Tk::Text does the right thing with "\n" in its display), the above regex will retain the original line count of the program output, and on each line, it removes everything up to and including the right-most "\r", leaving only the text that follows from that point to the next "\n" (which is all that would have been visible in a normal terminal display).

update: And as for actually making Tk::Text emulate a normal terminal display, you would need to keep track of the current line number in the text buffer (where the next chunk of program output will go), something like this:

# you need to know which line number you're at in the Tk::Text buffer # -- let's suppose that's in a variable called "$line_number" @updates = split( /\r/, $latest_output ); for my $string ( @updates ) { $tktext_widget->SetCursor( "$line_number.0" ); # go to start of +that line; $tktext_widget->deleteToEndofLine; $tktext_widget->Insert( $string ); $line_number += ( $string =~ tr/\n// ); }
That's a bit klugey because if one chunk of data from the program containins a lot of "\r"s, it does lots of changes to the widget's text content that won't be seen by the user. But it ought to work as intended, I think. (another update: fixed typo on "+=")

In reply to Re: inserting program output in Tk::Text by graff
in thread inserting program output in Tk::Text by diamantis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.