From faedf1fe8c22e4ccfa375951166bd1a41a4e3b94 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Sun, 26 Mar 2017 23:00:28 -0400 Subject: More FDS work --- .../src/main/java/bjc/utils/cli/fds/FDS.java | 62 ++++++++++++++-------- 1 file changed, 39 insertions(+), 23 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/cli/fds/FDS.java') diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/fds/FDS.java b/BJC-Utils2/src/main/java/bjc/utils/cli/fds/FDS.java index 6dc0337..91934be 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/cli/fds/FDS.java +++ b/BJC-Utils2/src/main/java/bjc/utils/cli/fds/FDS.java @@ -1,9 +1,7 @@ package bjc.utils.cli.fds; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; import java.io.PrintStream; + import bjc.utils.ioutils.Block; import bjc.utils.ioutils.BlockReader; @@ -22,19 +20,19 @@ public class FDS { /** * Run a provided FDS mode until it is exited or there is no more input. * - * @param comin + * @param blockSource * The command input source for the FDS mode. * * @param datain * The data input source for the FDS mode. * - * @param out + * @param printer * The output source for the FDS mode. * - * @param initialMode + * @param mode * The mode to start in. * - * @param initialState + * @param state * The initial state for the mode. * * @return The final state of the mode. @@ -42,28 +40,46 @@ public class FDS { * @throws FDSException * If something went wrong during mode execution. */ - public static S runFDS(InputStream comin, InputStream datain, OutputStream out, FDSMode initialMode, - S initialState) throws FDSException { - PrintStream printer = new PrintStream(out); + public static S runFDS(BlockReader blockSource, BlockReader datain, PrintStream printer, FDSMode mode, + FDSState state) throws FDSException { + //printer.print("Enter a command (m for help): "); + + while (blockSource.hasNext()) { + Block comBlock = blockSource.next(); + + handleCommandString(comBlock, blockSource, datain, printer, mode, state); + + //printer.print("Enter a command (m for help): "); + } - try (BlockReader blockSource = new BlockReader("\\R", new InputStreamReader(comin))) { - printer.print("Enter a command (m for help): "); + return state.state; + } - while (blockSource.hasNext()) { - Block comBlock = blockSource.next(); + private static void handleCommandString(Block comBlock, BlockReader blockSource, BlockReader datain, + PrintStream printer, FDSMode mode, FDSState state) throws FDSException { + String comString = comBlock.contents.trim(); - String comString = comBlock.contents.trim(); - - char comChar = comString.charAt(0); - - printer.println(String.format("\nRecieved command '%s'\n", comChar)); + switch (state.mode) { + case CHORD: + if (comString.length() > 1) { + for (char c : comString.substring(1).toCharArray()) { + Block newCom = new Block(comBlock.blockNo + 1, Character.toString(c), + comBlock.startLine, comBlock.startLine); - printer.print("Enter a command (m for help): "); + state.enqueCommand.accept(newCom); + } } - } catch (Exception ex) { - throw new FDSException("Unexpected I/O error", ex); + case NORMAL: + handleCommand(comString.charAt(0), blockSource, datain, printer, mode, state); + break; + + default: + throw new FDSException(String.format("Unknown input mode '%s'", state.mode)); } + } - return initialState; + private static void handleCommand(char charAt, BlockReader blockSource, BlockReader datain, + PrintStream printer, FDSMode mode, FDSState state) { + printer.printf("Recieved command '%s'\n", charAt); } } -- cgit v1.2.3