Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
76bf676c2c | |||
284a4159d1 | |||
e4a756baf5 |
12
build.xml
12
build.xml
@ -4,4 +4,16 @@
|
|||||||
<property file="project.properties"/>
|
<property file="project.properties"/>
|
||||||
<import file="jdb-build-1.10.xml"/>
|
<import file="jdb-build-1.10.xml"/>
|
||||||
|
|
||||||
|
<target name="package" depends="build">
|
||||||
|
<property name="package.dir" value="${build.dir}/${name}-${version}"/>
|
||||||
|
<mkdir dir="${package.dir}/lib"/>
|
||||||
|
<copy file="${build.dir}/${name}-${version}.${build.number}.jar"
|
||||||
|
tofile="${package.dir}/${name}-${version}.jar"/>
|
||||||
|
<copy todir="${package.dir}/lib">
|
||||||
|
<fileset dir="${build.dir}/lib/runtime/jar"/>
|
||||||
|
</copy>
|
||||||
|
<zip basedir="${build.dir}" includes="${name}-${version}/"
|
||||||
|
destfile="${build.dir}/${name}-${version}.zip"/>
|
||||||
|
|
||||||
|
</target>
|
||||||
</project>
|
</project>
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
lib/compile/jar/jdb-util-2.0.jar
Normal file
BIN
lib/compile/jar/jdb-util-2.0.jar
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
lib/runtime/jar/jdb-util-2.0.jar
Normal file
BIN
lib/runtime/jar/jdb-util-2.0.jar
Normal file
Binary file not shown.
Binary file not shown.
@ -1,5 +1,5 @@
|
|||||||
#Thu, 08 Aug 2013 19:52:35 -0500
|
#Sat, 10 Aug 2013 01:38:31 -0500
|
||||||
lib.local=true
|
lib.local=true
|
||||||
name=timestamper-cli
|
name=timestamper-cli
|
||||||
version=0.1
|
version=0.4
|
||||||
build.number=29
|
build.number=13
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.jdblabs.timestamper.cli
|
package com.jdblabs.timestamper.cli
|
||||||
|
|
||||||
|
import com.jdbernard.io.NonBlockingInputStreamReader
|
||||||
import com.jdbernard.util.SmartConfig
|
import com.jdbernard.util.SmartConfig
|
||||||
import com.jdbernard.util.LightOptionParser
|
import com.jdbernard.util.LightOptionParser
|
||||||
import com.jdblabs.timestamper.core.Timeline
|
import com.jdblabs.timestamper.core.Timeline
|
||||||
@ -22,12 +23,13 @@ public class TimeStamperCLI {
|
|||||||
protected TimelineProperties timelineProperties
|
protected TimelineProperties timelineProperties
|
||||||
protected Timeline timeline
|
protected Timeline timeline
|
||||||
|
|
||||||
public static final String VERSION = "0.1"
|
public static final String VERSION = "0.4"
|
||||||
|
|
||||||
protected static def cli = [
|
protected static def cli = [
|
||||||
'v': [longOpt: 'version'],
|
'v': [longOpt: 'version'],
|
||||||
'd': [longOpt: 'working-directory', arguments: 1],
|
'd': [longOpt: 'working-directory', arguments: 1],
|
||||||
't': [longOpt: 'timeline-config', arguments: 1] ]
|
't': [longOpt: 'timeline-config', arguments: 1],
|
||||||
|
'tty': [longOpt: 'tty', arguments: 1]]
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
@ -40,17 +42,22 @@ public class TimeStamperCLI {
|
|||||||
|
|
||||||
doMain(nailgunInst, context.args, context.in, context.out, context.err) }
|
doMain(nailgunInst, context.args, context.in, context.out, context.err) }
|
||||||
|
|
||||||
protected static doMain(TimeStamperCLI inst, String[] args,
|
protected static void doMain(TimeStamperCLI inst, String[] args,
|
||||||
def sin, def out, def err) {
|
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)
|
def opts = LightOptionParser.parseOptions(cli, args as List)
|
||||||
|
|
||||||
File workingDir = new File(opts.d ?: '.')
|
File workingDir = new File(opts.d ?: '.')
|
||||||
|
String ttyDevice = opts.tty ?: '/dev/tty'
|
||||||
|
|
||||||
|
if (opts.v) {
|
||||||
|
println "TimeStamperCLI v${VERSION}"
|
||||||
|
return }
|
||||||
|
|
||||||
if (opts.t) {
|
if (opts.t) {
|
||||||
File propFile = new File(workingDir, opts.t)
|
File propFile = new File(workingDir, opts.t)
|
||||||
inst.showTimeline(propFile, sin, out, err) }
|
inst.showTimeline(propFile, sin, out, err, ttyDevice) }
|
||||||
else if (inst.timeline == null) {
|
else if (inst.timeline == null) {
|
||||||
// Look for .timestamperrc user config file
|
// Look for .timestamperrc user config file
|
||||||
File cfgFile = new File(
|
File cfgFile = new File(
|
||||||
@ -60,13 +67,13 @@ public class TimeStamperCLI {
|
|||||||
cfgFile.canonicalPath
|
cfgFile.canonicalPath
|
||||||
else {
|
else {
|
||||||
def cfg = new SmartConfig(cfgFile)
|
def cfg = new SmartConfig(cfgFile)
|
||||||
inst.showTimeline(new File(cfg.lastUsed), sin, out, err) } }
|
inst.showTimeline(new File(cfg.lastUsed), sin, out, err, ttyDevice) } }
|
||||||
else { inst.showTimeline(sin, out, err) } }
|
else { inst.showTimeline(sin, out, err, ttyDevice) } }
|
||||||
|
|
||||||
public TimeStamperCLI() { }
|
public TimeStamperCLI() { }
|
||||||
|
|
||||||
public void showTimeline(File timelinePropertiesFile,
|
public void showTimeline(File timelinePropertiesFile,
|
||||||
def sin, def out, def err) {
|
def sin, def out, def err, String ttyDevice) {
|
||||||
if (!timelinePropertiesFile.exists() ||
|
if (!timelinePropertiesFile.exists() ||
|
||||||
!timelinePropertiesFile.isFile()) {
|
!timelinePropertiesFile.isFile()) {
|
||||||
|
|
||||||
@ -78,93 +85,180 @@ public class TimeStamperCLI {
|
|||||||
this.timelineProperties = new TimelineProperties(timelinePropertiesFile)
|
this.timelineProperties = new TimelineProperties(timelinePropertiesFile)
|
||||||
this.timeline = timelineProperties.timeline
|
this.timeline = timelineProperties.timeline
|
||||||
|
|
||||||
showTimeline(sin, out, err) }
|
showTimeline(sin, out, err, ttyDevice) }
|
||||||
|
|
||||||
public void showTimeline(final def sin, def out, def err) {
|
public void showTimeline(final def sin, def out, def err, String ttyDevice) {
|
||||||
|
|
||||||
//out.println ""
|
//out.println ""
|
||||||
def currentMarker = timeline.getLastMarker(new Date())
|
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
|
boolean running = true
|
||||||
|
|
||||||
|
def blockingReadLine = {
|
||||||
|
String line = null;
|
||||||
|
while (line == null && readerThread.isAlive()) {
|
||||||
|
line = reader.readLine()
|
||||||
|
|
||||||
|
Thread.sleep(200) }
|
||||||
|
|
||||||
|
return line }
|
||||||
|
|
||||||
def readNotes = {
|
def readNotes = {
|
||||||
out.println(ansi().fg(YELLOW).
|
out.println(ansi().fg(YELLOW).
|
||||||
a("Notes (end with EOF or a blank line):").reset())
|
a("Notes (end with EOF or a blank line):").reset())
|
||||||
|
|
||||||
String notes = ""
|
String notes = ""
|
||||||
String line = null
|
String line = null
|
||||||
line = reader.readLine()
|
line = blockingReadLine()
|
||||||
|
|
||||||
while(line != "" && line != "EOF" && line != null) {
|
while(line != "" && line != "EOF" && line != null) {
|
||||||
notes += line + EOL
|
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
|
String line = null
|
||||||
|
|
||||||
while (running) {
|
printPrompt()
|
||||||
|
while (running && readerThread.isAlive()) {
|
||||||
|
|
||||||
out.println formatMarker(currentMarker)
|
// Handle user input
|
||||||
out.print(ansi().fg(YELLOW).a("> ").reset())
|
|
||||||
out.flush();
|
|
||||||
|
|
||||||
// Handle user input
|
|
||||||
line = reader.readLine()
|
line = reader.readLine()
|
||||||
|
if (line != null) {
|
||||||
switch (line) {
|
out.flush();
|
||||||
|
switch (line) {
|
||||||
|
case ~/quit|exit|\u0004/:
|
||||||
|
running = false;
|
||||||
|
break
|
||||||
|
|
||||||
case null:
|
case ~/n|new/:
|
||||||
case ~/quit|exit|\u0004/:
|
|
||||||
running = false;
|
|
||||||
break
|
|
||||||
|
|
||||||
case ~/r|refresh|^$/:
|
// Read mark
|
||||||
out.print(ansi().eraseLine().cursorUp(2).eraseLine())
|
out.println(ansi().fg(YELLOW).a("New timestamp mark:").reset())
|
||||||
break
|
String mark = blockingReadLine()
|
||||||
|
|
||||||
case ~/n|new/:
|
// Read notes
|
||||||
|
String notes = readNotes();
|
||||||
|
|
||||||
// Read mark
|
// Create marker
|
||||||
out.println(ansi().fg(YELLOW).a("New timestamp:").reset())
|
currentMarker = new TimelineMarker(new Date(), mark, notes)
|
||||||
String mark = reader.readLine()
|
timeline.addMarker(currentMarker)
|
||||||
|
if (timelineProperties.persistOnUpdate)
|
||||||
|
timelineProperties.save()
|
||||||
|
break
|
||||||
|
|
||||||
// Read notes
|
case ~/h|help/:
|
||||||
String notes = readNotes();
|
out.println(ansi().fg(RED).
|
||||||
|
a("Not yet implemented.").reset());
|
||||||
|
break
|
||||||
|
|
||||||
// Create marker
|
case ~/l|list|history/:
|
||||||
currentMarker = new TimelineMarker(new Date(), mark, notes)
|
out.println(ansi().fg(RED).
|
||||||
timeline.addMarker(currentMarker)
|
a("Not yet implemented.").reset());
|
||||||
if (timelineProperties.persistOnUpdate)
|
break
|
||||||
|
|
||||||
|
case ~/s|save/:
|
||||||
timelineProperties.save()
|
timelineProperties.save()
|
||||||
break
|
break
|
||||||
|
|
||||||
case ~/h|help/:
|
case ~/reload/:
|
||||||
out.println(ansi().eraseLine().
|
timeline = timelineProperties.reloadTimeline()
|
||||||
fg(RED).a("Not yet implemented."));
|
currentMarker = timeline.getLastMarker(new Date())
|
||||||
break
|
break
|
||||||
|
|
||||||
case ~/l|list|history/:
|
case ~/e|ed|edit/:
|
||||||
out.println(ansi().eraseLine().
|
reader.pause()
|
||||||
fg(RED).a("Not yet implemented."));
|
out.println(ansi().fg(YELLOW).
|
||||||
break
|
a("Press ENTER to launch an editor for the current marker..."))
|
||||||
|
out.flush()
|
||||||
|
blockingReadLine()
|
||||||
|
currentMarker = edit(currentMarker, ttyDevice)
|
||||||
|
reader.resume()
|
||||||
|
break
|
||||||
|
|
||||||
case ~/s|save/:
|
case ~/d|del|delete/:
|
||||||
timelineProperties.save()
|
timeline.removeMarker(currentMarker)
|
||||||
break
|
currentMarker = timeline.getLastMarker(new Date())
|
||||||
|
break
|
||||||
|
|
||||||
default:
|
default:
|
||||||
String notes = readNotes()
|
String notes = readNotes()
|
||||||
currentMarker = new TimelineMarker(new Date(), line, notes)
|
currentMarker = new TimelineMarker(new Date(), line, notes)
|
||||||
timeline.addMarker(currentMarker)
|
timeline.addMarker(currentMarker)
|
||||||
if (timelineProperties.persistOnUpdate)
|
if (timelineProperties.persistOnUpdate)
|
||||||
timelineProperties.save()
|
timelineProperties.save()
|
||||||
break
|
break
|
||||||
|
}
|
||||||
|
printPrompt()
|
||||||
|
} else {
|
||||||
|
out.print(ansi().saveCursorPosition().cursorUpLine().eraseLine().toString() +
|
||||||
|
formatMarker(currentMarker) +
|
||||||
|
ansi().cursorDown(1).restorCursorPosition().toString())
|
||||||
|
out.flush();
|
||||||
|
|
||||||
|
Thread.sleep(200)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (readerThread.isAlive()) {
|
||||||
|
readerThread.interrupt();
|
||||||
|
readerThread.join(500);
|
||||||
|
if (readerThread.isAlive()) readerThread.stop(); }
|
||||||
|
|
||||||
|
out.println ""
|
||||||
|
}
|
||||||
|
|
||||||
|
protected TimelineMarker edit(TimelineMarker tm, String ttyDevice) {
|
||||||
|
File temp = File.createTempFile('timestamp-mark-', '.txt')
|
||||||
|
temp.withPrintWriter { fout ->
|
||||||
|
fout.println("""\
|
||||||
|
# Edit the time, mark, and notes below. Any lines starting with '#' will be
|
||||||
|
# ignored. When done, save the file and close the editor.""")
|
||||||
|
fout.println(Timeline.longFormat.format(tm.timestamp))
|
||||||
|
fout.println(tm.mark)
|
||||||
|
fout.println("""\
|
||||||
|
# Everything from the line below to the end of the file will be considered
|
||||||
|
# notes for this timeline mark.""")
|
||||||
|
fout.println(tm.notes) }
|
||||||
|
|
||||||
|
['sh', '-c', "\$EDITOR ${temp.canonicalPath} <${ttyDevice} >${ttyDevice}"].execute().waitFor()
|
||||||
|
|
||||||
|
Thread.sleep(200)
|
||||||
|
|
||||||
|
String newTimeStr
|
||||||
|
String newMark
|
||||||
|
String newNotes = ""
|
||||||
|
|
||||||
|
temp.eachLine { line ->
|
||||||
|
if (line =~ /^\s*#/) return
|
||||||
|
|
||||||
|
if (!newTimeStr) newTimeStr = line
|
||||||
|
else if (!newMark) newMark = line
|
||||||
|
else newNotes += line + EOL }
|
||||||
|
|
||||||
|
Date newTime
|
||||||
|
try { newTime = Timeline.longFormat.parse(newTimeStr) }
|
||||||
|
catch(Exception e) {
|
||||||
|
out.println(ansi().fg(RED).a("Invalid timestamp format. The " +
|
||||||
|
"previous timestamp value will be retained."))
|
||||||
|
newTime = currentMark.timestamp }
|
||||||
|
|
||||||
|
timeline.removeMarker(tm)
|
||||||
|
def newMarker = new TimelineMarker(newTime, newMark, newNotes)
|
||||||
|
timeline.addMarker(newMarker)
|
||||||
|
if (timelineProperties.persistOnUpdate)
|
||||||
|
timelineProperties.save()
|
||||||
|
|
||||||
|
return newMarker
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static String formatMarker(TimelineMarker tm) {
|
protected static String formatMarker(TimelineMarker tm) {
|
||||||
|
Reference in New Issue
Block a user