Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^3: Console Output Formatting Help Required

by tarunmudgal4u (Sexton)
on Sep 29, 2013 at 13:06 UTC ( #1056218=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Console Output Formatting Help Required
in thread Console Output Formatting Help Required

Hi, I've written two methods printR and printL to write text on the right side and left side respectively on the screen. It's working fine.

sub printL { my $str = shift; my $widthL = 60; #my $widthR = 80; my @strWrap = (); for (1 .. int (length $str)/$widthL ) { push @strWrap, substr($str, 0, $widthL-1, '')."\n"; } #push @strWrap, $str; print "@strWrap"; printf ("%-80s", "$str"); } sub printR { if (@_ == 1){ my $status = shift; print "$status\n"; } elsif (@_ == 2){ my $status = shift; my $msg = shift; print "$status\n$msg\n"; } }

Now there is one problem. In my code I've used multiple printL methods consecutively. So first printL writes at the left side of the screen and leaves the cursor at that place only and next consecutive printL continues from there. that's not what I want.

I have a solution for this. I can find the current cursor coordinates and if x coordinate is greater than 0, next printL will add newline char at the beginning of the string. But, how to find current cursor position, I don't know. Can somebody help me with this?

Perl tell function doesn't help me with this as it returns the position in bytes. Any suggestion would also fine.


Comment on Re^3: Console Output Formatting Help Required
Download Code
Re^4: Console Output Formatting Help Required
by Anonymous Monk on Sep 30, 2013 at 10:40 UTC
    Its simple, keep track of what you printed :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1056218]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2014-09-20 03:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (152 votes), past polls