}
@FXML
private void handleKeyPress(final InputEvent event) throws Exception {
//private void handleEnter(ActionEvent event) throws Exception {
final KeyEvent keyEvent = (KeyEvent) event;
if (keyEvent.getCode().equals(KeyCode.ENTER)) {
String command = (input.getText() + "\n");
logger.info("Entered Command: " + command);
if (!tg.isConnected().get()) {
logger.error("TinyG is not connected....\n");
postConsoleMessage("[!]TinyG is not connected....\n");
input.setPromptText(PROMPT);
return;
}
//TinyG is connected... Proceed with processing command.
//This will send the command to get a OK prompt if the buffer is empty.
//"{\""+ command.split("=")[0].replace("$", "") + "\":" + command.split("=")[1].trim() + "}\n"
if ("".equals(command)) {
tg.write(CommandManager.CMD_QUERY_OK_PROMPT);
}
tg.write(command);
postConsoleMessage(command.replace("\n", ""));
gcodeCommandHistory.addCommandToHistory(command); //Add this command to the history
input.clear();
input.setPromptText(PROMPT);
} else if (keyEvent.getCode().equals(KeyCode.UP)) {
input.setText(gcodeCommandHistory.getNextHistoryCommand());
// input.positionCaret(input.lengthProperty().get());
} else if (keyEvent.getCode().equals(KeyCode.DOWN)) {
input.setText(gcodeCommandHistory.getPreviousHistoryCommand());
// input.positionCaret(input.lengthProperty().get());
}
}