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:
parent
8cf0bf5d98
commit
d04797460c
@ -1,6 +1,6 @@
|
|||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "4.24.1"
|
version = "4.25.0"
|
||||||
author = "Jonathan Bernard"
|
author = "Jonathan Bernard"
|
||||||
description = "Personal issue tracker."
|
description = "Personal issue tracker."
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
44
src/pit.nim
44
src/pit.nim
@ -70,6 +70,24 @@ proc formatIssue*(issue: Issue): string =
|
|||||||
|
|
||||||
result &= termReset
|
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*(
|
proc formatSectionIssue*(
|
||||||
issue: Issue,
|
issue: Issue,
|
||||||
width: int = 80,
|
width: int = 80,
|
||||||
@ -251,7 +269,15 @@ proc list(
|
|||||||
it.hasProp("completed") and
|
it.hasProp("completed") and
|
||||||
sameDay(getTime().local, it.getDateTime("completed")))
|
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"
|
trace "listing complete"
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -279,7 +305,13 @@ proc list(
|
|||||||
not (it.hasProp("hide-until") and
|
not (it.hasProp("hide-until") and
|
||||||
it.getDateTime("hide-until") > getTime().local))
|
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
|
# Future items
|
||||||
if future:
|
if future:
|
||||||
@ -296,7 +328,13 @@ proc list(
|
|||||||
not (it.hasProp("hide-until") and
|
not (it.hasProp("hide-until") and
|
||||||
it.getDateTime("hide-until") > getTime().local))
|
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"
|
trace "listing complete"
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const PIT_VERSION* = "4.24.1"
|
const PIT_VERSION* = "4.25.0"
|
||||||
|
|
||||||
const USAGE* = """Usage:
|
const USAGE* = """Usage:
|
||||||
pit ( new | add) <summary> [<state>] [options]
|
pit ( new | add) <summary> [<state>] [options]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user