| author | indvdum |
| Tue, 31 May 2011 15:52:03 +0400 | |
| branch | consoleWithANSI |
| changeset 15 | ea825ba6336b |
| parent 0 | c46bb04134cb |
| permissions | -rw-r--r-- |
| indvdum@0 | 1 |
package org.vaadin.console; |
| indvdum@0 | 2 |
|
| indvdum@0 | 3 |
import java.util.HashSet; |
| indvdum@0 | 4 |
import java.util.Set; |
| indvdum@0 | 5 |
|
| indvdum@0 | 6 |
import org.vaadin.console.Console.Command; |
| indvdum@0 | 7 |
import org.vaadin.console.Console.Handler; |
| indvdum@0 | 8 |
|
| indvdum@0 | 9 |
/** |
| indvdum@0 | 10 |
* Default handler for console. |
| indvdum@0 | 11 |
* |
| indvdum@0 | 12 |
*/ |
| indvdum@0 | 13 |
public class DefaultConsoleHandler implements Handler {
|
| indvdum@0 | 14 |
|
| indvdum@0 | 15 |
private static final long serialVersionUID = 1L; |
| indvdum@0 | 16 |
|
| indvdum@0 | 17 |
public void handleException(final Console console, final Exception e, |
| indvdum@0 | 18 |
final Command cmd, final String[] argv) {
|
| indvdum@0 | 19 |
e.printStackTrace(); |
| indvdum@0 | 20 |
console.println(e.getClass().getSimpleName() + ": " + e.getMessage()); |
| indvdum@0 | 21 |
} |
| indvdum@0 | 22 |
|
| indvdum@0 | 23 |
public Set<String> getSuggestions(final Console console, final String input) {
|
| indvdum@0 | 24 |
|
| indvdum@0 | 25 |
final String prefix = console.parseCommandPrefix(input); |
| indvdum@0 | 26 |
if (prefix != null) {
|
| indvdum@0 | 27 |
final Set<String> matches = new HashSet<String>(); |
| indvdum@0 | 28 |
final Set<String> cmds = console.getCommands(); |
| indvdum@0 | 29 |
for (final String cmd : cmds) {
|
| indvdum@0 | 30 |
if (cmd.startsWith(prefix)) {
|
| indvdum@0 | 31 |
matches.add(cmd); |
| indvdum@0 | 32 |
} |
| indvdum@0 | 33 |
} |
| indvdum@0 | 34 |
return matches; |
| indvdum@0 | 35 |
} |
| indvdum@0 | 36 |
return null; |
| indvdum@0 | 37 |
} |
| indvdum@0 | 38 |
|
| indvdum@0 | 39 |
public void inputReceived(final Console console, final String lastInput) {
|
| indvdum@0 | 40 |
console.parseAndExecuteCommand(lastInput); |
| indvdum@0 | 41 |
console.prompt(); |
| indvdum@0 | 42 |
} |
| indvdum@0 | 43 |
|
| indvdum@0 | 44 |
public void commandNotFound(final Console console, final String[] argv) {
|
| indvdum@0 | 45 |
console.print("ERROR: " + argv[0] + ": command not found.");
|
| indvdum@0 | 46 |
} |
| indvdum@0 | 47 |
|
| indvdum@0 | 48 |
} |