public void setUpUndoKey() { String backKeyStroke = "ctrl U"; boolean registeredBackKeyStroke = terminal.registerHandler(backKeyStroke, t -> new ReadHandlerData(ABORT)); if (registeredBackKeyStroke) { terminal.println("Press Ctrl-U to go back to the previous field." + System.lineSeparator()); } int step = 0; while(step < operations.size()) { terminal.setBookmark("bookmark_" + step); try { operations.get(step).run(); } catch (ReadAbortedException e) { if(step > 0) step--; terminal.resetToBookmark("bookmark_" + step); continue; } step++; } }
public static ReadInterruptionData from(ReadHandlerData handlerData, String partialInput) { Function<String, String> valueProvider = handlerData.getReturnValueProvider(); String retVal = (valueProvider == null) ? null : valueProvider.apply(partialInput); return new ReadInterruptionData(handlerData.getAction()) .withRedrawRequired(handlerData.isRedrawRequired()) .withPayload(handlerData.getPayload()) .withReturnValue(retVal); }
public void setUpCountryKey() { String keyCountries = "ctrl O"; boolean isKeyCountries = terminal.registerHandler(keyCountries, t -> { terminal.executeWithPropertiesPrefix("country", tt -> { tt.print(System.lineSeparator() + System.lineSeparator() + " ---------------------- Country Listing ----------------------" + System.lineSeparator() + System.lineSeparator()); List<String> countries = UnitManager.getCountryList(); tt.print(printList(countries)); } ); return new ReadHandlerData(ReadInterruptionStrategy.Action.RESTART).withRedrawRequired(true); }); if (isKeyCountries) { terminal.println("Press Ctrl-O to show a list of countries."); } }
ReadInterruptionStrategy.Action action = handlerData.getAction(); switch (action) { case CONTINUE: println(); waitForDataCleared(); Function<String, String> valueProvider = handlerData.getReturnValueProvider(); result = (valueProvider == null) ? null : valueProvider.apply(input); setAction(CLEAR_OLD_INPUT); setAction(CLEAR_OLD_INPUT); waitForDataCleared(); throw new ReadAbortedException(handlerData.getPayload(), input);
dialog.setVisible(true); dialog.dispose(); return new ReadHandlerData(ReadInterruptionStrategy.Action.CONTINUE); }); return new ReadHandlerData(ReadInterruptionStrategy.Action.RETURN) .withReturnValueProvider(partialInput -> partialInput.isEmpty() ? "nothing" : "high-quality-" + partialInput); }); terminal.executeWithPropertiesPrefix("help", tt -> tt.print("\n\nType the name of a product to be included in your shopping list.")); return new ReadHandlerData(ReadInterruptionStrategy.Action.RESTART).withRedrawRequired(true); }); t -> new ReadHandlerData(ReadInterruptionStrategy.Action.ABORT) .withPayload(System.getProperty("user.name", "nobody")));
@Override public void actionPerformed(ActionEvent e) { CursorBuffer buf = textTerminal.reader.getCursorBuffer(); String partialInput = buf.buffer.toString(); buf.clear(); ReadHandlerData handlerData = handler.apply(textTerminal); ReadInterruptionStrategy.Action action = handlerData.getAction(); if(action == CONTINUE) { buf.write(partialInput); } else { if(action == RESTART) { textTerminal.initialReadBuffer = partialInput; } ReadInterruptionData interruptData = ReadInterruptionData.from(handlerData, partialInput); throw new ReadInterruptionException(interruptData, partialInput); } } }
public void setUpArrows() { terminal.registerHandler(KEY_STROKE_UP, t -> { if(choiceIndex < 0) { originalInput = terminal.getPartialInput(); } if(choiceIndex < choices.length - 1) { choiceIndex++; t.replaceInput(choices[choiceIndex], false); } return new ReadHandlerData(ReadInterruptionStrategy.Action.CONTINUE); }); terminal.registerHandler(KEY_STROKE_DOWN, t -> { if(choiceIndex >= 0) { choiceIndex--; String text = (choiceIndex < 0) ? originalInput : choices[choiceIndex]; t.replaceInput(text, false); } return new ReadHandlerData(ReadInterruptionStrategy.Action.CONTINUE); }); }
public void setUpJobKey() { String keyJobs = "ctrl J"; boolean isKeyJobs = terminal.registerHandler(keyJobs, t -> { terminal.executeWithPropertiesPrefix("job", tt -> { tt.print(System.lineSeparator() + System.lineSeparator() + " ----------------------- Job Listing -----------------------" + System.lineSeparator() + System.lineSeparator()); List<String> jobs = JobType.getEditedList(); tt.print(printList(jobs)); } ); return new ReadHandlerData(ReadInterruptionStrategy.Action.RESTART).withRedrawRequired(true); }); if (isKeyJobs) { terminal.println("Press Ctrl-J to show a list of jobs."); } }
public void setUpArrows() { terminal.registerHandler(KEY_STROKE_UP, t -> { if(choiceIndex < 0) { originalInput = terminal.getPartialInput(); } if(choiceIndex < choices.length - 1) { choiceIndex++; t.replaceInput(choices[choiceIndex], false); } return new ReadHandlerData(ReadInterruptionStrategy.Action.CONTINUE); }); terminal.registerHandler(KEY_STROKE_DOWN, t -> { if(choiceIndex >= 0) { choiceIndex--; String text = (choiceIndex < 0) ? originalInput : choices[choiceIndex]; t.replaceInput(text, false); } return new ReadHandlerData(ReadInterruptionStrategy.Action.CONTINUE); }); }
t.replaceInput(text, false); return new ReadHandlerData(ReadInterruptionStrategy.Action.CONTINUE); }); t.replaceInput(text, false); return new ReadHandlerData(ReadInterruptionStrategy.Action.CONTINUE); }); choiceIndex = savedChoiceIndex; return new ReadHandlerData(ReadInterruptionStrategy.Action.CONTINUE); }); choiceIndex = savedChoiceIndex; return new ReadHandlerData(ReadInterruptionStrategy.Action.CONTINUE); }); terminal.registerHandler(backKeyStroke, t -> new ReadHandlerData(ABORT));
public void setUpMouseCopyKey() { terminal.registerHandler("ctrl C", t -> { t.getTextPane().copy(); return new ReadHandlerData(ReadInterruptionStrategy.Action.CONTINUE); }); terminal.registerHandler("ctrl V", t -> { // t.getTextPane().paste(); String selectedText = t.getTextPane().getSelectedText(); if(selectedText != null) { t.getTextPane().setCaretPosition(t.getDocument().getLength()); t.appendToInput(selectedText, false); } return new ReadHandlerData(ReadInterruptionStrategy.Action.CONTINUE); }); }
public void setUpESC() { terminal.registerHandler(KEY_ESC, t -> { MasterClock mc = Simulation.instance().getMasterClock(); if (mc != null) { if (mc.isPaused()) { mc.setPaused(false, false); terminal.printf(System.lineSeparator() + System.lineSeparator()); terminal.printf(" [ Simulation Unpaused ]"); //terminal.printf(System.lineSeparator() + System.lineSeparator()); } else { terminal.resetLine(); mc.setPaused(true, false); // terminal.printf(System.lineSeparator() + System.lineSeparator()); terminal.printf(" [ Simulation Paused ]"); //terminal.printf(System.lineSeparator() + System.lineSeparator()); } } return new ReadHandlerData(ReadInterruptionStrategy.Action.CONTINUE); }); }
boolean registered = terminal.registerHandler(backKeyStroke, t -> new ReadHandlerData(ABORT)); if(registered) { terminal.println("During data entry you can press '" + backKeyStroke + "' to go back to the previous field.\n");
boolean registered = terminal.registerHandler(backKeyStroke, t -> new ReadHandlerData(ABORT)); if(registered) { terminal.println("During data entry you can press '" + backKeyStroke + "' to go back to the previous field.\n");