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