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.
This commit is contained in:
Jonathan Bernard 2024-01-01 12:47:43 -06:00
parent 8cf0bf5d98
commit d04797460c
3 changed files with 43 additions and 5 deletions

View File

@ -1,6 +1,6 @@
# Package
version = "4.24.1"
version = "4.25.0"
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(stdin):
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(stdin):
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(stdin):
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.0"
const USAGE* = """Usage:
pit ( new | add) <summary> [<state>] [options]