Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Determine length of input as it is typed

Reply
Thread Tools

Determine length of input as it is typed

 
 
destraynor@gmail.com
Guest
Posts: n/a
 
      03-18-2006
Hi all,
I have a quick question, I have a command line app that takes
text input. What I'd like to be able to do is determine the length of
the input, as it is typed. So, for example, if the string goes above
100 characters, I can let the user know. Something like this would be
ideal...
---------------------------------------------------------------
~dez > perl sms.pl
Characters remaining 100
|
---------------------------------------------------------------
and then onto...
---------------------------------------------------------------
~dez > perl sms.pl
Characters remaining 64
Hi there, long time no see. Check out nakatomiweb.com
---------------------------------------------------------------

I'm (obviously) not looking for someone to write this for me, just some
information beyond "omg curses.h dude".

Thanks for your time,
Des

 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      03-18-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote in
news:(E-Mail Removed) ups.com:

> I have a quick question, I have a command line app that takes
> text input. What I'd like to be able to do is determine the length of
> the input, as it is typed. So, for example, if the string goes above
> 100 characters, I can let the user know. Something like this would be
> ideal...


....

> I'm (obviously) not looking for someone to write this for me, just
> some information beyond "omg curses.h dude".


Well, here is something that is obviously primitive and flawed (no
editing facilities):

#!/usr/bin/perl

use strict;
use warnings;

use Term::ReadKey;

my $s = read_input(100);
print "$s\n";

sub read_input {
my ($limit) = @_;
my $s = q{};

ReadMode 4;
READKEY: while ( my $left = $limit - length $s ) {
syswrite STDOUT, "\r(Limit = $left): $s";

my $key;
1 while not defined ($key = ReadKey -1);
last READKEY if $key eq "\015";
next READKEY unless $key =~ /[[:alnum:][unct:] ]/;
$s .= $key;
}
ReadMode 0;
return $s;
}

__END__


--
A. Sinan Unur <(E-Mail Removed)>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html
 
Reply With Quote
 
 
 
 
destraynor@gmail.com
Guest
Posts: n/a
 
      03-21-2006

A. Sinan Unur wrote:
> (E-Mail Removed) wrote in
> news:(E-Mail Removed) ups.com:
>
> > I have a quick question, I have a command line app that takes
> > text input. What I'd like to be able to do is determine the length of
> > the input, as it is typed. So, for example, if the string goes above
> > 100 characters, I can let the user know. Something like this would be
> > ideal...

>
> ...
>
> > I'm (obviously) not looking for someone to write this for me, just
> > some information beyond "omg curses.h dude".

>
> Well, here is something that is obviously primitive and flawed (no
> editing facilities):
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> use Term::ReadKey;
>
> my $s = read_input(100);
> print "$s\n";
>
> sub read_input {
> my ($limit) = @_;
> my $s = q{};
>
> ReadMode 4;
> READKEY: while ( my $left = $limit - length $s ) {
> syswrite STDOUT, "\r(Limit = $left): $s";
>
> my $key;
> 1 while not defined ($key = ReadKey -1);
> last READKEY if $key eq "\015";
> next READKEY unless $key =~ /[[:alnum:][unct:] ]/;
> $s .= $key;
> }
> ReadMode 0;
> return $s;
> }
>
> __END__
> comp.lang.perl.misc guidelines on the WWW:
> http://mail.augustmail.com/~tadmc/cl...uidelines.html


Thank you, thats a good start

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mix statically typed with dynamically typed Yingjie Lan Python 4 01-29-2010 08:50 AM
Get current word being typed in a text input field darius Javascript 1 06-04-2008 02:46 AM
Scan input - But only if something has been typed macuser55 C Programming 4 10-14-2004 04:16 PM
How can I add a row from a typed datatable to another instance of that typed datatable? Ersin Gençtürk ASP .Net 1 10-06-2004 01:11 PM
nuby: determine method passed and determine the receiver that received the method Peña, Botp Ruby 1 01-24-2004 07:51 PM



Advertisments