Fix quit command and move help command
[kaka/cakelight.git] / src / kaka / cakelight / Console.java
index 873dac1..3f9bce9 100644 (file)
@@ -9,6 +9,7 @@ import java.util.List;
 import java.util.Map;
 
 public class Console extends Thread {
+    private boolean running;
     private CakeLight cakelight;
     private Configuration config;
     private Map<String, Command> commands = new HashMap<>();
@@ -23,7 +24,7 @@ public class Console extends Thread {
     private Console(CakeLight cakelight, Configuration config) {
         this.cakelight = cakelight;
        this.config = config;
-       register(new HelpCommand());
+       register(Commands.help());
        register(Commands.quit());
        register(Commands.video());
        register(Commands.color());
@@ -43,18 +44,13 @@ public class Console extends Thread {
        return config;
     }
 
-    private class HelpCommand implements Command {
-       @Override
-       public String[] getNames() {
-           return new String[] {"?", "h", "help"};
-       }
+    List<Command> getCommands() {
+        return commandList;
+    }
 
-       @Override
-       public void activate(Console console, String[] args) {
-           for (Command c : commandList) {
-               System.out.println(String.join("|", c.getNames()));
-           }
-       }
+    void quit() {
+        cakelight.turnOff();
+        running = false;
     }
 
     private void register(Command cmd) {
@@ -70,8 +66,9 @@ public class Console extends Thread {
 
     @Override
     public void run() {
+       running = true;
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
-           while (true) {
+           while (running) {
                System.out.print("> ");
                String input = reader.readLine();
                handleInput(input);