2 Commits
0.1 ... 0.3

Author SHA1 Message Date
284a4159d1 Added command to re-read the timeline source. 2013-08-09 11:45:56 -05:00
e4a756baf5 Moved back to realtime update model.
* Using patched version of Jansi.
* Raw ANSI controls always sent to play well with Nailgun.
2013-08-08 23:14:18 -05:00
13 changed files with 83 additions and 55 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,5 +1,5 @@
#Thu, 08 Aug 2013 19:52:35 -0500
#Fri, 09 Aug 2013 11:44:57 -0500
lib.local=true
name=timestamper-cli
version=0.1
build.number=29
version=0.3
build.number=1

View File

@ -1,5 +1,6 @@
package com.jdblabs.timestamper.cli
import com.jdbernard.io.NonBlockingInputStreamReader
import com.jdbernard.util.SmartConfig
import com.jdbernard.util.LightOptionParser
import com.jdblabs.timestamper.core.Timeline
@ -25,7 +26,7 @@ public class TimeStamperCLI {
public static final String VERSION = "0.1"
protected static def cli = [
'v': [longOpt: 'version'],
'v': [longOpt: 'version'],
'd': [longOpt: 'working-directory', arguments: 1],
't': [longOpt: 'timeline-config', arguments: 1] ]
@ -43,7 +44,7 @@ public class TimeStamperCLI {
protected static doMain(TimeStamperCLI inst, String[] args,
def sin, def out, def err) {
out = new PrintStream(AnsiConsole.wrapOutputStream(out))
//out = new PrintStream(AnsiConsole.wrapOutputStream(out))
def opts = LightOptionParser.parseOptions(cli, args as List)
File workingDir = new File(opts.d ?: '.')
@ -84,87 +85,114 @@ public class TimeStamperCLI {
//out.println ""
def currentMarker = timeline.getLastMarker(new Date())
Reader reader = new InputStreamReader(sin)
def reader = new NonBlockingInputStreamReader(sin)
Thread readerThread = new Thread(reader)
readerThread.start()
boolean running = true
def blockingReadLine = {
String line = null;
while (line == null && readerThread.isAlive()) {
line = reader.readLine()
Thread.sleep(200) }
return line }
def readNotes = {
out.println(ansi().fg(YELLOW).
a("Notes (end with EOF or a blank line):").reset())
String notes = ""
String line = null
line = reader.readLine()
line = blockingReadLine()
while(line != "" && line != "EOF" && line != null) {
notes += line + EOL
line = reader.readLine() }
line = blockingReadLine() }
return notes
}
return notes }
def printPrompt = {
out.print(formatMarker(currentMarker) + EOL +
ansi().fg(YELLOW).a("> ").reset())
out.flush() }
String line = null
while (running) {
printPrompt()
while (running && readerThread.isAlive()) {
out.println formatMarker(currentMarker)
out.print(ansi().fg(YELLOW).a("> ").reset())
out.flush();
// Handle user input
// Handle user input
line = reader.readLine()
switch (line) {
if (line != null) {
out.flush();
switch (line) {
case ~/quit|exit|\u0004/:
running = false;
break
case null:
case ~/quit|exit|\u0004/:
running = false;
break
case ~/n|new/:
case ~/r|refresh|^$/:
out.print(ansi().eraseLine().cursorUp(2).eraseLine())
break
// Read mark
out.println(ansi().fg(YELLOW).a("New timestamp:").reset())
String mark = blockingReadLine()
case ~/n|new/:
// Read notes
String notes = readNotes();
// Read mark
out.println(ansi().fg(YELLOW).a("New timestamp:").reset())
String mark = reader.readLine()
// Create marker
currentMarker = new TimelineMarker(new Date(), mark, notes)
timeline.addMarker(currentMarker)
if (timelineProperties.persistOnUpdate)
timelineProperties.save()
break
// Read notes
String notes = readNotes();
case ~/h|help/:
out.println(ansi().fg(RED).
a("Not yet implemented.").reset());
break
// Create marker
currentMarker = new TimelineMarker(new Date(), mark, notes)
timeline.addMarker(currentMarker)
if (timelineProperties.persistOnUpdate)
case ~/l|list|history/:
out.println(ansi().fg(RED).
a("Not yet implemented.").reset());
break
case ~/s|save/:
timelineProperties.save()
break
break
case ~/h|help/:
out.println(ansi().eraseLine().
fg(RED).a("Not yet implemented."));
break
case ~/reload/:
timeline = timelineProperties.reloadTimeline()
currentMarker = timeline.getLastMarker(new Date())
break
case ~/l|list|history/:
out.println(ansi().eraseLine().
fg(RED).a("Not yet implemented."));
break
default:
String notes = readNotes()
currentMarker = new TimelineMarker(new Date(), line, notes)
timeline.addMarker(currentMarker)
if (timelineProperties.persistOnUpdate)
timelineProperties.save()
break
}
printPrompt()
} else {
out.print(ansi().saveCursorPosition().cursorUpLine().eraseLine().toString() +
formatMarker(currentMarker) +
ansi().cursorDown(1).restorCursorPosition().toString())
out.flush();
case ~/s|save/:
timelineProperties.save()
break
default:
String notes = readNotes()
currentMarker = new TimelineMarker(new Date(), line, notes)
timeline.addMarker(currentMarker)
if (timelineProperties.persistOnUpdate)
timelineProperties.save()
break
Thread.sleep(200)
}
}
if (readerThread.isAlive()) {
readerThread.interrupt();
readerThread.join(500);
if (readerThread.isAlive()) readerThread.stop(); }
out.println ""
}
protected static String formatMarker(TimelineMarker tm) {