Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
57a3af4f2f | |||
08b9df2086 | |||
339e88cddd |
@ -1,6 +1,6 @@
|
||||
# Package
|
||||
|
||||
version = "4.8.0"
|
||||
version = "4.9.2"
|
||||
author = "Jonathan Bernard"
|
||||
description = "Personal issue tracker."
|
||||
license = "MIT"
|
||||
|
22
src/pit.nim
22
src/pit.nim
@ -2,10 +2,10 @@
|
||||
## ====================================
|
||||
|
||||
import cliutils, docopt, json, logging, options, os, sequtils,
|
||||
tables, terminal, times, timeutils, unicode, uuids
|
||||
std/wordwrap, tables, terminal, times, timeutils, unicode, uuids
|
||||
|
||||
from nre import re
|
||||
import strutils except capitalize, strip, toUpper, toLower
|
||||
import strutils except alignLeft, capitalize, strip, toUpper, toLower
|
||||
import pitpkg/private/libpit
|
||||
export libpit
|
||||
|
||||
@ -49,7 +49,7 @@ proc initContext(args: Table[string, Value]): CliContext =
|
||||
|
||||
proc getIssueContextDisplayName(ctx: CliContext, context: string): string =
|
||||
if not ctx.contexts.hasKey(context):
|
||||
if context.isNilOrWhitespace: return "<default>"
|
||||
if context.isEmptyOrWhitespace: return "<default>"
|
||||
else: return context.capitalize()
|
||||
return ctx.contexts[context]
|
||||
|
||||
@ -67,7 +67,7 @@ proc formatIssue(ctx: CliContext, issue: Issue): string =
|
||||
|
||||
|
||||
result &= "--------".withColor(fgBlack, true) & "\n"
|
||||
if not issue.details.isNilOrWhitespace:
|
||||
if not issue.details.isEmptyOrWhitespace:
|
||||
result &= issue.details.strip.withColor(fgCyan) & "\n"
|
||||
|
||||
proc formatSectionIssue(ctx: CliContext, issue: Issue, width: int, indent = "",
|
||||
@ -75,7 +75,7 @@ proc formatSectionIssue(ctx: CliContext, issue: Issue, width: int, indent = "",
|
||||
|
||||
result = ""
|
||||
|
||||
var showDetails = not issue.details.isNilOrWhitespace and verbose
|
||||
var showDetails = not issue.details.isEmptyOrWhitespace and verbose
|
||||
|
||||
var prefixLen = 0
|
||||
var summaryIndentLen = indent.len + 7
|
||||
@ -83,7 +83,7 @@ proc formatSectionIssue(ctx: CliContext, issue: Issue, width: int, indent = "",
|
||||
if issue.hasProp("delegated-to"): prefixLen += issue["delegated-to"].len + 2 # space for the ':' and ' '
|
||||
|
||||
# Wrap and write the summary.
|
||||
var wrappedSummary = ("+".repeat(prefixLen) & issue.summary).wordWrap(width - summaryIndentLen).indent(summaryIndentLen)
|
||||
var wrappedSummary = ("+".repeat(prefixLen) & issue.summary).wrapWords(width - summaryIndentLen).indent(summaryIndentLen)
|
||||
|
||||
wrappedSummary = wrappedSummary[(prefixLen + summaryIndentLen)..^1]
|
||||
|
||||
@ -103,7 +103,7 @@ proc formatSectionIssue(ctx: CliContext, issue: Issue, width: int, indent = "",
|
||||
|
||||
if issue.hasProp("pending"):
|
||||
let startIdx = "Pending: ".len
|
||||
var pendingText = issue["pending"].wordWrap(width - startIdx - summaryIndentLen)
|
||||
var pendingText = issue["pending"].wrapWords(width - startIdx - summaryIndentLen)
|
||||
.indent(startIdx)
|
||||
pendingText = ("Pending: " & pendingText[startIdx..^1]).indent(summaryIndentLen)
|
||||
result &= "\n" & pendingText.withColor(fgCyan)
|
||||
@ -490,7 +490,13 @@ Options:
|
||||
if issue.hasProp("context") and not uniqContexts.contains(issue["context"]):
|
||||
uniqContexts.add(issue["context"])
|
||||
|
||||
for c in uniqContexts: stdout.writeLine(c)
|
||||
let maxLen = foldl(uniqContexts,
|
||||
if a.len > b.len: a
|
||||
else: b
|
||||
).len
|
||||
|
||||
for c in uniqContexts:
|
||||
stdout.writeLine(c.alignLeft(maxLen+2) & ctx.getIssueContextDisplayName(c))
|
||||
|
||||
# List a specific issue
|
||||
elif issueIdOption.isSome:
|
||||
|
@ -1,4 +1,4 @@
|
||||
import cliutils, docopt, json, logging, langutils, options, os, ospaths,
|
||||
import cliutils, docopt, json, logging, langutils, options, os,
|
||||
sequtils, strutils, tables, times, timeutils, uuids
|
||||
|
||||
from nre import find, match, re, Regex
|
||||
@ -49,6 +49,7 @@ proc `[]`*(issue: Issue, key: string): string =
|
||||
proc `[]=`*(issue: Issue, key: string, value: string) =
|
||||
issue.properties[key] = value
|
||||
|
||||
## Issue property accessors
|
||||
proc hasProp*(issue: Issue, key: string): bool =
|
||||
return issue.properties.hasKey(key)
|
||||
|
||||
@ -62,6 +63,7 @@ proc getDateTime*(issue: Issue, key: string, default: DateTime): DateTime =
|
||||
proc setDateTime*(issue: Issue, key: string, dt: DateTime) =
|
||||
issue.properties[key] = dt.formatIso8601
|
||||
|
||||
## Issue filtering
|
||||
proc initFilter*(): IssueFilter =
|
||||
result = IssueFilter(
|
||||
completedRange: none(tuple[b, e: DateTime]),
|
||||
@ -120,7 +122,7 @@ proc fromStorageFormat*(id: string, issueTxt: string): Issue =
|
||||
|
||||
of ReadingProps:
|
||||
# Ignore empty lines
|
||||
if line.isNilOrWhitespace: continue
|
||||
if line.isEmptyOrWhitespace: continue
|
||||
|
||||
# Look for the sentinal to start parsing as detail lines
|
||||
if line == "--------":
|
||||
@ -147,9 +149,9 @@ proc toStorageFormat*(issue: Issue, withComments = false): string =
|
||||
lines.add(issue.summary)
|
||||
if withComments: lines.add("# Properties (\"key:value\" per line):")
|
||||
for key, val in issue.properties:
|
||||
if not val.isNilOrWhitespace: lines.add(key & ": " & val)
|
||||
if not val.isEmptyOrWhitespace: lines.add(key & ": " & val)
|
||||
if issue.tags.len > 0: lines.add("tags: " & issue.tags.join(","))
|
||||
if not isNilOrWhitespace(issue.details) or withComments:
|
||||
if not isEmptyOrWhitespace(issue.details) or withComments:
|
||||
if withComments: lines.add("# Details go below the \"--------\"")
|
||||
lines.add("--------")
|
||||
lines.add(issue.details)
|
||||
@ -168,6 +170,7 @@ proc loadIssueById*(tasksDir, id: string): Issue =
|
||||
raise newException(KeyError, "cannot find issue for id: " & id)
|
||||
|
||||
proc store*(issue: Issue, withComments = false) =
|
||||
discard existsOrCreateDir(issue.filePath.parentDir)
|
||||
writeFile(issue.filepath, toStorageFormat(issue, withComments))
|
||||
|
||||
proc store*(tasksDir: string, issue: Issue, state: IssueState, withComments = false) =
|
||||
@ -200,7 +203,7 @@ proc loadIssues*(path: string): seq[Issue] =
|
||||
toSeq(orderFile.lines)
|
||||
.mapIt(it.split(' ')[0])
|
||||
.deduplicate
|
||||
.filterIt(not it.startsWith("> ") and not it.isNilOrWhitespace)
|
||||
.filterIt(not it.startsWith("> ") and not it.isEmptyOrWhitespace)
|
||||
else: newSeq[string]()
|
||||
|
||||
type TaggedIssue = tuple[issue: Issue, ordered: bool]
|
||||
@ -267,7 +270,7 @@ proc loadConfig*(args: Table[string, Value] = initTable[string, Value]()): PitCo
|
||||
|
||||
if not existsFile(pitrcFilename):
|
||||
warn "pit: could not find .pitrc file: " & pitrcFilename
|
||||
if isNilOrWhitespace(pitrcFilename):
|
||||
if isEmptyOrWhitespace(pitrcFilename):
|
||||
pitrcFilename = $getEnv("HOME") & "/.pitrc"
|
||||
var cfgFile: File
|
||||
try:
|
||||
@ -293,7 +296,7 @@ proc loadConfig*(args: Table[string, Value] = initTable[string, Value]()): PitCo
|
||||
for k, v in cfgJson["contexts"]:
|
||||
result.contexts[k] = v.getStr()
|
||||
|
||||
if isNilOrWhitespace(result.tasksDir):
|
||||
if isEmptyOrWhitespace(result.tasksDir):
|
||||
raise newException(Exception, "no tasks directory configured")
|
||||
|
||||
if not existsDir(result.tasksDir):
|
||||
|
@ -1 +1 @@
|
||||
const PIT_VERSION* = "4.8.0"
|
||||
const PIT_VERSION* = "4.9.2"
|
Reference in New Issue
Block a user