diff options
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/cli/fds/FDSUtils.java')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/cli/fds/FDSUtils.java | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/fds/FDSUtils.java b/BJC-Utils2/src/main/java/bjc/utils/cli/fds/FDSUtils.java new file mode 100644 index 0000000..ec8cea8 --- /dev/null +++ b/BJC-Utils2/src/main/java/bjc/utils/cli/fds/FDSUtils.java @@ -0,0 +1,61 @@ +package bjc.utils.cli.fds; + +import static bjc.utils.ioutils.BlockReaders.pushback; +import static bjc.utils.ioutils.BlockReaders.simple; +import static bjc.utils.ioutils.BlockReaders.trigger; + +import java.io.PrintStream; +import java.io.Reader; + +import bjc.utils.cli.fds.FDSState.InputMode; +import bjc.utils.ioutils.BlockReader; +import bjc.utils.ioutils.Prompter; +import bjc.utils.ioutils.PushbackBlockReader; + +/** + * Utilities for dealing with FDS + * + * @author bjculkin + * + */ +public class FDSUtils { + /** + * Run a FDS instance from a reader. + * + * @param reader + * The reader to use. + * + * @param out + * The output stream to use. + * + * @param mode + * The mode to use. + * + * @param ctx + * The initial state. + * + * @return The final state. + * + * @throws FDSException + * If something goes wrong. + */ + public static <S> S runFromReader(Reader reader, PrintStream out, FDSMode<S> mode, S ctx) throws FDSException { + BlockReader input = simple("\\R", reader); + + Prompter comPrompter = new Prompter("Enter a command (m for help): ", out); + Prompter dataPrompter = new Prompter("> ", out); + + BlockReader rawComInput = trigger(input, comPrompter); + BlockReader rawDataInput = trigger(input, dataPrompter); + + PushbackBlockReader comInput = pushback(rawComInput); + PushbackBlockReader dataInput = pushback(rawDataInput); + + FDSState<S> fdsState = new FDSState<>(ctx, InputMode.NORMAL, comInput, dataInput, out); + fdsState.modes.push(mode); + + FDS.runFDS(fdsState); + + return ctx; + } +}
\ No newline at end of file |
