summaryrefslogtreecommitdiff
path: root/base/src/main/java/bjc/utils/cli/Terminal.java
diff options
context:
space:
mode:
authorBen Culkin <scorpress@gmail.com>2023-06-23 19:48:38 -0400
committerBen Culkin <scorpress@gmail.com>2023-06-23 19:48:38 -0400
commit2df02c35b70f7e8077832470de9594b657f1be67 (patch)
tree4353ce1f78571e038bbe8fed62d321c77a7b868c /base/src/main/java/bjc/utils/cli/Terminal.java
parent4a96d9cad446ea405b51dfeebb01a1b6d7f6fb2b (diff)
Add terminal
This is some functionality based on the way that MVS/other IBM OSes handle their UI
Diffstat (limited to 'base/src/main/java/bjc/utils/cli/Terminal.java')
-rw-r--r--base/src/main/java/bjc/utils/cli/Terminal.java51
1 files changed, 51 insertions, 0 deletions
diff --git a/base/src/main/java/bjc/utils/cli/Terminal.java b/base/src/main/java/bjc/utils/cli/Terminal.java
new file mode 100644
index 0000000..a10d82e
--- /dev/null
+++ b/base/src/main/java/bjc/utils/cli/Terminal.java
@@ -0,0 +1,51 @@
+package bjc.utils.cli;
+
+import java.util.*;
+
+/**
+ * A terminal with support for asking multiple questions, and retrieving the
+ * results piecemeal.
+ *
+ * This class is heavily inspired by the way that the old IBM MVS terminal
+ * worked, where the terminal would send you a series of requests and you would
+ * reply to them in whatever order you wanted.
+ *
+ * @author bjcul
+ */
+public interface Terminal {
+ /**
+ * Submit a request to the terminal
+ *
+ * @param req The body of the request
+ * @return The ID of the request
+ */
+ long submitRequest(String req);
+
+ /**
+ * Await a reply for a given request. Will block the current thread until a
+ * response is available.
+ *
+ * @param id The ID of the request
+ * @return The response to that request
+ * @throws InterruptedException If we are interrupted waiting for the reply
+ */
+ String awaitReply(long id) throws InterruptedException;
+
+ /**
+ * Check if a reply for a request is available, without blocking.
+ *
+ * @param id The ID of the request
+ * @return The reply to the request if one is available, and empty otherwise
+ */
+ Optional<String> checkReply(long id);
+
+ /**
+ * Submit a request and await the reply to it. Will block the current thread
+ * until a response is received.
+ *
+ * @param req The request to submit
+ * @return The reply to the request
+ * @throws InterruptedException If we are interrupted waiting for the reply
+ */
+ String submitRequestSync(String req) throws InterruptedException;;
+} \ No newline at end of file