Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
e62a4e31de | |||
5140afa671 |
34
ptk.nim
34
ptk.nim
@ -188,27 +188,6 @@ proc writeMarks(timeline: Timeline, indices: seq[int], includeNotes = false): vo
|
|||||||
writeLine(stdout, spaces(notesPrefixLen) & line)
|
writeLine(stdout, spaces(notesPrefixLen) & line)
|
||||||
writeLine(stdout, "")
|
writeLine(stdout, "")
|
||||||
|
|
||||||
proc formatMark(mark: Mark, nextMark = NO_MARK, timeFormat = ISO_TIME_FORMAT, includeNotes = false): string =
|
|
||||||
## Pretty-format a Mark, optionally taking the next Mark in the timeline (to
|
|
||||||
## compute duration) and a time format string, and conditionally including
|
|
||||||
## the Mark's notes in the output.
|
|
||||||
|
|
||||||
let nextTime =
|
|
||||||
if nextMark == NO_MARK: getTime().local
|
|
||||||
else: nextMark.time
|
|
||||||
|
|
||||||
let duration = (nextTime - mark.time).flexFormat
|
|
||||||
# TODO: pick up here calculating the time between marks
|
|
||||||
|
|
||||||
let prefix = ($mark.id)[0..<8] & " " & mark.time.format(timeFormat) & " (" & duration & ") -- "
|
|
||||||
|
|
||||||
result = prefix & mark.summary
|
|
||||||
if includeNotes and len(mark.notes.strip()) > 0:
|
|
||||||
let wrappedNotes = wordWrap(s = mark.notes, maxLineWidth = 80 - prefix.len)
|
|
||||||
for line in splitLines(wrappedNotes):
|
|
||||||
result &= "\x0D\x0A" & spaces(prefix.len) & line
|
|
||||||
result &= "\x0D\x0A"
|
|
||||||
|
|
||||||
proc findById(marks: seq[Mark], id: string): int =
|
proc findById(marks: seq[Mark], id: string): int =
|
||||||
var idx = 0
|
var idx = 0
|
||||||
for mark in marks:
|
for mark in marks:
|
||||||
@ -407,13 +386,12 @@ Options:
|
|||||||
-v --verbose Include notes in timeline entry output.
|
-v --verbose Include notes in timeline entry output.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# TODO: add ptk delete [options]
|
|
||||||
|
|
||||||
logging.addHandler(newConsoleLogger())
|
logging.addHandler(newConsoleLogger())
|
||||||
let now = getTime().local
|
let now = getTime().local
|
||||||
|
|
||||||
# Parse arguments
|
# Parse arguments
|
||||||
let args = docopt(doc, version = "ptk 0.12.2")
|
let args = docopt(doc, version = "ptk 0.12.4")
|
||||||
|
|
||||||
if args["--echo-args"]: echo $args
|
if args["--echo-args"]: echo $args
|
||||||
|
|
||||||
@ -423,7 +401,7 @@ Options:
|
|||||||
|
|
||||||
# Find and parse the .ptkrc file
|
# Find and parse the .ptkrc file
|
||||||
let ptkrcLocations = @[
|
let ptkrcLocations = @[
|
||||||
if args["--config"]: $args["<cfgFile>"] else:"",
|
if args["--config"]: $args["--config"] else:"",
|
||||||
".ptkrc", $getEnv("PTKRC"), $getEnv("HOME") & "/.ptkrc"]
|
".ptkrc", $getEnv("PTKRC"), $getEnv("HOME") & "/.ptkrc"]
|
||||||
|
|
||||||
var ptkrcFilename: string =
|
var ptkrcFilename: string =
|
||||||
@ -447,7 +425,7 @@ Options:
|
|||||||
|
|
||||||
# Find the time log file
|
# Find the time log file
|
||||||
let timelineLocations = @[
|
let timelineLocations = @[
|
||||||
if args["--file"]: $args["<file>"] else: "",
|
if args["--file"]: $args["--file"] else: "",
|
||||||
$getEnv("PTK_FILE"),
|
$getEnv("PTK_FILE"),
|
||||||
cfg["timelineLogFile"].getStr(""),
|
cfg["timelineLogFile"].getStr(""),
|
||||||
"ptk.log.json"]
|
"ptk.log.json"]
|
||||||
@ -494,7 +472,7 @@ Options:
|
|||||||
if args["stop"]:
|
if args["stop"]:
|
||||||
|
|
||||||
if timeline.marks.last.summary == STOP_MSG:
|
if timeline.marks.last.summary == STOP_MSG:
|
||||||
echo "no current task, nothing to stop"
|
echo "ptk: no current task, nothing to stop"
|
||||||
quit(0)
|
quit(0)
|
||||||
|
|
||||||
let newMark: Mark = (
|
let newMark: Mark = (
|
||||||
@ -509,14 +487,14 @@ Options:
|
|||||||
timeline.writeMarks(
|
timeline.writeMarks(
|
||||||
indices = @[timeline.marks.len - 2],
|
indices = @[timeline.marks.len - 2],
|
||||||
includeNotes = args["--verbose"])
|
includeNotes = args["--verbose"])
|
||||||
echo "stopped timer"
|
echo "ptk: stopped timer"
|
||||||
|
|
||||||
saveTimeline(timeline, timelineLocation)
|
saveTimeline(timeline, timelineLocation)
|
||||||
|
|
||||||
if args["continue"]:
|
if args["continue"]:
|
||||||
|
|
||||||
if timeline.marks.last.summary != STOP_MSG:
|
if timeline.marks.last.summary != STOP_MSG:
|
||||||
echo "There is already something in progress:"
|
echo "ptk: there is already something in progress:"
|
||||||
timeline.writeMarks(
|
timeline.writeMarks(
|
||||||
indices = @[timeline.marks.len - 1],
|
indices = @[timeline.marks.len - 1],
|
||||||
includeNotes = args["--verbose"])
|
includeNotes = args["--verbose"])
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "0.12.2"
|
version = "0.12.4"
|
||||||
author = "Jonathan Bernard"
|
author = "Jonathan Bernard"
|
||||||
description = "Personal Time Keeper"
|
description = "Personal Time Keeper"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
Reference in New Issue
Block a user