X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fkaka%2Fcakelight%2FConsole.java;h=3f9bce9e42d8a63c93d2fde59ca84008cf16a3ac;hb=fc040bcb6270ff0a4bfaab6cfeaad60edef2a11c;hp=f32ba9824edfe632868c22823c1dfcf9210fddcd;hpb=f1a6a6a5cf7d61c2df185206cb0a5b0e7eceb3c1;p=kaka%2Fcakelight.git diff --git a/src/kaka/cakelight/Console.java b/src/kaka/cakelight/Console.java index f32ba98..3f9bce9 100644 --- a/src/kaka/cakelight/Console.java +++ b/src/kaka/cakelight/Console.java @@ -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 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()); @@ -32,6 +33,7 @@ public class Console extends Thread { register(Commands.saturation()); register(Commands.ambientMode()); register(Commands.twoColorNoiseMode()); + register(Commands.sunriseMode()); } public CakeLight getCakelight() { @@ -42,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 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) { @@ -69,16 +66,16 @@ public class Console extends Thread { @Override public void run() { - while (true) { - System.out.print("> "); - try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) { + running = true; + try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) { + while (running) { + System.out.print("> "); String input = reader.readLine(); handleInput(input); - } catch (IOException e) { - System.out.println("Error reading from command line"); - break; } - } + } catch (IOException e) { + System.out.println("Error reading from command line"); + } } void handleInput(String input) {