in reply to Win32::Console Input Buffer Problem

As a suggestion, for the future monks who may read your question, please paste your code into your post (or a comment onto the post), for people to peruse. You may not have that code on your scratch pad forever, and people may be plagued by the same problem in the future. Another good suggestion is to surround it with <code></code> tags (In your case, the code was long and needed to be given <readmore> tags. I've taken the liberty and pasted the code here
# File Viewing Module for hex editor package Hex::FileSelect; use strict; use Win32::Console; use File::Spec; use Cwd; sub new { my $class = shift; my $self = { Title => 'Select File', #TitleBar text Start => getcwd(), #Start Dir CurDir => '', #Current Dir Dir => [], #Dir Contents Offset => 0, #Filelist display offset Highlighted => 0, #Highlighted file offset Console => new Win32::Console(), }; bless($self, $class); return $self; } # Returns a string representing the path to the chosen file. sub Run { my $self = shift; $self->{Console}->Size(80, 50); $self->{Console}->Window(1, 0, 0, 640, 480); $self->{Console}->Cursor(-1, -1, 100, 0); $self->{Console}->FillAttr($main::BG_BLACK | $main::FG_CYAN, 80 * +50, 0, 0); #Title Bar $self->{Console}->FillAttr($main::BG_BLUE | $main::FG_WHITE, 80, 0 +, 0); $self->{Console}->FillChar(' ', 80, 0, 0); $self->{Console}->WriteChar($self->{Title}, 0, 0); #Status Bar $self->{Console}->FillAttr($main::BG_BLUE | $main::FG_WHITE, 80, 0 +, 49); #Swap in display buffer $self->{Console}->Display(); #Read Start Directory $self->{CurDir} = $self->{Start}; $self->_DisplayCurDir(); $self->_LoadCurDir(); $self->_DisplayList(); $self->_StatusBar("I'm your status bar for today!"); return $self->_MainLoop(); } #Returns a path/filname or '' on cancel sub _MainLoop() { my($self) = @_; my $events; my @event; #0 Event Type (1 = keyboard) #1 Key Down (TRUE = Pressed, FALSE = Released) #2 Repeat #3 Virtual Key #4 Virtual Scan #5 ASCII Char (0 if non-character) #6 Control Key State while(1) { while($self->{Console}->GetEvents()) { @event = $self->{Console}->Input(); $self->_StatusBar("KC: $event[3] SC: $event[4]"); } 1; } } sub Title { my($self, $title) = @_; if(defined $title) { #Set Title $self->{Title} = $title; return; }else{ #Get Title return $self->{Title}; } } sub Start { my($self, $start) = @_; if(defined $start) { #Set Start $self->{Start} = $start; return; }else{ #Get Start return $self->{Start}; } } sub _DisplayCurDir { my($self) = @_; $self->{Console}->FillChar(' ', 80, 0, 1); $self->{Console}->WriteChar($self->{CurDir}, 0, 1) } sub _DisplayList { my($self) = @_; my $line = 2; #Range to display my $first = $self->{Offset}; my $last; if($first + 46 > @{ $self->{Dir} }) { $last = $#{ $self->{Dir} } }else{ $last = $first + 46; } $self->{Console}->FillChar(' ', 80 * 47, 0, 2); foreach( @{ $self->{Dir} }[$first .. $last] ) { if($_->[1]) { $self->{Console}->WriteChar("-> $_->[0]", 0, $line); }else{ $self->{Console}->WriteChar($_->[0], 3, $line); } $line++; last if($line > 49); } } sub _LoadCurDir { my($self) = @_; opendir(DIR, $self->{CurDir}) || die "Unable to open $self->{Start +}: $!\n"; my @dir = readdir(DIR); my $filenum = 0; closedir(DIR); foreach(@dir) { if(-d File::Spec->catfile($self->{CurDir}, $_)) { $self->{Dir}->[$filenum] = [$_, 1]; }else{ $self->{Dir}->[$filenum] = [$_, 0]; } $filenum++; } #Sort alphabetically @{ $self->{Dir} } = sort { $a->[0] cmp $b->[0] } @{ $self->{Dir} } +; #Put Dir's first my(@dirs, @files); foreach(@{ $self->{Dir} }) { if($_->[1]) { push(@dirs, $_); }else{ push(@files, $_); } } @{ $self->{Dir} } = (@dirs, @files); } sub _Highlight { my($self) = @_; $self->{Console}->FillAttr($main::BG_BLACK | $main::FG_CYAN, 80 * +47, 0, 2); $self->{Console}->FillAttr($main::BG_LIGHTRED | $main::FG_WHITE, 8 +0, 0, 2 + $self->{Highlighted} - $self->{Offset}); } sub _StatusBar { my($self, $text) = @_; $self->{Console}->FillChar(' ', 80, 0, 49); $self->{Console}->WriteChar($text, 0, 49); } 1;


    --jb

Replies are listed 'Best First'.
Re: Re: Win32::Console Input Buffer Problem
by Android 18 (Novice) on Jul 21, 2002 at 23:04 UTC
    Thank you, I didn't know about the readmore tags. I'll remember that in the future.

    Once bread becomes toast, it can never be bread again.