# Name: showLoop # Desc: MainLoop for displaying text menu and handling input # In: loopMax - max number of looping # Out: None sub showLoop { my ($self,$loopMax) = (@_); my $loopNum = 0; while (1) { # clear screen clearScreen(); # display menu print "\n $self->{'title'}\n\n"; foreach my $item (@{$self->{"itemsRef"}}) { my $label = $item->getLabel(); print " $label\n"; } print "\n Select an option or quit [q]: "; # handle user response my $resp = $self->getResponse(); if ($resp =~ /^[qQ]$/) { last; } else { $self->handleResponse($resp); } $loopNum++; if ((defined $loopMax) && ($loopNum >= $loopMax)) { last; } # flush stdout and stdin autoflush STDOUT,1; # how to flush/empty stdin without blocking? # continue print "\n Return continues\n"; ; } }