wodel.youchi has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am writing a script to manage users, on ldap and another application. The script offers to the user : the creation, modification and deletion of an account. When creating a new account, I present to the user a series of inputs to fill in, some are mandatory, using IO::Prompter For each input I then execute a sanity check according to the filled parameter (name, mail, date, password, ...etc.) The problem is, if I make a mistake on the name parameter, for example, there is no way to go up and make the change (using tabulation for example), like in a web form. The only way is to fill the other mandatory fields with anything then discard the whole operation and start the creation from scratch. Is there a way to present to the user, a web form like, but in text mode, where he can go back and modify a field before submission. Regards.

Replies are listed 'Best First'.
Re: Create an html like form on text tty
by LanX (Saint) on Dec 25, 2018 at 04:14 UTC
Re: Create an html like form on text tty
by haukex (Archbishop) on Dec 25, 2018 at 11:08 UTC
    there is no way to go up and make the change

    Not necessarily...

    use warnings; use strict; use IO::Prompter; use Email::Valid; my @fields = ( { name=>'name', desc=>'Name', prompter => { -must => { 'be at least three characters' => qr{\A\w{3,}} } } }, { name=>'mail', desc=>'EMail', prompter => { -must => { 'be a valid email address' => sub { Email::Valid->address(shift) } } } }, { name=>'date', desc=>'Date', prompter => { -must => { 'be in the format DD.MM.YYYY' => qr{\A\d\d?\.\d\d?\.\d\d\d\d\z} } } }, { name=>'pass', desc=>'Password', prompter => { -echo => '*' } }, ); my %data; INPUT: { for my $f (@fields) { my $default = ''; if ( defined $f->{prompter}{-default} ) { if ( defined $f->{prompter}{-echo} ) { $default = " [" . ( $f->{prompter}{-echo} x length($f->{prompter}{-default}) ) . "]"; } else { $default = " [" . $f->{prompter}{-default} . "]"; } } my $rv = prompt( $f->{desc} . $default . ':', %{ $f->{prompter} } ); $data{ $f->{name} } = "$rv"; $f->{prompter}{-default} = "$rv"; } prompt("Is this correct?", -Y1) or redo INPUT; } use Data::Dump; dd \%data;

    Although if you really want it to be like a web form, LanX's suggestion is probably better for that.