Assuming that autohistory is disabled in ReadLine (see The synopsis should probably show the disabling of the autohistory in ReadLine #21), using,
Using the code from the synopsis, the history (arguably) ends up being somewhat inconsistent:
- If you select the default option for the first question, then in the history will be placed "blue".
- If you select a non-default option for the first question, using the option's index, then that index, i.e. "3", is placed in the history, rather than the item's name, i.e. "green".
This seems a little inconsistent.
The reason for this is that the input is entered into the history, before it is converted into the item's name.
If the following lines in _tt_readline()
$term->addhistory( $answer ) if length $answer;
### add both prompt and answer to the history
history( defined $answer ? "$prompt $answer" : "$prompt", 0 );
are moved to the else block at the end of the function,
} else {
return $multi ? @rv : $rv[0];
}
}
}
like so
} else {
$term->addhistory( $multi ? @rv : $rv[0] );
### add both prompt and answer to the history
history( $multi ? @rv : $rv[0], 0 );
return $multi ? @rv : $rv[0];
}
}
}
then the issue is fixed, and the history will only contain the item's names, and never their respective indices.
User chooses behaviour?
The user should, at least, have the option to select the behaviour. Adding a flag (or two) would fix this.
If the code in _tt_readline() is changed to
$term->addhistory( $answer ) if !$flg_no_history && !$flg_post_add_history && length $answer;
### add both prompt and answer to the history
history( defined $answer ? "$prompt $answer" : "$prompt", 0 ) if !$flg_no_history && !$flg_post_add_history;
and
} else {
$term->addhistory( $multi ? @rv : $rv[0] ) if !$flg_no_history && $flg_post_add_history;
### add both prompt and answer to the history
history( $multi ? @rv : $rv[0], 0 ) if !$flg_no_history && $flg_post_add_history;
return $multi ? @rv : $rv[0];
}
}
}
with two flags at the start of the file
our $flg_post_add_history = 1; # Move the add history to the end of _tt_readline()
our $flg_no_history = 0; # Disable all history calls in _tt_readline()
Note: You would also need to add if !$flg_no_history to four other lines in the module, to disable the history completely:
history( $print_me ) if !$flg_no_history && $print_me;
...
history( join ' ', grep { defined } $prompt, @$default ) if !$flg_no_history;
...
history( join ' ', grep { defined } $prompt, $default ) if !$flg_no_history;
...
if (!$flg_no_history){
history( "$_\n" ) for @lines ;
}
This seems to work for me in a locally modified version of the module.
Assuming that autohistory is disabled in ReadLine (see The synopsis should probably show the disabling of the autohistory in ReadLine #21), using,
Using the code from the synopsis, the history (arguably) ends up being somewhat inconsistent:
This seems a little inconsistent.
The reason for this is that the input is entered into the history, before it is converted into the item's name.
If the following lines in
_tt_readline()are moved to the
elseblock at the end of the function,like so
then the issue is fixed, and the history will only contain the item's names, and never their respective indices.
User chooses behaviour?
The user should, at least, have the option to select the behaviour. Adding a flag (or two) would fix this.
If the code in
_tt_readline()is changed toand
with two flags at the start of the file
Note: You would also need to add
if !$flg_no_historyto four other lines in the module, to disable the history completely:This seems to work for me in a locally modified version of the module.