Ask a Question related to PERL Beginners, Design and Development.
-
James Edward Gray II #1
Get Terminal Width and Height, Pure Perl
Okay, I have a terminal program I need to get the width and height for.
I have a very good reason needing to do it with a base 5.8 Perl
install, if at all possible. Unfortunately, that rules out the super
easy Term::ReadKey CPAN module.
(Side note: I do have Term::ReadKey installed and am very aware of how
wonderful it is. In fact, why isn't this a standard module??? I just
can't count on it being on the box this program will be run on. I'll
fight that fight if I have to, but first I thought I would check for
another option.)
So my question is, is there a "Pure Perl" way to fetch the terminal
columns and rows?
Thanks.
James
James Edward Gray II Guest
-
how to get stream width and height?
hello; is there a way to get a streams width and heigh so that I can dynamically change the size of the video object? thanks dsdsdsdsd Chicago -
ActionScripting Width, Height, X, and Y ?
ActionScripting Width, Height, X, and Y ? Anyone know what actionscript is involved in changing the width, height, x, and y data for a graphic... -
Stage width & height
Has anyone else noticed that stage.width and stage.height report incorrectly when yopu test your movie at 100% Does anyone have a good way round... -
Can't control height and width
When I draw a rounded rectangle, i can no longer get a Height and Width measurement readout from the properties window. It gives me 64000 for the... -
GetTextExtent (get RTF string's width/height) function in Win32 Perl?
Microsoft Visual C++ and Borland (Inprise) Delphi have GetTextExtent (and similar functions) to determine the width and height of a string of RTF... -
Charles K. Clarkson #2
RE: Get Terminal Width and Height, Pure Perl
James Edward Gray II <james@grayproductions.net> wrote:
:
: So my question is, is there a "Pure Perl" way to fetch
: the terminal columns and rows?
I took a look at the source of Term::ReadKey and it
seemed to be pure perl. Are you sure it's not? If it is,
you could use it as a guide to write your own sub. Or,
if you're allowed to install multiple files, you could
include this module in your package.
HTH,
Charles K. Clarkson
--
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328
Charles K. Clarkson Guest
-
James Edward Gray II #3
Re: Get Terminal Width and Height, Pure Perl
On Dec 15, 2003, at 10:51 AM, Charles K. Clarkson wrote:
Haven't got a clue, to tell the truth! <laughs>> James Edward Gray II <james@grayproductions.net> wrote:
> :
> : So my question is, is there a "Pure Perl" way to fetch
> : the terminal columns and rows?
>
>
> I took a look at the source of Term::ReadKey and it
> seemed to be pure perl. Are you sure it's not?
I assumed it was not, for two reasons. One, the POD says,
"Term::ReadKey is a compiled perl module..." and that ugly compiled
word in there scared me. And two, I can't see where the function calls
at the beginning of GetTerminalSize() are coming from
(termsizeoptions(), GetTermSizeVIO(), GetTermSizeGWINSZ(),
GetTermSizeGSIZE(), GetTermSizeWin32()).
I also just had the thought to go check the CPAN's listing. It said
'Rdcf?' under the DSLIP column. I'm pretty sure that middle 'c' in
there means it's written in C and Perl. I know how dangerous
assumptions are though, especially mine, and I won't be surprised if
I'm wrong.
I did try to look at the module, but as you can see, I can't tell what> If it is, you could use it as a guide to write your own sub. Or,
> if you're allowed to install multiple files, you could
> include this module in your package.
it's doing.
Finally, I can only use the include it trick if it is indeed pure Perl,
right?
Thanks for all the good ideas. I did try them.
James
James Edward Gray II Guest
-
Bob Showalter #4
RE: Get Terminal Width and Height, Pure Perl
James Edward Gray II wrote:
You're right, it's not a pure perl module. The "bootstrap" statement around> On Dec 15, 2003, at 10:51 AM, Charles K. Clarkson wrote:
>>> > James Edward Gray II <james@grayproductions.net> wrote:> >> > >
> > > So my question is, is there a "Pure Perl" way to fetch
> > > the terminal columns and rows?
> >
> > I took a look at the source of Term::ReadKey and it
> > seemed to be pure perl. Are you sure it's not?
> Haven't got a clue, to tell the truth! <laughs>
>
> I assumed it was not, for two reasons. One, the POD says,
> "Term::ReadKey is a compiled perl module..." and that ugly compiled
> word in there scared me. And two, I can't see where the
> function calls
> at the beginning of GetTerminalSize() are coming from
> (termsizeoptions(), GetTermSizeVIO(), GetTermSizeGWINSZ(),
> GetTermSizeGSIZE(), GetTermSizeWin32()).
>
> I also just had the thought to go check the CPAN's listing. It said
> 'Rdcf?' under the DSLIP column. I'm pretty sure that middle 'c' in
> there means it's written in C and Perl. I know how dangerous
> assumptions are though, especially mine, and I won't be surprised if
> I'm wrong.
line 240 gives it away as well.
It's trying to make the process platform-independent, which is rather>>> > If it is, you could use it as a guide to write your own sub. Or,
> > if you're allowed to install multiple files, you could
> > include this module in your package.
> I did try to look at the module, but as you can see, I can't
> tell what
> it's doing.
tricky.
You might be able to get away with something as simple as querying the LINES
and COLUMNS environment variables. Or use the output from 'tput lines' and
'tput columns'. It all depends on your platform...
Bob Showalter Guest
-
Steven Kreuzer #5
RE: Get Terminal Width and Height, Pure Perl
>> You might be able to get away with something as simple as querying
theActually, its tput cols>> LINES and COLUMNS environment variables. Or use the output from 'tput
>> lines' and 'tput columns'. It all depends on your platform...
Steven Kreuzer
Linux Systems Administrator
Etagon, Inc
W: 646.728.0656
F: 646.728.0607
E: [email]steven_kreuzer@etagon.com[/email]
Steven Kreuzer Guest
-
Clifton Wood #6
Re: Get Terminal Width and Height, Pure Perl
In article <8A7DF9E1-2F1C-11D8-B912-000A95BA45F8@grayproductions.net>,
James Edward Gray II <james@grayproductions.net> wrote:
Would you be adverse to parsing output from a unix command?> Okay, I have a terminal program I need to get the width and height for.
> I have a very good reason needing to do it with a base 5.8 Perl
> install, if at all possible. Unfortunately, that rules out the super
> easy Term::ReadKey CPAN module.
>
> (Side note: I do have Term::ReadKey installed and am very aware of how
> wonderful it is. In fact, why isn't this a standard module??? I just
> can't count on it being on the box this program will be run on. I'll
> fight that fight if I have to, but first I thought I would check for
> another option.)
>
> So my question is, is there a "Pure Perl" way to fetch the terminal
> columns and rows?
use strict;
my ($rows, $cols);
$data = `stty -a`;
if ($data =~ /rows (\d+)\; columns (\d+)/) {
($rows, $cols) = ($1, $2);
} else {
print "No match.\n";
}
Of course, this is NOT pure Perl, but stty exists on most systems
so this should be *fairly* reliable. At the very least, it may
hold you until you can find a better solution.
- C
Clifton Wood Guest
-
Unregistered #7
Re: Get Terminal Width and Height, Pure Perl
Code:use Term::ReadKey qw(GetTerminalSize); sub get_term_cols { my $cols = ((GetTerminalSize())[0]); # cols = 0; lines = 1 $cols and return $cols; # alternative: -f "/bin/tput" or die("/bin/tput: command not found.."); open( my $OH, '-|', "/bin/tput cols" ) or die($!); chomp(($cols) = <$OH>); close($OH) or die($!); return $cols } print "Columns on your terminal: ".get_term_cols()."\n";Unregistered Guest



Reply With Quote

