public void run() throws IOException { CHIAState chiaState = CHIAState.AUTOMATAMODE; CandidateListCompletionHandler ch = new CandidateListCompletionHandler(); console.setCompletionHandler(ch); ch.setPrintSpaceAfterFullCompletion(false); CHIAAutomataConsole chiaAutomataConsole = new CHIAAutomataConsole(); CHIAReplacementConsole chiaReplacementConsole = new CHIAReplacementConsole(); List<Completer> replacementCompleter = chiaReplacementConsole.getCompleter().computeCompleters(); replacementCompleter.add(new StringsCompleter(AUTOMATA_MODE)); Completer replacementCom = new AggregateCompleter(replacementCompleter); List<Completer> automataCompletor = this.automataConsole.getCompleter().computeCompleters(); automataCompletor.add(new StringsCompleter(REPLACEMENT_MODE)); Completer automataCom = new AggregateCompleter(automataCompletor); console.addCompleter(new AggregateCompleter(automataCompletor)); String line; while ((line = console.readLine()) != null) { try { if (line.equals(REPLACEMENT_MODE)) { chiaState = CHIAState.REPLACEMENTMODE; this.removeCompleter(); console.removeCompleter(automataCom); console.addCompleter(replacementCom); out.write("replacement mode enabled" + "\n"); out.flush(); } else { if (line.equals(AUTOMATA_MODE)) { chiaState = CHIAState.AUTOMATAMODE; this.removeCompleter(); console.removeCompleter(replacementCom); console.addCompleter(automataCom); out.write("automata mode enabled" + "\n"); out.flush(); } else { if (QUIT.equalsIgnoreCase(line) || EXIT.equalsIgnoreCase(line)) { System.exit(0); } else { if (line.equalsIgnoreCase(CLS)) { console.clearScreen(); } else { if (chiaState.equals(CHIAState.REPLACEMENTMODE)) { ReplacementAction action = chiaReplacementConsole .getCompleter() .parse(line, chiaReplacementConsole, out); if (chiaReplacementConsole.getChiaState().isPerformable(action)) { action.perform(chiaReplacementConsole); chiaReplacementConsole.setChiaState( chiaReplacementConsole.getChiaState().next(action)); } else { out.write( "Action: " + line + " not performable into the state " + chiaReplacementConsole.getChiaState().getClass() + "\n"); out.flush(); } } else { if (chiaState.equals(CHIAState.AUTOMATAMODE)) { AutomataAction action = this.automataConsole.getCompleter().parse(line, chiaAutomataConsole, out); if (this.automataConsole.getChiaState().isPerformable(action)) { action.perform(chiaAutomataConsole); this.automataConsole.setChiaState( this.automataConsole.getChiaState().next(action)); } else { out.write( "Action: " + line + " not performable into the state " + this.automataConsole.getChiaState().getClass() + "\n"); out.flush(); } } } } } } } } catch (Exception e) { out.write(e.getMessage()); out.flush(); } } }
@Override public void clear() throws IOException { reader.clearScreen(); }