From ea88542aec97f570a01303a7e73336701e266259 Mon Sep 17 00:00:00 2001 From: "Benjamin J. Culkin" Date: Sun, 10 Sep 2017 21:07:22 -0300 Subject: More BlockReader work This includes some minor fixes to the BlockReaderCLI, and two new BlockReader types * MappedBlockReader - Apply a function to each block, transforming it. * FlatMappedBlockReader - Apply a function to each block, expanding it into one or more blocks. --- .../java/bjc/utils/cli/objects/BlockReaderCLI.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/cli') diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/objects/BlockReaderCLI.java b/BJC-Utils2/src/main/java/bjc/utils/cli/objects/BlockReaderCLI.java index 115f782..5a87a9a 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/cli/objects/BlockReaderCLI.java +++ b/BJC-Utils2/src/main/java/bjc/utils/cli/objects/BlockReaderCLI.java @@ -46,7 +46,7 @@ public class BlockReaderCLI { BlockReaderCLI reader = new BlockReaderCLI(sources); - reader.run(new Scanner(System.in), "console"); + reader.run(new Scanner(System.in), "console", true); } /** @@ -56,11 +56,15 @@ public class BlockReaderCLI { * The place to read input from. * @param ioSource * The name of the place to read input from. + * @param interactive + * Whether or not the source is interactive */ - public void run(Scanner input, String ioSource) { + public void run(Scanner input, String ioSource, boolean interactive) { int lno = 0; while(input.hasNextLine()) { - System.out.printf("reader-conf(%d)>", lno); + if(interactive) + System.out.printf("reader-conf(%d)>", lno); + String ln = input.nextLine(); lno += 1; @@ -68,7 +72,7 @@ public class BlockReaderCLI { Command com = Command.fromString(ln, lno, ioSource); if(com == null) continue; - handleCommand(com); + handleCommand(com, true); } input.close(); @@ -77,7 +81,7 @@ public class BlockReaderCLI { /* * Handle a command. */ - public void handleCommand(Command com) { + public void handleCommand(Command com, boolean interactive) { switch(com.nameCommand) { case "def-filtered": defFiltered(com); @@ -96,8 +100,9 @@ public class BlockReaderCLI { break; case "exit": case "quit": - System.out.printf("Exiting reader-conf, %d readers configured in %d commands\n", - readers.size(), com.lineNo); + if(interactive) + System.out.printf("Exiting reader-conf, %d readers configured in %d commands\n", + readers.size(), com.lineNo); break; default: System.err.print(com.error("Unknown command '%s'\n", com.nameCommand)); -- cgit v1.2.3