Skip to content

Commit

Permalink
support multi-line update in repl
Browse files Browse the repository at this point in the history
  • Loading branch information
joprice committed Jun 18, 2016
1 parent 83a230e commit 5cfae9f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/Eval.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final case class ResultSet(results: Iterator[Try[List[Item]]]) extends Response
final case class TableNames(names: Iterator[Try[List[String]]]) extends Response
case object Complete extends Response

class Eval(client: AmazonDynamoDB, pageSize: Int = 5) {
class Eval(client: AmazonDynamoDB, pageSize: Int = 20) {
val dynamo = new DynamoDB(client)

def run(query: Query): Try[Response] = query match {
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/Parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ object Parser {
) ~ spaces.? ~ End)

def apply(input: String): Either[Parsed.Failure, Query] = {
// import explicitly as a workaround to this https://github.com/lihaoyi/fastparse/issues/34
import fastparse.core.Parsed.{ Failure, Success }
query.parse(input) match {
case Success(query, _) => Right(query)
Expand Down
33 changes: 19 additions & 14 deletions src/main/scala/Repl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -269,38 +269,43 @@ object Repl {
out.println(Color.Yellow(s"[warn] unhandled response $unhandled"))
}

@tailrec def repl(): Unit = {
@tailrec def repl(buffer: String): Unit = {
// While paging, a single char is read so that a new line is not required to
// go the next page, or quit the pager
val line = if (inPager) {
reader.readCharacter().toChar.toString
} else reader.readLine()
if (line != null) {
val trimmed = line.trim
if (inPager) {
val updated = if (inPager) {
// q is used to quit pagination
if (trimmed == "q")
resetPagination()
else
nextPage()
""
} else if (trimmed.contains(";")) {
resetPrompt(reader)
//TODO: switch to either with custom error type for console output
val stripped = s"$buffer\n${line.stripSuffix(";")}"
Parser(stripped)
.fold(failure => out.println(parseError(stripped, failure)), { query =>
eval(query) match {
case Success(results) => report(query, results)
case Failure(ex) => formatError(ex.getMessage)
}
})
""
} else {
if (trimmed.nonEmpty) {
//TODO: switch to either with custom error type for console output
Parser(line)
.fold(failure => out.println(parseError(line, failure)), { query =>
eval(query) match {
case Success(results) => report(query, results)
case Failure(ex) => formatError(ex.getMessage)
}
})
}
reader.setPrompt(Bold.On(Str(" -> ")).render)
s"$buffer\n$line"
}
out.flush()
repl()
repl(updated)
}
}

repl()
repl("")
}

}
Expand Down

0 comments on commit 5cfae9f

Please sign in to comment.