in reply to Simulating Command Line History in Perl
I believe "up" and "down" are linked to the key callbacks for various tk entries. "add" is probably linked to the enter key.sub tkhistory { my $entry = shift; if ($entry == 0) { # an "unattached" new history my %hash; my @list; $hash{hlist} = \@list; my $ref = \%hash; return $ref;} my $cmand = shift; my $hist; if ($cmand eq "new") { my %hash; my @list; $hash{hlist} = \@list; $hash{$entry} = -1; my $ref = \%hash; return $ref; } else {$hist = shift;} if ($cmand eq "add") { my $string = $$entry->get; foreach my $elem (@{$hist->{hlist}}) { # prevent duplic +ates if ($string eq $elem) {return 0}} push(@{$hist->{hlist}},$string); $hist->{$entry} == $#{$hist->{hlist}}; } elsif ($cmand eq "up") { if ($#{$hist->{hlist}} == -1) {return} if ($hist->{$entry} < 0) {$hist->{$entry} = $#{$hist->{hlist}} +} else {$hist->{$entry}--}; $$entry->delete('0','end'); $$entry->insert('1',$hist->{hlist}[$hist->{$entry}]); } elsif ($cmand eq "down") { $$entry->delete('0','end'); if ($#{$hist->{hlist}} == -1) {return} if ($hist->{$entry} == $#{$hist->{hlist}}) { $hist->{$entry} = -1; return} $hist->{$entry}++; $$entry->insert('1',$hist->{hlist}[$hist->{$entry}]); } elsif ($cmand eq "join") { $hist->{$entry} = 0; } }
|
|---|