public class BurlapShell
extends java.lang.Object
InputStream
and OutputStream
for the shell. Shell commands are implemented by objects implementing the ShellCommand
interface, and allows a shells set of commands to be customized and trivially extended by adding new commands
with the addCommand(burlap.shell.command.ShellCommand)
method.
The shell keeps a small set of special reserved commands that new commands cannot replace. These include the help, cmds (lists all known shell commands), quit (stops the shell), alias (allows a custom name to be assigned to a command), and aliases (lists all known aliases).
The shell is started with the start()
method, which runs the shell in a separate thread. Beyond the
InputStream
that is scanned for user input, shell commands may also be executed using the
executeCommand(String)
method. Other objects can be alerted to command execution completion by implementing
the ShellObserver
and adding an observer with the addObservers(ShellObserver...)
method.
EnvironmentShell
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<java.lang.String,java.lang.String> |
aliases |
protected java.util.Map<java.lang.String,ShellCommand> |
commands |
protected Domain |
domain |
protected java.lang.String |
helpText |
protected java.io.InputStream |
is |
protected boolean |
kill |
protected java.util.List<ShellObserver> |
observers |
protected java.io.PrintStream |
os |
protected java.util.Set<java.lang.String> |
reserved |
protected java.util.Scanner |
scanner |
protected Visualizer |
visualizer |
protected java.lang.String |
welcomeMessage |
Constructor and Description |
---|
BurlapShell(Domain domain,
java.io.InputStream is,
java.io.PrintStream os) |
Modifier and Type | Method and Description |
---|---|
void |
addCommand(ShellCommand command) |
void |
addCommandAs(ShellCommand command,
java.lang.String as) |
void |
addObservers(ShellObserver... observers) |
java.lang.String |
aliasPointer(java.lang.String alias) |
void |
executeCommand(java.lang.String input) |
protected java.util.Collection<ShellCommand> |
generateReserved() |
protected java.util.Collection<ShellCommand> |
generateStandard() |
java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.String>> |
getAliases() |
java.util.Set<java.lang.String> |
getCommands() |
Domain |
getDomain() |
java.lang.String |
getHelpText() |
java.io.InputStream |
getIs() |
java.io.PrintStream |
getOs() |
Visualizer |
getVisualizer() |
java.lang.String |
getWelcomeMessage() |
void |
kill() |
void |
removeAlias(java.lang.String alias) |
void |
removeCommand(java.lang.String command) |
ShellCommand |
resolveCommand(java.lang.String commandName) |
void |
setAlias(java.lang.String commandName,
java.lang.String alias) |
void |
setAlias(java.lang.String commandName,
java.lang.String alias,
boolean force) |
void |
setDomain(Domain domain) |
void |
setHelpText(java.lang.String helpText) |
void |
setIs(java.io.InputStream is) |
void |
setOs(java.io.PrintStream os) |
void |
setVisualizer(Visualizer visualizer) |
void |
setWelcomeMessage(java.lang.String welcomeMessage) |
void |
start() |
protected java.io.InputStream is
protected java.io.PrintStream os
protected java.util.Scanner scanner
protected Domain domain
protected Visualizer visualizer
protected java.util.Map<java.lang.String,ShellCommand> commands
protected java.util.Map<java.lang.String,java.lang.String> aliases
protected java.util.Set<java.lang.String> reserved
protected java.util.List<ShellObserver> observers
protected volatile boolean kill
protected java.lang.String welcomeMessage
protected java.lang.String helpText
public BurlapShell(Domain domain, java.io.InputStream is, java.io.PrintStream os)
public void addCommand(ShellCommand command)
public void addCommandAs(ShellCommand command, java.lang.String as)
public void setAlias(java.lang.String commandName, java.lang.String alias)
public void setAlias(java.lang.String commandName, java.lang.String alias, boolean force)
public void removeAlias(java.lang.String alias)
public void removeCommand(java.lang.String command)
public java.lang.String getHelpText()
public void setHelpText(java.lang.String helpText)
public java.lang.String getWelcomeMessage()
public void setWelcomeMessage(java.lang.String welcomeMessage)
public void kill()
public java.io.InputStream getIs()
public void setIs(java.io.InputStream is)
public java.io.PrintStream getOs()
public void setOs(java.io.PrintStream os)
public ShellCommand resolveCommand(java.lang.String commandName)
public java.lang.String aliasPointer(java.lang.String alias)
public java.util.Set<java.lang.String> getCommands()
public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.String>> getAliases()
public Domain getDomain()
public void setDomain(Domain domain)
public Visualizer getVisualizer()
public void setVisualizer(Visualizer visualizer)
public void addObservers(ShellObserver... observers)
public void start()
public void executeCommand(java.lang.String input)
protected java.util.Collection<ShellCommand> generateReserved()
protected java.util.Collection<ShellCommand> generateStandard()