aboutsummaryrefslogtreecommitdiff
path: root/src/scalevalapokalypsi/UI/StdinLineReader.scala
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-27 12:29:43 +0200
committerJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-27 12:29:43 +0200
commit98407b35ff477f372baa92bf582b90a961d4ad16 (patch)
treebb58925090075d1e9e30dd1593547db2cbe03bb6 /src/scalevalapokalypsi/UI/StdinLineReader.scala
parent38900e0b291d5e0f59afaaa239cd237f733b6588 (diff)
downloadscalevalapokalypsi-98407b35ff477f372baa92bf582b90a961d4ad16.tar.gz
scalevalapokalypsi-98407b35ff477f372baa92bf582b90a961d4ad16.zip
Added part of story & improved singing with multiple verses & hemingway distance
Diffstat (limited to 'src/scalevalapokalypsi/UI/StdinLineReader.scala')
-rw-r--r--src/scalevalapokalypsi/UI/StdinLineReader.scala20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/scalevalapokalypsi/UI/StdinLineReader.scala b/src/scalevalapokalypsi/UI/StdinLineReader.scala
index 4d0f778..1509f75 100644
--- a/src/scalevalapokalypsi/UI/StdinLineReader.scala
+++ b/src/scalevalapokalypsi/UI/StdinLineReader.scala
@@ -12,18 +12,22 @@ class StdinLineReader:
private var nextLine: Future[String] = Future.failed(Exception())
- /** Returns a new line of input if there are any. */
- def newLine(): Option[String] =
+ /** Returns a new line of input as a Right when there are any.
+ * If there is no new line due to EOF, returns Left(true),
+ * if there is no new line due to some other error, returns Left(false)
+ */
+ def newLine(): Either[Boolean, String] =
this.nextLine.value match
case Some(Success(s)) =>
- if s.contains("\u0000") then
- println("End of stream!")
- this.startReading()
- Some(s)
+ if s == null then
+ Left(true)
+ else
+ this.startReading()
+ Right(s)
case Some(Failure(e)) =>
this.startReading()
- None
- case None => None
+ Left(false)
+ case None => Left(false)
/** Discards the line that is currently being read and restarts reading */
def startReading(): Unit =