3 # A simple shell written in Perl6
6 # BACKPSACE, history, editing ?
9 my $prompt = '<p6shell>$ ';
12 # we should have this list from some internal command
13 # probably along with the signature of these functions
14 my @available_commands = <exit print say>;
15 @available_commands.push( <mkdir rmdir chdir unlink chmod chown> );
16 @available_commands.push( <pop push> );
19 # Enable reading character as they ar typed, see Perl5: perldoc -f getc
20 # It would be better to use Term::ReadKey but it has to be implemented for Perl6
24 run
"stty cbreak </dev/tty >/dev/tty 2>&1";
27 run
"stty", '-icanon', 'eol', "\x01";
30 my $_loop_ = get_loop
();
34 run
"stty -cbreak </dev/tty >/dev/tty 2>&1";
37 run
"stty", 'icanon', 'eol', '^@'; # ASCII null
41 #################################################333
51 # TODO: maybe check if _loop_ shows up in the input and disallow that code ?
52 if (eval "$command;" ~ $_loop_ ) {
61 # clean the TAB but keep what we had so far
62 refresh_commandline($command);
64 my $tail = tab_completition($command);
68 refresh_commandline($command);
78 # TODO: this should understand the command line typed in so far....
79 sub tab_completition
{
82 my @possible_commands = grep { not index($_, $command)}, @available_commands;
83 # TODO: might really get more than one... and we should let the user step through them using TAB
84 # or display all possible values, or the user should be able to configure the behivaior
85 return if not @possible_commands;
86 return substr(@possible_commands[0], $command.bytes
) if 1 == @possible_commands;
88 # TODO: if there are too many (> $LIMIT) ask if the user really wants to display all
92 for @possible_commands -> $com {
93 if ($line.bytes
+ 1 + $com.bytes
<= $WIDTH) {
105 sub refresh_commandline
{
108 print " " x
$command.bytes
+ 1;