|
|
|
@ -3,8 +3,8 @@
|
|
|
|
|
##
|
|
|
|
|
## Simple time keeping CLI
|
|
|
|
|
|
|
|
|
|
import algorithm, docopt, json, langutils, logging, os, nre, sequtils,
|
|
|
|
|
sets, strutils, tempfile, terminal, times, uuids
|
|
|
|
|
import algorithm, docopt, json, langutils, logging, os, nre, std/wordwrap,
|
|
|
|
|
sequtils, sets, strutils, tempfile, terminal, times, uuids
|
|
|
|
|
|
|
|
|
|
import timeutils except `-`;
|
|
|
|
|
|
|
|
|
@ -98,7 +98,7 @@ proc writeMarks(timeline: Timeline, indices: seq[int], includeNotes = false): vo
|
|
|
|
|
|
|
|
|
|
if includeNotes and len(w.mark.notes.strip) > 0:
|
|
|
|
|
writeLine(stdout, "")
|
|
|
|
|
let wrappedNotes = wordWrap(s = w.mark.notes,
|
|
|
|
|
let wrappedNotes = wrapWords(s = w.mark.notes,
|
|
|
|
|
maxLineWidth = colWidth)
|
|
|
|
|
for line in splitLines(wrappedNotes):
|
|
|
|
|
writeLine(stdout, spaces(notesPrefixLen) & line)
|
|
|
|
@ -123,10 +123,12 @@ proc doInit(timelineLocation: string): void =
|
|
|
|
|
|
|
|
|
|
type ExpectedMarkPart = enum Time, Summary, Tags, Notes
|
|
|
|
|
|
|
|
|
|
proc edit(mark: var Mark): void =
|
|
|
|
|
proc edit(mark: Mark): Mark =
|
|
|
|
|
## Interactively edit a mark using the editor named in the environment
|
|
|
|
|
## variable "EDITOR"
|
|
|
|
|
|
|
|
|
|
result = mark
|
|
|
|
|
|
|
|
|
|
var
|
|
|
|
|
tempFile: File
|
|
|
|
|
tempFileName: string
|
|
|
|
@ -142,22 +144,26 @@ proc edit(mark: var Mark): void =
|
|
|
|
|
tempFile.writeLine(
|
|
|
|
|
"""# Everything from the line below to the end of the file will be considered
|
|
|
|
|
# notes for this timeline mark.""")
|
|
|
|
|
tempFile.write(mark.notes)
|
|
|
|
|
|
|
|
|
|
close(tempFile)
|
|
|
|
|
tempFile = nil
|
|
|
|
|
|
|
|
|
|
discard os.execShellCmd "$EDITOR " & tempFileName & " </dev/tty >/dev/tty"
|
|
|
|
|
|
|
|
|
|
var markPart = Time
|
|
|
|
|
var notes: seq[string] = @[]
|
|
|
|
|
|
|
|
|
|
for line in lines tempFileName:
|
|
|
|
|
if strip(line)[0] == '#': continue
|
|
|
|
|
elif markPart == Time: mark.time = parseTime(line); markPart = Summary
|
|
|
|
|
elif markPart == Summary: mark.summary = line; markPart = Tags
|
|
|
|
|
if strip(line).len > 0 and strip(line)[0] == '#': continue
|
|
|
|
|
elif markPart == Time: result.time = parseTime(line); markPart = Summary
|
|
|
|
|
elif markPart == Summary: result.summary = line; markPart = Tags
|
|
|
|
|
elif markPart == Tags:
|
|
|
|
|
mark.tags = line.split({',', ';'});
|
|
|
|
|
result.tags = line.split({',', ';'});
|
|
|
|
|
markPart = Notes
|
|
|
|
|
else: mark.notes &= line & "\x0D\x0A"
|
|
|
|
|
else: notes.add(line)
|
|
|
|
|
|
|
|
|
|
result.notes = notes.join("\n")
|
|
|
|
|
finally: close(tempFile)
|
|
|
|
|
|
|
|
|
|
proc filterMarkIndices(timeline: Timeline, args: Table[string, Value]): seq[int] =
|
|
|
|
@ -424,7 +430,7 @@ Options:
|
|
|
|
|
notes: args["--notes"] ?: "",
|
|
|
|
|
tags: (args["--tags"] ?: "").split({',', ';'}).filterIt(not it.isNilOrWhitespace))
|
|
|
|
|
|
|
|
|
|
if args["--edit"]: edit(newMark)
|
|
|
|
|
if args["--edit"]: newMark = edit(newMark)
|
|
|
|
|
|
|
|
|
|
let prevLastIdx = timeline.marks.getLastIndex()
|
|
|
|
|
timeline.marks.add(newMark)
|
|
|
|
@ -454,7 +460,7 @@ Options:
|
|
|
|
|
notes: markToResume.notes,
|
|
|
|
|
tags: markToResume.tags)
|
|
|
|
|
|
|
|
|
|
if args["--edit"]: edit(newMark)
|
|
|
|
|
if args["--edit"]: newMark = edit(newMark)
|
|
|
|
|
|
|
|
|
|
timeline.marks.add(newMark)
|
|
|
|
|
timeline.writeMarks(
|
|
|
|
@ -491,7 +497,7 @@ Options:
|
|
|
|
|
except: raise newException(ValueError,
|
|
|
|
|
"invalid value for --time: " & getCurrentExceptionMsg())
|
|
|
|
|
|
|
|
|
|
if args["--edit"]: edit(mark)
|
|
|
|
|
if args["--edit"]: mark = edit(mark)
|
|
|
|
|
|
|
|
|
|
timeline.marks.delete(markIdx)
|
|
|
|
|
timeline.marks.insert(mark, markIdx)
|
|
|
|
|