Ace128 has asked for the wisdom of the Perl Monks concerning the following question:
#!/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
#!/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();
2006-07-15 Retitled by Arunbear, as per Monastery guidelines
Original title: 'AceShell'
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Weird screen output in my AceShell module
by ikegami (Patriarch) on Jul 15, 2006 at 06:11 UTC | |
| |
Re: Weird screen output in my AceShell module
by liverpole (Monsignor) on Jul 15, 2006 at 14:18 UTC | |
by Ace128 (Hermit) on Jul 15, 2006 at 20:13 UTC | |
by ikegami (Patriarch) on Jul 15, 2006 at 21:01 UTC | |
by Ace128 (Hermit) on Jul 15, 2006 at 21:25 UTC | |
by ikegami (Patriarch) on Jul 15, 2006 at 21:41 UTC | |
Re: Weird screen output in my AceShell module
by planetscape (Chancellor) on Jul 15, 2006 at 03:50 UTC | |
| |
Re: Weird screen output in my AceShell module
by Khen1950fx (Canon) on Jul 15, 2006 at 10:25 UTC | |
|