From 78480dc61cf20844dd91bbcbed98357c724f0030 Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Mon, 16 Mar 2020 09:47:15 -0500 Subject: [PATCH] Include notes when editing marks. --- private/version.nim | 2 +- ptk.nim | 20 ++++++++++++-------- ptk.nimble | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/private/version.nim b/private/version.nim index b010ea6..388a931 100644 --- a/private/version.nim +++ b/private/version.nim @@ -1 +1 @@ -const PTK_VERSION* = "1.0.3" \ No newline at end of file +const PTK_VERSION* = "1.0.4" \ No newline at end of file diff --git a/ptk.nim b/ptk.nim index ff75bc5..843c37f 100644 --- a/ptk.nim +++ b/ptk.nim @@ -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,6 +144,7 @@ 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 @@ -152,12 +155,13 @@ proc edit(mark: var Mark): void = 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 + 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({',', ';'}); + result.notes = "" markPart = Notes - else: mark.notes &= line & "\x0D\x0A" + else: result.notes &= line & "\x0D\x0A" finally: close(tempFile) @@ -425,7 +429,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) @@ -455,7 +459,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( @@ -492,7 +496,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) diff --git a/ptk.nimble b/ptk.nimble index 8dc902d..5bb70fb 100644 --- a/ptk.nimble +++ b/ptk.nimble @@ -1,6 +1,6 @@ # Package -version = "1.0.3" +version = "1.0.4" author = "Jonathan Bernard" description = "Personal Time Keeper" license = "MIT"