Compare commits

..

4 Commits

Author SHA1 Message Date
0c3d73dc2b Add debug logging when changing the state of an issue. 2024-08-12 10:52:51 -05:00
9a0bf35882 Add asdf tool-versions definitions pinning this to Nim 1.6 2024-05-10 11:58:35 -05:00
be7c099b7b Format listed issues plainly when STDOUT is not a TTY 2024-01-01 12:55:01 -06:00
d04797460c Format listed issues plainly when STDIN is not a TTY
When calling pit from other programs or as part of a pipe, the display
style typically used to format listed issues contains a lot of unwanted
output (ANSI escape code, headings, etc.). Now when STDIN is not a TTY,
a plain and consistently formatted version of the issues is listed
without any additional formatting, one issue per line of output.
2024-01-01 12:47:43 -06:00
5 changed files with 49 additions and 5 deletions

1
.tool-versions Normal file
View File

@ -0,0 +1 @@
nim 1.6.20

View File

@ -1,6 +1,6 @@
# Package
version = "4.24.1"
version = "4.25.2"
author = "Jonathan Bernard"
description = "Personal issue tracker."
license = "MIT"

View File

@ -70,6 +70,24 @@ proc formatIssue*(issue: Issue): string =
result &= termReset
proc formatPlainIssueSummary*(issue: Issue): string =
result = "$#: $# $#" % [
$issue.state,
($issue.id)[0..<6],
issue.summary ]
if issue.hasProp("delegated-to") or issue.hasProp("pending"):
var parts = newSeq[string]()
if issue.hasProp("delegated-to"):
parts.add("delegated to " & issue["delegated-to"])
if issue.hasProp("pending"):
parts.add("pendin: " & issue["pending"])
result &= "($#)" % [ parts.join("; ") ]
proc formatSectionIssue*(
issue: Issue,
width: int = 80,
@ -251,7 +269,15 @@ proc list(
it.hasProp("completed") and
sameDay(getTime().local, it.getDateTime("completed")))
stdout.write ctx.formatSection(ctx.issues[state], state, "", verbose)
if isatty(stdout):
stdout.write ctx.formatSection(ctx.issues[state], state, "", verbose)
else:
stdout.writeLine ctx.issues[state]
.mapIt(formatPlainIssueSummary(it))
.join("\n")
trace "listing complete"
return
@ -279,7 +305,13 @@ proc list(
not (it.hasProp("hide-until") and
it.getDateTime("hide-until") > getTime().local))
stdout.write ctx.formatSection(visibleIssues, s, indent, verbose)
if isatty(stdout):
stdout.write ctx.formatSection(visibleIssues, s, indent, verbose)
else:
stdout.writeLine visibleIssues
.mapIt(formatPlainIssueSummary(it))
.join("\n")
# Future items
if future:
@ -296,7 +328,13 @@ proc list(
not (it.hasProp("hide-until") and
it.getDateTime("hide-until") > getTime().local))
stdout.write ctx.formatSection(visibleIssues, s, indent, verbose)
if isatty(stdout):
stdout.write ctx.formatSection(visibleIssues, s, indent, verbose)
else:
stdout.writeLine visibleIssues
.mapIt(formatPlainIssueSummary(it))
.join("\n")
trace "listing complete"

View File

@ -1,4 +1,4 @@
const PIT_VERSION* = "4.24.1"
const PIT_VERSION* = "4.25.2"
const USAGE* = """Usage:
pit ( new | add) <summary> [<state>] [options]

View File

@ -328,11 +328,16 @@ proc loadAllIssues*(tasksDir: string): TableRef[IssueState, seq[Issue]] =
for state in IssueState: result[state] = tasksDir.loadIssues(state)
proc changeState*(issue: Issue, tasksDir: string, newState: IssueState) =
var dbgInfo = "[$#] changing state: $#$#" %
[ ($issue.id)[0..<6], $issue.state, $newState ]
let oldFilepath = issue.filepath
if newState == Done: issue.setDateTime("completed", getTime().local)
tasksDir.store(issue, newState)
if oldFilePath != issue.filepath: removeFile(oldFilepath)
dbgInfo &= "\n\told path: $#\n\tnew path: $#" % [oldFilePath, issue.filepath]
issue.state = newState
debug dbgInfo
proc delete*(issue: Issue) = removeFile(issue.filepath)