Hey,

Can someone try this out and explain to me why! I just put same code into a module (to make it more modular), but in Windows I get some wierd "←[0J" output every time I press a key! Where does this come from? I didn't have this problem when not having the code as a module! However, I want it as a module, but I dunno how to solve the problem.

AceShell.pm
#!/usr/bin/env perl package AceShell; use Term::ANSIScreen qw/:color :cursor :screen :keyboard/; use Term::ReadKey; use Time::HiRes qw( usleep ); use Time::localtime; use Data::Dumper; use strict; use warnings; sub new { my $class = shift; my @history = (); my $history_at = 0; my $word = ""; my $word_ghost = ""; my $prompt = "AceShell> "; my $pos = 0; my $self = { 'Applied_Commands' => {}, 'History' => \@history, 'History_At' => $history_at, 'Word' => $word, 'Word_Ghost' => $word_ghost, 'Prompt' => $prompt, 'Pos' => $pos, }; return bless($self, $class); } sub startShell { my $self = shift; # Disable CTRL keys ReadMode(4); $| = 1; while(1){ my $char; while (!defined ($char = ReadKey(-1))){ usleep 1_100; print "\r" . formatTime(time) . " | " . $self->{'Prompt'} . $self +->{'Word'}; } cldown; my $ord = ord($char); last if ($ord == 3); last if ($ord == 4); if ($ord == 10 or $ord == 13) { # "Enter" print "\n"; $self->{'Word'} = ""; $self->{'Pos'} = 0; next; } elsif ($ord == 8 || $ord == 127) { # ie "Backspace") if ($self->{'Pos'} == 0) { print " "; next; } --$self->{'Pos'}; print chr(8) . ' ' . chr(8); chop($self->{'Word'}); $self->{'Wword_Ghost'} = ""; next; } if($ord >= 32 && $ord < 155) { ++$self->{'Pos'}; $self->{'Word'} .= chr($ord); } } ReadMode(0); } sub formatTime { my $t_time = shift; my $temp_time = localtime($t_time); my $time = "1900-01-01 01:01:01"; if (defined ($temp_time)) { $time = sprintf "%04d-%02d-%02d %02d:%02d:%02d", $temp_time->y +ear+1900, $temp_time->mon+1, $temp_time->mday, $temp_time->hour, $tem +p_time->min, $temp_time->sec; } return $time; } sub formatText { my $subform = "@<<<<<<<<<<< - @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +<<<<<<<<<<<<<<<<<<<<<<"; formline($subform, @_); my $formated = $^A; $^A = ""; return $formated; } 1
aceShellTest.pl:
#!/usr/bin/env perl use AceShell; use lib "."; use strict; use warnings; my %COMMANDS = ( 'help' => "Show help information.", 'history' => "Show history of typed commands.", 'quit' => "Quit the Shell.", ); my $aceshell = AceShell->new(); $aceshell->startShell();

Thanks,
Ace

2006-07-15 Retitled by Arunbear, as per Monastery guidelines
Original title: 'AceShell'


In reply to Weird screen output in my AceShell module by Ace128

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.