For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > October 2005 > HTAB, VTAB in a terminal?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author HTAB, VTAB in a terminal?
Bryan R Harris

2005-10-20, 9:55 pm



I'd like to write a perl script to do very simple bitmap editing. The part
I can't figure out is how to write text into the terminal at any x,y point.
Is this possible?

e.g. how can I write an "*" at 10 columns over, 5 rows down in the current
terminal?

TIA.

- Bryan



Jeff 'japhy' Pinyan

2005-10-20, 9:55 pm

On Oct 20, Bryan R Harris said:

> I'd like to write a perl script to do very simple bitmap editing. The part
> I can't figure out is how to write text into the terminal at any x,y point.
> Is this possible?
>
> e.g. how can I write an "*" at 10 columns over, 5 rows down in the current
> terminal?


The Curses module is probably a good starting point. It gives you control
over the terminal displays.

Curses! Foiled again!

--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
http://www.perlmonks.org/ % have long ago been overpaid?
http://princeton.pm.org/ % -- Meister Eckhart
Bryan R Harris

2005-10-20, 9:55 pm



> On Oct 20, Bryan R Harris said:
>
>
> The Curses module is probably a good starting point. It gives you control
> over the terminal displays.
>
> Curses! Foiled again!



Curses is a CPAN module, correct?

I have an office-full of users here, most of which will not not have that
module installed on their workstations. What's the best way to do something
like that? Can I have my perl script install that module on their machines?
Or can I simply embed that module within my script somehow?

- B



Paul Lalli

2005-10-20, 9:55 pm

Bryan R Harris wrote:
> Curses is a CPAN module, correct?
>
> I have an office-full of users here, most of which will not not have that
> module installed on their workstations. What's the best way to do something
> like that? Can I have my perl script install that module on their machines?
> Or can I simply embed that module within my script somehow?


I don't understand your dilemma. "Most of" your users will not have
Curses.pm. Okay, I accept that. But *none* of your users have the
script you're about to write. You're obviously about to tell them to
put it on their machines. Why do you not simply also tell them to put
Curses.pm on their machines?

As for whether or not you can have your script install the module, yes,
you can, using the CPAN.pm module:
#!/usr/bin/perl
use strict;
use warnings;

eval { #Attempt to load Curses
require Curses;
import Curses;
};
#If that failed, load the CPAN.pm module, and use it
#to install Curses.pm
if ($@){
print "Curses not found. About to install it...\n";
require CPAN;
import CPAN;
install ('Curses') or die "Could not install Curses from CPAN!\n";


#At this point, Curses should be installed. Attempt to load it
#again. If it still fails for some reason, let the script die
#as it normally would.
require Curses;
import Curses;
print "Curses successfully installed and used\n";
} else {
print "Curses successfully used the first time\n";
}

Hope this helps,
Paul Lalli

Paul Lalli

2005-10-20, 9:55 pm

Paul Lalli wrote:
> install ('Curses') or die "Could not install Curses from CPAN!\n";


Hrm. Correction. I had assumed install() would return a true or false
value depending on whether or not the installation succeeded. That
appears not to be the case. When I ran this script on a machine
without Curses, Curses successfully installed, but I still got the
"Could not install..." message. I guess you should simply do
install('Curses');
and then attempt to require Curses. If it successfully installed, the
require will work fine (assuming @INC is set up correctly), if not, the
script will die when require can't find the module.

Paul Lalli

Jeff 'japhy' Pinyan

2005-10-20, 9:55 pm

On Oct 20, Bryan R Harris said:

> Curses is a CPAN module, correct?
>
> I have an office-full of users here, most of which will not not have that
> module installed on their workstations. What's the best way to do something
> like that? Can I have my perl script install that module on their machines?
> Or can I simply embed that module within my script somehow?


It's not that easy. Curses is a wrapper around a bunch of C functions and
what-not. I don't know what the simplest non-Curses way of controlling a
terminal is.

--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
http://www.perlmonks.org/ % have long ago been overpaid?
http://princeton.pm.org/ % -- Meister Eckhart
Ryan Frantz

2005-10-20, 9:55 pm



> -----Original Message-----
> From: Jeff 'japhy' Pinyan [mailto:japhy@perlmonk.org]
> Sent: Thursday, October 20, 2005 2:22 PM
> To: Bryan R Harris
> Cc: Beginners Perl
> Subject: Re: HTAB, VTAB in a terminal?
>=20
> On Oct 20, Bryan R Harris said:
>=20
> that
> something
> machines?
>=20
> It's not that easy. Curses is a wrapper around a bunch of C functions

and
> what-not. I don't know what the simplest non-Curses way of

controlling a
> terminal is.


Correct me if I'm wrong, but if you're users are accessing (something)
via a terminal, wouldn't they all be accessing a central system? In
other words, your script would reside on a *NIX box (for argument's
sake) whose environment would include Perl and the relevant modules,
correct?

>=20
> --
> Jeff "japhy" Pinyan % How can we ever be the sold short or
> RPI Acacia Brother #734 % the cheated, we who for every service
> http://www.perlmonks.org/ % have long ago been overpaid?
> http://princeton.pm.org/ % -- Meister Eckhart
>=20
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>=20


Bryan R Harris

2005-10-20, 9:55 pm



>
> Correct me if I'm wrong, but if you're users are accessing (something)
> via a terminal, wouldn't they all be accessing a central system? In
> other words, your script would reside on a *NIX box (for argument's
> sake) whose environment would include Perl and the relevant modules,
> correct?



Nope, the script is on an NFS mounted fileserver, but each is running them
on a local workstation, so each user is using /usr/bin/perl on their local
machine.

- B



Ryan Frantz

2005-10-20, 9:55 pm



> -----Original Message-----
> From: Bryan R Harris [mailto:Bryan_R_Harris@raytheon.com]
> Sent: Thursday, October 20, 2005 3:02 PM
> To: Beginners Perl
> Subject: Re: HTAB, VTAB in a terminal?
>=20
>=20
>=20
have[color=darkred]
> that
> something
> machines?
functions[color=darkred]
> and
controlling[color=darkred]
> a
(something)[color=darkred]
>=20
>=20
> Nope, the script is on an NFS mounted fileserver, but each is running

them
> on a local workstation, so each user is using /usr/bin/perl on their

local
> machine.
>=20
> - B
>=20


Ahhhh, bugger! I see. Perhaps you could include the module via the
script using 'use' if the module is installed somewhere on the NFS share
like so:

use lib qw(/mountpoint/path/to/module);

I don't know if there are any restrictions with NFS, but it's worth a
try.

ry

>=20
>=20
>=20
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>=20


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com