summaryrefslogtreecommitdiff
path: root/BJC-Utils2
diff options
context:
space:
mode:
authorbjculkin <bjculkin@mix.wvu.edu>2017-03-27 18:58:46 -0400
committerbjculkin <bjculkin@mix.wvu.edu>2017-03-27 18:58:46 -0400
commit4da4974456179168125fd78e5bde09c2de81b258 (patch)
tree8566c28858eb20a50e225bbfe3cde2e3f8208d3a /BJC-Utils2
parentf6c19bb14bf5be44c2d7bf1fef014d170f1c4343 (diff)
Work on FDS more
Diffstat (limited to 'BJC-Utils2')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/CommandHelp.java2
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/fds/FDS.java63
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/fds/FDSMode.java9
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/fds/FDSState.java15
4 files changed, 67 insertions, 22 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/CommandHelp.java b/BJC-Utils2/src/main/java/bjc/utils/cli/CommandHelp.java
index 327fb75..68ed41a 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/CommandHelp.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/CommandHelp.java
@@ -18,7 +18,7 @@ public interface CommandHelp {
* Get the summary line for a command.
*
* A summary line should consist of a string of the following format
- * "<command-name>\t<command-summary>" where anything in angle brackets
+ * <pre>"&lt;command-name>\t&lt;command-summary>"</pre> where anything in angle brackets
* should be filled in.
*
* @return The summary line line for a command
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 effc200..3076415 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
@@ -2,6 +2,7 @@ package bjc.utils.cli.fds;
import java.io.PrintStream;
+import bjc.utils.cli.CommandHelp;
import bjc.utils.cli.fds.FDSState.InputMode;
import bjc.utils.ioutils.Block;
import bjc.utils.ioutils.BlockReader;
@@ -22,28 +23,28 @@ public class FDS {
* Run a provided FDS mode until it is exited or there is no more input.
*
* @param blockSource
- * The command input source for the FDS mode.
+ * The command input source for the FDS mode.
*
* @param datain
- * The data input source for the FDS mode.
+ * The data input source for the FDS mode.
*
* @param printer
- * The output source for the FDS mode.
+ * The output source for the FDS mode.
*
* @param mode
- * The mode to start in.
+ * The mode to start in.
*
* @param state
- * The initial state for the mode.
+ * The initial state for the mode.
*
* @return The final state of the mode.
*
* @throws FDSException
- * If something went wrong during mode execution.
+ * If something went wrong during mode execution.
*/
public static <S> S runFDS(BlockReader blockSource, BlockReader datain, PrintStream printer, FDSState<S> state)
throws FDSException {
- while (blockSource.hasNext()) {
+ while(blockSource.hasNext() && !state.modes.empty()) {
Block comBlock = blockSource.next();
handleCommandString(comBlock, blockSource, datain, printer, state);
@@ -56,19 +57,23 @@ public class FDS {
PrintStream printer, FDSState<S> state) throws FDSException {
String comString = comBlock.contents.trim();
- switch (state.mode) {
+ switch(state.mode) {
case CHORD:
chordCommand(comBlock, state, comString);
case NORMAL:
handleCommand(comString.charAt(0), blockSource, datain, printer, state);
break;
+ case INLINE:
+ break;
+ case CHARINLINE:
+ break;
default:
throw new FDSException(String.format("Unknown input mode '%s'", state.mode));
}
}
private static <S> void chordCommand(Block comBlock, FDSState<S> state, String comString) {
- for (int i = 1; i < comString.length(); i++) {
+ for(int i = 1; i < comString.length(); i++) {
char c = comString.charAt(i);
Block newCom = new Block(comBlock.blockNo + 1, Character.toString(c), comBlock.startLine,
@@ -78,16 +83,18 @@ public class FDS {
}
}
- private static <S> void handleCommand(char com, BlockReader blockSource, BlockReader datain, PrintStream printer,
- FDSState<S> state) throws FDSException {
+ private static <S> void handleCommand(char com, BlockReader blockSource, BlockReader datain,
+ PrintStream printer, FDSState<S> state) throws FDSException {
+ if(state.modes.empty()) return;
+
/*
* Handle built-in commands over user commands.
*/
- switch (com) {
+ switch(com) {
case 'x':
- if (state.mode == InputMode.CHORD) {
+ if(state.mode == InputMode.CHORD) {
state.mode = InputMode.NORMAL;
- } else if (state.mode == InputMode.NORMAL) {
+ } else if(state.mode == InputMode.NORMAL) {
state.mode = InputMode.CHORD;
} else {
printer.println("? CNV\n");
@@ -98,16 +105,38 @@ public class FDS {
* TODO implement loading scripts from file.
*/
break;
+
+ case 'q':
+ state.modes.drop();
+ break;
+ case 'Q':
+ state.modes.drop(state.modes.size());
+ break;
+ case 'm':
+ helpSummary(printer, state);
+ break;
default:
FDSMode<S> curMode = state.modes.top();
- if (curMode.hasSubmode(com)) {
+ if(curMode.hasSubmode(com)) {
curMode.getCommand(com).run(state.state, datain);
- } else if (curMode.hasCommand(com)) {
+ } else if(curMode.hasCommand(com)) {
state.modes.push(curMode.getSubmode(com));
} else {
- printer.printf("? UBC '%s'", com);
+ printer.printf("? UBC '%s'\n", com);
}
}
}
+
+ private static <S> void helpSummary(PrintStream printer, FDSState<S> state) {
+ FDSMode<S> mode = state.modes.top();
+
+ printer.printf("Help for mode %s:\n", mode.getName());
+
+ for(char bound : mode.registeredChars()) {
+ CommandHelp help = mode.getHelp(bound);
+
+ printer.printf("%s\t-\t%s", help.getSummary());
+ }
+ }
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/fds/FDSMode.java b/BJC-Utils2/src/main/java/bjc/utils/cli/fds/FDSMode.java
index acdcbcb..29857e0 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/fds/FDSMode.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/fds/FDSMode.java
@@ -13,6 +13,15 @@ import bjc.utils.cli.NullHelp;
*/
public interface FDSMode<S> {
/**
+ * Get the name of this mode.
+ *
+ * @return The mode of this name.
+ */
+ default String getName() {
+ return "Unnamed Mode";
+ }
+
+ /**
* Get all the characters that are registered to something in this mode.
*
* In this context, something means a command or submode.
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/fds/FDSState.java b/BJC-Utils2/src/main/java/bjc/utils/cli/fds/FDSState.java
index 4a6e1c6..bef86ae 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/fds/FDSState.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/fds/FDSState.java
@@ -34,7 +34,7 @@ public class FDSState<S> {
CHORD,
/**
* Reads every character in the block, but after a terminal
- * command, data will be read inline separated by spaces until a
+ * command, data will be read in-line separated by spaces until a
* semicolon is read.
*
* The semicolon can be escaped with a backslash.
@@ -42,11 +42,12 @@ public class FDSState<S> {
INLINE,
/**
* Reads every character in the block, but after a terminal
- * command, data will be read inline with each character being a
+ * command, data will be read in-line with each character being a
* separate item until a semicolon is read.
*
* The semicolon can be escaped with a backslash.
*/
+ CHARINLINE,
}
/**
@@ -62,7 +63,7 @@ public class FDSState<S> {
* The modes being used.
*/
public Stack<FDSMode<S>> modes;
-
+
/**
* Function to add a command block to be processed.
*/
@@ -81,13 +82,19 @@ public class FDSState<S> {
*
* @param inputMode
* The input mode for the interface.
+ *
+ * @param comQueue
+ * The function to call to add a command block.
+ *
+ * @param dataQueue
+ * The function to call to add a data block.
*/
public FDSState(S stat, InputMode inputMode, Consumer<Block> comQueue, Consumer<Block> dataQueue) {
state = stat;
mode = inputMode;
modes = new SimpleStack<>();
-
+
enqueCommand = comQueue;
enqueData = dataQueue;
}