diff --git a/bin/commandLine/CommandLineController$1.class b/bin/commandLine/CommandLineController$1.class index 880eccbdc686b23d4d6337cda0c8fa6005ac990d..49f2355d32ecca790d580f34166cfe2648a41df5 100644 Binary files a/bin/commandLine/CommandLineController$1.class and b/bin/commandLine/CommandLineController$1.class differ diff --git a/bin/commandLine/CommandLineController$2.class b/bin/commandLine/CommandLineController$2.class new file mode 100644 index 0000000000000000000000000000000000000000..f33ce602ec2282fd579c474b77d257c707279324 Binary files /dev/null and b/bin/commandLine/CommandLineController$2.class differ diff --git a/bin/commandLine/CommandLineController.class b/bin/commandLine/CommandLineController.class index 599d4ef1c027c4c82ded9c8f7daf005973c1b040..d6d149ea752d50f710ba853e0fcd3931897f332b 100644 Binary files a/bin/commandLine/CommandLineController.class and b/bin/commandLine/CommandLineController.class differ diff --git a/bin/commandLine/_en.properties b/bin/commandLine/_en.properties index c7814cf01dd0527d7ee1a118c1d02621a4a11f4c..deb6bb3ba8118bc0301221055037e146a474f4c4 100644 --- a/bin/commandLine/_en.properties +++ b/bin/commandLine/_en.properties @@ -1,13 +1,16 @@ app.name=CommandLine -version.code=1 -version.name=1.0.0 -version.date=26.07.16 +version.code=0 +version.name=1.1.0 +version.date=16.09.16 help.list=list - lists all possible commands help.help=help - shows help for given command\nSYNTAX: help [COMMAND] help.clear=clear - clears the history +help.shortcuts=shortcuts - lists all available shortcuts error.general=An error occurred. error.unknown.command=Unknown command. Use \"list\" for a list of possible commands. error.invalid.arguments=Invalid arguments. Use \"help commandname\" for help. -error.no.help=Unknown command as parameter. Can't display help. Use \"list\" for a list of possible commands. \ No newline at end of file +error.no.help=Unknown command as parameter. Can't display help. Use \"list\" for a list of possible commands. + +info.shortcuts=[ENTER] - execute command\n[UP] - scroll through recently used commands\n[ESC] - clear input\n[TAB] - autocomplete \ No newline at end of file diff --git a/bin/commands/CommandShortcuts.class b/bin/commands/CommandShortcuts.class new file mode 100644 index 0000000000000000000000000000000000000000..41f4889d0da5c483195663eb2466b3df5a10defc Binary files /dev/null and b/bin/commands/CommandShortcuts.class differ diff --git a/bin/commands/PossibleCommands.class b/bin/commands/PossibleCommands.class index f89f06a53eb69b4c55cd2523a41972728870249d..7415b1fb1a5d3021a461a791a4846b9b4c8b505f 100644 Binary files a/bin/commands/PossibleCommands.class and b/bin/commands/PossibleCommands.class differ diff --git a/src/commandLine/CommandLine.java b/src/commandLine/CommandLine.java index 16d1f8f388cbf237b5ba24bd38301135e5365f3c..5e9add883845105da020c996b1a4df32ff61fc7d 100644 --- a/src/commandLine/CommandLine.java +++ b/src/commandLine/CommandLine.java @@ -57,7 +57,7 @@ public class CommandLine { return lastShownCommand; } - + public String getPromptText() { return promptText; diff --git a/src/commandLine/CommandLineController.java b/src/commandLine/CommandLineController.java index d4b4fc5b03df9de28e8ea1c16077409ea4a8472f..d96b28df19e3123182a9488ddfc8ef1efcdb48ec 100644 --- a/src/commandLine/CommandLineController.java +++ b/src/commandLine/CommandLineController.java @@ -1,11 +1,13 @@ package commandLine; import java.util.ArrayList; +import java.util.Comparator; import commands.Command; import commands.HistoryEntry; import commands.HistoryType; import commands.PossibleCommands; +import javafx.application.Platform; import javafx.event.EventHandler; import javafx.fxml.FXML; import javafx.scene.control.TextArea; @@ -15,6 +17,7 @@ import javafx.scene.input.KeyEvent; /** * Controller for the CommandLine stage + * * @author deadlocker8 * */ @@ -22,84 +25,90 @@ public class CommandLineController { @FXML private TextArea textareaHistory; @FXML private TextField textfieldInput; - - private CommandLine commandLine; - + + private CommandLine commandLine; + public void init(CommandLine commandLine) - { - this.commandLine = commandLine; - - commandLine.getBundle().setController(this); - commandLine.getBundle().setLanguageBundle(commandLine.getLanguageBundle()); - + { + this.commandLine = commandLine; + + commandLine.getBundle().setController(this); + commandLine.getBundle().setLanguageBundle(commandLine.getLanguageBundle()); + textareaHistory.setEditable(false); - textareaHistory.setWrapText(true); - + textareaHistory.setWrapText(true); + textfieldInput.setOnKeyPressed(new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent event) { if(event.getCode().equals(KeyCode.ENTER)) - { + { parse(); - } - + } + if(event.getCode().equals(KeyCode.UP)) - { + { showLastCommand(); - } - + } + if(event.getCode().equals(KeyCode.ESCAPE)) - { + { clearConsole(); - } + } + + if(event.getCode().equals(KeyCode.TAB)) + { + autocomplete(); + event.consume(); + } } - }); - - printPrompt(); - } + }); + + printPrompt(); + } public void printPrompt() - { + { setConsoleText(); - clearConsole(); + clearConsole(); } - + public void print(String message) - { + { commandLine.history.add(new HistoryEntry(HistoryType.MESSAGE, message)); setConsoleText(); printPrompt(); } - + public void clearHistoryLog() { textareaHistory.setText(""); } - + public void clearHistory() { commandLine.history = new ArrayList<>(); } - + public void clearConsole() { textfieldInput.setText(""); textfieldInput.requestFocus(); } - + private void setConsoleText() - { - clearHistoryLog(); - + { + clearHistoryLog(); + StringBuilder sb = new StringBuilder(); boolean printedLastEntry = false; - for(int i = 0; i < commandLine.history.size(); i++) - { + for(int i = 0; i < commandLine.history.size(); i++) + { HistoryEntry currentEntry = commandLine.history.get(i); if(currentEntry.getType().equals(HistoryType.COMMAND)) - { + { if(printedLastEntry) { sb.append("\n"); @@ -110,72 +119,136 @@ public class CommandLineController printedLastEntry = true; } else - { + { if(i != 0) { sb.append("\n"); } sb.append(currentEntry.getText()); - printedLastEntry = true; + printedLastEntry = true; } - } - + } + textareaHistory.setText(sb.toString()); - textareaHistory.positionCaret(sb.toString().length()); + textareaHistory.positionCaret(sb.toString().length()); } - + private boolean executeCommand(String[] command) { for(Command cmd : PossibleCommands.possibleCommands) { if(cmd.getKeyword().equals(command[0])) - { - cmd.execute(command, commandLine.getBundle()); + { + cmd.execute(command, commandLine.getBundle()); return true; } } return false; } - + private void parse() { - String input = textfieldInput.getText().replace("\n", ""); - + String input = textfieldInput.getText().replace("\n", ""); + if(input.equals("")) { printPrompt(); return; - } - + } + commandLine.globalHistory.add(new HistoryEntry(HistoryType.COMMAND, input)); commandLine.history.add(new HistoryEntry(HistoryType.COMMAND, input)); - commandLine.lastShownCommand = -1; - - String[] command = input.split(" "); - if(!executeCommand(command)) + commandLine.lastShownCommand = - 1; + + String[] command = input.split(" "); + if( ! executeCommand(command)) { - print(commandLine.getLanguageBundle().getString("error.unknown.command")); + print(commandLine.getLanguageBundle().getString("error.unknown.command")); } else { printPrompt(); } } - + private void showLastCommand() { if(commandLine.globalHistory.size() > 0) { if(commandLine.lastShownCommand <= 0) { - textfieldInput.setText(commandLine.globalHistory.get(commandLine.globalHistory.size()-1).getText()); - commandLine.lastShownCommand = commandLine.globalHistory.size()-1; + textfieldInput.setText(commandLine.globalHistory.get(commandLine.globalHistory.size() - 1).getText()); + commandLine.lastShownCommand = commandLine.globalHistory.size() - 1; } else - { + { textfieldInput.setText(commandLine.globalHistory.get(commandLine.lastShownCommand - 1).getText()); - commandLine.lastShownCommand--; + commandLine.lastShownCommand--; + } + + Platform.runLater(()-> + { + textfieldInput.positionCaret(textfieldInput.getText().length()); + }); + } + } + + private void autocomplete() + { + String input = textfieldInput.getText().replace("\n", ""); + + if(input.equals("")) + { + return; + } + + ArrayList<Command> commands = PossibleCommands.possibleCommands; + + //filter possible commands + ArrayList<Command> filteredCommands = new ArrayList<>(); + for(Command currentCommand : commands) + { + if(currentCommand.getKeyword().startsWith(input)) + { + filteredCommands.add(currentCommand); } + } + + //sort commands alphabetically + filteredCommands.sort(new Comparator<Command>() + { + @Override + public int compare(Command o1, Command o2) + { + return o1.keyword.compareTo(o2.keyword); + } + }); + + if(filteredCommands.size() == 1) + { + textfieldInput.setText(filteredCommands.get(0).getKeyword()); + } + else + { + StringBuilder sb = new StringBuilder(); + sb.append(">>> Possible commands for \"" + input + "\":\n"); + for(int i = 0; i < filteredCommands.size(); i++) + { + sb.append(filteredCommands.get(i).keyword); + if(i != (filteredCommands.size()-1)) + { + sb.append("\n"); + } + } + + print(sb.toString()); + + textfieldInput.setText(input); } + + Platform.runLater(()-> + { + textfieldInput.positionCaret(textfieldInput.getText().length()); + }); } } \ No newline at end of file diff --git a/src/commandLine/_en.properties b/src/commandLine/_en.properties index c7814cf01dd0527d7ee1a118c1d02621a4a11f4c..deb6bb3ba8118bc0301221055037e146a474f4c4 100644 --- a/src/commandLine/_en.properties +++ b/src/commandLine/_en.properties @@ -1,13 +1,16 @@ app.name=CommandLine -version.code=1 -version.name=1.0.0 -version.date=26.07.16 +version.code=0 +version.name=1.1.0 +version.date=16.09.16 help.list=list - lists all possible commands help.help=help - shows help for given command\nSYNTAX: help [COMMAND] help.clear=clear - clears the history +help.shortcuts=shortcuts - lists all available shortcuts error.general=An error occurred. error.unknown.command=Unknown command. Use \"list\" for a list of possible commands. error.invalid.arguments=Invalid arguments. Use \"help commandname\" for help. -error.no.help=Unknown command as parameter. Can't display help. Use \"list\" for a list of possible commands. \ No newline at end of file +error.no.help=Unknown command as parameter. Can't display help. Use \"list\" for a list of possible commands. + +info.shortcuts=[ENTER] - execute command\n[UP] - scroll through recently used commands\n[ESC] - clear input\n[TAB] - autocomplete \ No newline at end of file diff --git a/src/commands/CommandShortcuts.java b/src/commands/CommandShortcuts.java new file mode 100644 index 0000000000000000000000000000000000000000..63b5cbf1a79ef67d42d7057114f731d0a215c665 --- /dev/null +++ b/src/commands/CommandShortcuts.java @@ -0,0 +1,23 @@ +package commands; + +/** + * Lists all available Shortcuts + * @author deadlocker8 + * + */ +public class CommandShortcuts extends Command +{ + public CommandShortcuts() + { + super.keyword = "shortcuts"; + super.numberOfParams = 0; + super.helptText = "help.shortcuts"; + } + + @Override + public void execute(String[] command, CommandBundle bundle) + { + bundle.getController().print("Available Shortcuts:"); + bundle.getController().print(bundle.getLanguageBundle().getString("info.shortcuts")); + } +} \ No newline at end of file diff --git a/src/commands/PossibleCommands.java b/src/commands/PossibleCommands.java index bdf8a51fec10af772e05ad612db9a51c244c9260..35842a6d0428b71dd16422ffe6b96c7df6f5749b 100644 --- a/src/commands/PossibleCommands.java +++ b/src/commands/PossibleCommands.java @@ -13,6 +13,7 @@ public class PossibleCommands public static final ArrayList<Command> possibleCommands = new ArrayList<>(Arrays.asList( new CommandList(), new CommandHelp(), - new CommandClear() + new CommandClear(), + new CommandShortcuts() )); } \ No newline at end of file