Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ec1198dcf0 | |||
| 2ed12e7487 | |||
| a273091dc7 |
+1
-1
@@ -1,2 +1,2 @@
|
||||
[tools]
|
||||
nim = "2.2.6"
|
||||
nim = "2.2.8"
|
||||
|
||||
+11
-14
@@ -1,6 +1,6 @@
|
||||
# Package
|
||||
|
||||
version = "4.33.0"
|
||||
version = "4.33.3"
|
||||
author = "Jonathan Bernard"
|
||||
description = "Personal issue tracker."
|
||||
license = "MIT"
|
||||
@@ -10,21 +10,18 @@ bin = @["pit"]
|
||||
|
||||
# Dependencies
|
||||
|
||||
requires @[
|
||||
"nim >= 1.4.0",
|
||||
"docopt >= 0.7.1",
|
||||
"uuids >= 0.1.10",
|
||||
"zero_functional"
|
||||
]
|
||||
requires "nim >= 1.6.0"
|
||||
requires "docopt >= 0.7.1"
|
||||
requires "regex >= 0.26.3"
|
||||
requires "uuids >= 0.1.10"
|
||||
requires "zero_functional"
|
||||
|
||||
# Dependencies from git.jdb-software.com/jdb/nim-packages
|
||||
requires @[
|
||||
"cliutils >= 0.10.2",
|
||||
"langutils >= 0.4.0",
|
||||
"timeutils >= 0.5.4",
|
||||
"data_uri > 1.0.0",
|
||||
"update_nim_package_version >= 0.2.0"
|
||||
]
|
||||
requires "cliutils >= 0.11.1"
|
||||
requires "langutils >= 0.4.0"
|
||||
requires "timeutils >= 0.5.4"
|
||||
requires "filetype >= 0.9.0"
|
||||
requires "update_nim_package_version >= 0.2.0"
|
||||
|
||||
task updateVersion, "Update the version of this package.":
|
||||
exec "update_nim_package_version pit 'src/pit/cliconstants.nim'"
|
||||
+13
-12
@@ -1,13 +1,14 @@
|
||||
## Personal Issue Tracker CLI interface
|
||||
## ====================================
|
||||
|
||||
import std/[algorithm, logging, options, os, sequtils, sets, tables, terminal,
|
||||
times, unicode]
|
||||
import cliutils, data_uri, docopt, json, timeutils, uuids, zero_functional
|
||||
import std/[algorithm, logging, options, os, sequtils, sets, tables, times,
|
||||
unicode]
|
||||
import docopt, json, timeutils, uuids, zero_functional
|
||||
|
||||
from nre import match, re
|
||||
from regex import match, re2
|
||||
import strutils except alignLeft, capitalize, strip, toUpper, toLower
|
||||
import pit/[cliconstants, formatting, libpit, projects, sync_pbm_vsb]
|
||||
import pit/[ansiterm, cliconstants, data_uri, formatting, libpit, projects,
|
||||
sync_pbm_vsb]
|
||||
|
||||
export formatting, libpit
|
||||
|
||||
@@ -73,7 +74,7 @@ proc addIssue(
|
||||
if issueProps.hasKey("context"):
|
||||
ctx.filterIssues(propsFilter(newTable({"context": issueProps["context"]})))
|
||||
|
||||
let numberRegex = re("^[0-9]+$")
|
||||
let numberRegex = re2("^[0-9]+$")
|
||||
for propName in defaultProps:
|
||||
if not issueProps.hasKey(propName):
|
||||
let allIssues: seq[seq[Issue]] = toSeq(values(ctx.issues))
|
||||
@@ -92,13 +93,13 @@ proc addIssue(
|
||||
"Do you want to set a value for '" & propName & "'? " &
|
||||
"You can use the numbers above to use an existing value, enter " &
|
||||
"something new, or leave blank to indicate no value.\p" &
|
||||
withColor(propName, fgMagenta) & ":" &
|
||||
withColor(" ", fgBlue, bright=true, skipReset=true))
|
||||
color(propName, fg=cMagenta) & ":" &
|
||||
ansiEscSeq(fg=cBrightBlue) & " ")
|
||||
|
||||
let resp = stdin.readLine.strip
|
||||
let numberResp = resp.match(numberRegex)
|
||||
|
||||
if numberResp.isSome:
|
||||
if numberResp:
|
||||
let idx = parseInt(resp)
|
||||
if idx >= 0 and idx < previousValues.len:
|
||||
issueProps[propName] = previousValues[idx]
|
||||
@@ -106,7 +107,7 @@ proc addIssue(
|
||||
elif resp.len > 0:
|
||||
issueProps[propName] = resp
|
||||
|
||||
stdout.writeLine(termReset)
|
||||
stdout.writeLine(RESET_FORMATTING)
|
||||
|
||||
result = Issue(
|
||||
id: genUUID(),
|
||||
@@ -211,10 +212,10 @@ when isMainModule:
|
||||
|
||||
# If they supplied text matches, add that to the filter.
|
||||
if args["--match"]:
|
||||
filter.summaryMatch = some(re("(?i)" & $args["--match"]))
|
||||
filter.summaryMatch = some(re2("(?i)" & $args["--match"]))
|
||||
|
||||
if args["--match-all"]:
|
||||
filter.fullMatch = some(re("(?i)" & $args["--match-all"]))
|
||||
filter.fullMatch = some(re2("(?i)" & $args["--match-all"]))
|
||||
|
||||
# If no "context" property is given, use the default (if we have one)
|
||||
if ctx.defaultContext.isSome and not filter.properties.hasKey("context"):
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
import std/[sequtils, strutils]
|
||||
|
||||
const CSI = "\x1b["
|
||||
const RESET_FORMATTING* = "\x1b[0m"
|
||||
|
||||
type
|
||||
TrueColor* = tuple[r, g, b: int]
|
||||
|
||||
TerminalColors* = enum
|
||||
cBlack = 0, cRed, cGreen, cYellow, cBlue, cMagenta, cCyan, cWhite,
|
||||
cDefault = 9
|
||||
|
||||
cBrightBlack = 60, cBrightRed, cBrightGreen, cBrightYellow, cBrightBlue,
|
||||
cBrightMagenta, cBrightCyan, cBrightWhite
|
||||
|
||||
TerminalStyle* = enum
|
||||
tsBold = 1, tsDim, tsItalic, tsUnderline, tsBlink, tsInverse, tsHidden,
|
||||
tsStrikethrough
|
||||
|
||||
func isAnsiTerminator(c: char): bool =
|
||||
c in {'A'..'Z'} or c in {'a'..'z'}
|
||||
|
||||
proc stripAnsi*(text: string): string =
|
||||
var i = 0
|
||||
while i < text.len:
|
||||
if i + 1 < text.len and text[i] == '\x1b' and text[i + 1] == '[':
|
||||
i += 2
|
||||
while i < text.len and not text[i].isAnsiTerminator:
|
||||
inc i
|
||||
if i < text.len:
|
||||
inc i
|
||||
else:
|
||||
result.add(text[i])
|
||||
inc i
|
||||
|
||||
func ansiEscSeq*(style: set[TerminalStyle]): string =
|
||||
CSI & toSeq(style).mapIt($int(it)).join(";") & "m"
|
||||
|
||||
func ansiEscSeq*(fg: int): string = CSI & "38;5;" & $fg & "m"
|
||||
func ansiEscSeq*(bg: int): string = CSI & "48;5;" & $bg & "m"
|
||||
|
||||
func ansiEscSeq*(fg: TrueColor): string =
|
||||
"$#38;2;$#;$#;$#m" % [CSI, $fg.r, $fg.g, $fg.b]
|
||||
|
||||
func ansiEscSeq*(bg: TrueColor): string =
|
||||
"$#48;2;$#;$#;$#m" % [CSI, $bg.r, $bg.g, $bg.b]
|
||||
|
||||
func ansiEscSeq*(fg: TerminalColors): string = CSI & $(int(fg) + 30) & "m"
|
||||
func ansiEscSeq*(bg: TerminalColors): string = CSI & $(int(bg) + 40) & "m"
|
||||
|
||||
func ansiEscSeq*(
|
||||
fg: TerminalColors,
|
||||
bg: TerminalColors,
|
||||
style: set[TerminalStyle]): string =
|
||||
result = CSI
|
||||
if style != {}:
|
||||
result &= toSeq(style).mapIt($int(it)).join(";") & ";"
|
||||
result &= $(int(fg) + 30) & ";" & $(int(bg) + 40) & "m"
|
||||
|
||||
func termFmt*(
|
||||
text: string,
|
||||
fg = cDefault,
|
||||
bg = cDefault,
|
||||
style: set[TerminalStyle] = {}): string =
|
||||
ansiEscSeq(fg, bg, style) & text & RESET_FORMATTING
|
||||
|
||||
func termFmt*[C: int | TrueColor](
|
||||
text: string,
|
||||
fg, bg: C,
|
||||
style: set[TerminalStyle] = {}): string =
|
||||
ansiEscSeq(style) & ansiEscSeq(fg = fg) & ansiEscSeq(bg = bg) &
|
||||
text & RESET_FORMATTING
|
||||
|
||||
func color*(text: string, fg = cDefault, bg = cDefault): string =
|
||||
termFmt(text, fg, bg, {})
|
||||
@@ -1,4 +1,4 @@
|
||||
const PIT_VERSION* = "4.33.0"
|
||||
const PIT_VERSION* = "4.33.3"
|
||||
|
||||
const USAGE* = """Usage:
|
||||
pit ( new | add) <summary> [<state>] [options]
|
||||
@@ -71,10 +71,10 @@ Options:
|
||||
properties set.
|
||||
|
||||
-m, --match <pattern> Limit to issues whose summaries match the given
|
||||
pattern (PCRE regex supported).
|
||||
pattern (regex syntax supported).
|
||||
|
||||
-M, --match-all <pat> Limit to the issues whose summaries or details
|
||||
match the given pattern (PCRE regex supported).
|
||||
match the given pattern (regex syntax supported).
|
||||
|
||||
-v, --verbose Show issue details when listing issues.
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import std/[base64, strutils]
|
||||
|
||||
import filetype
|
||||
|
||||
proc encodeAsDataUri*(value: string, mimeType: string = ""): string =
|
||||
let actualMimeType =
|
||||
if mimeType.isEmptyOrWhitespace: filetype.match(cast[seq[byte]](value)).mime.value
|
||||
else: mimeType
|
||||
|
||||
"data:" & actualMimeType & ";base64," & encode(value)
|
||||
|
||||
proc decodeDataUri*(dataUri: string): string =
|
||||
if not dataUri.startsWith("data:"):
|
||||
raise newException(Exception, "input does not look like a valid data URI")
|
||||
|
||||
let commaIdx = dataUri.find(',')
|
||||
if commaIdx < 0:
|
||||
raise newException(Exception, "input does not look like a valid data URI")
|
||||
|
||||
decode(dataUri[commaIdx + 1..^1])
|
||||
+32
-30
@@ -1,41 +1,42 @@
|
||||
import std/[options, sequtils, tables, terminal, times, unicode, wordwrap]
|
||||
import cliutils, uuids
|
||||
import uuids
|
||||
import std/strutils except alignLeft, capitalize, strip, toLower, toUpper
|
||||
import ./ansiterm
|
||||
import ./libpit
|
||||
|
||||
proc adjustedTerminalWidth(): int = min(terminalWidth(), 80)
|
||||
|
||||
proc formatIssue*(issue: Issue): string =
|
||||
result = ($issue.id).withColor(fgBlack, true) & "\n"&
|
||||
issue.summary.withColor(fgWhite) & "\n"
|
||||
result = ($issue.id).color(cBrightBlack) & "\n"&
|
||||
issue.summary.color(cWhite) & "\n"
|
||||
|
||||
if issue.tags.len > 0:
|
||||
result &= "tags: ".withColor(fgMagenta) &
|
||||
issue.tags.join(",").withColor(fgGreen, true) & "\n"
|
||||
result &= "tags: ".color(cMagenta) &
|
||||
issue.tags.join(",").color(cBrightGreen) & "\n"
|
||||
|
||||
if issue.properties.len > 0:
|
||||
for k, v in issue.properties:
|
||||
|
||||
if k == "project":
|
||||
result &= "project: ".withColor(fgMagenta) &
|
||||
v.withColor(fgBlue, bright = true) & "\n"
|
||||
result &= "project: ".color(cMagenta) &
|
||||
v.color(cBrightBlue) & "\n"
|
||||
|
||||
elif k == "milestone":
|
||||
result &= "milestone: ".withColor(fgMagenta) &
|
||||
v.withColor(fgBlue, bright = true) & "\n"
|
||||
result &= "milestone: ".color(cMagenta) &
|
||||
v.color(cBrightBlue) & "\n"
|
||||
|
||||
elif k == "priority":
|
||||
result &= "priority: ".withColor(fgMagenta) &
|
||||
v.withColor(fgRed, bright = true) & "\n"
|
||||
result &= "priority: ".color(cMagenta) &
|
||||
v.color(cBrightRed) & "\n"
|
||||
|
||||
else:
|
||||
result &= termColor(fgMagenta) & k & ": " & v & "\n"
|
||||
result &= ansiEscSeq(fg = cMagenta) & k & ": " & v & "\n"
|
||||
|
||||
result &= "--------".withColor(fgBlack, true) & "\n"
|
||||
result &= "--------".color(cBrightBlack) & "\n"
|
||||
if not issue.details.isEmptyOrWhitespace:
|
||||
result &= issue.details.strip.withColor(fgCyan) & "\n"
|
||||
result &= issue.details.strip.color(cCyan) & "\n"
|
||||
|
||||
result &= termReset
|
||||
result &= RESET_FORMATTING
|
||||
|
||||
|
||||
proc formatPlainIssueSummary*(issue: Issue): string =
|
||||
@@ -64,7 +65,7 @@ proc formatSectionIssue*(
|
||||
verbose = false,
|
||||
bold = false): string =
|
||||
|
||||
result = (indent & ($issue.id)[0..<6]).withColor(fgBlack, true) & " "
|
||||
result = (indent & ($issue.id)[0..<6]).color(cBrightBlack) & " "
|
||||
|
||||
let showDetails = not issue.details.isEmptyOrWhitespace and verbose
|
||||
|
||||
@@ -75,7 +76,8 @@ proc formatSectionIssue*(
|
||||
.wrapWords(summaryWidth)
|
||||
.splitLines
|
||||
|
||||
result &= summaryLines[0].termFmt(fgWhite, bold=bold, underline=bold)
|
||||
result &= summaryLines[0].termFmt(fg=cWhite, bg=cDefault,
|
||||
style = if bold: { tsBold, tsUnderline } else: {})
|
||||
|
||||
for line in summaryLines[1..^1]:
|
||||
result &= "\p" & line.indent(summaryIndentLen)
|
||||
@@ -84,11 +86,11 @@ proc formatSectionIssue*(
|
||||
|
||||
if issue.hasProp("delegated-to"):
|
||||
if lastLineLen + issue["delegated-to"].len + 1 < summaryWidth:
|
||||
result &= " " & issue["delegated-to"].withColor(fgMagenta)
|
||||
result &= " " & issue["delegated-to"].color(cMagenta)
|
||||
lastLineLen += issue["delegated-to"].len + 1
|
||||
else:
|
||||
result &= "\p" & issue["delegated-to"]
|
||||
.withColor(fgMagenta)
|
||||
.color(cMagenta)
|
||||
.indent(summaryIndentLen)
|
||||
lastLineLen = issue["delegated-to"].len
|
||||
|
||||
@@ -99,28 +101,28 @@ proc formatSectionIssue*(
|
||||
|
||||
if tagsStrLines.len == 1 and
|
||||
(lastLineLen + tagsStrLines[0].len + 1) < summaryWidth:
|
||||
result &= " " & tagsStrLines[0].withColor(fgGreen)
|
||||
result &= " " & tagsStrLines[0].color(cGreen)
|
||||
lastLineLen += tagsStrLines[0].len + 1
|
||||
else:
|
||||
result &= "\p" & tagsStrLines
|
||||
.mapIt(it.indent(summaryIndentLen))
|
||||
.join("\p")
|
||||
.withColor(fgGreen)
|
||||
.color(cGreen)
|
||||
lastLineLen = tagsStrLines[^1].len
|
||||
|
||||
if issue.hasProp("pending"):
|
||||
result &= "\p" & ("Pending: " & issue["pending"])
|
||||
.wrapwords(summaryWidth)
|
||||
.withColor(fgCyan)
|
||||
.color(cCyan)
|
||||
.indent(summaryIndentLen)
|
||||
|
||||
if showDetails:
|
||||
result &= "\p" & issue.details
|
||||
.strip
|
||||
.withColor(fgBlack, bright = true)
|
||||
.color(cBrightBlack)
|
||||
.indent(summaryIndentLen)
|
||||
|
||||
result &= termReset
|
||||
result &= RESET_FORMATTING
|
||||
|
||||
|
||||
proc formatSectionIssueList*(
|
||||
@@ -139,19 +141,19 @@ proc formatSection(ctx: CliContext, issues: seq[Issue], state: IssueState,
|
||||
indent = "", verbose = false): string =
|
||||
let innerWidth = adjustedTerminalWidth() - (indent.len * 2)
|
||||
|
||||
result = termColor(fgBlue) &
|
||||
result = ansiEscSeq(fg = cBlue) &
|
||||
(indent & ".".repeat(innerWidth)) & "\n" &
|
||||
state.displayName.center(adjustedTerminalWidth()) & "\n\n" &
|
||||
termReset
|
||||
RESET_FORMATTING
|
||||
|
||||
let issuesByContext = issues.groupBy("context")
|
||||
|
||||
if issues.len > 5 and issuesByContext.len > 1:
|
||||
for context, ctxIssues in issuesByContext:
|
||||
|
||||
result &= termColor(fgYellow) &
|
||||
result &= ansiEscSeq(fg = cYellow) &
|
||||
indent & ctx.getIssueContextDisplayName(context) & ":" &
|
||||
termReset & "\n\n"
|
||||
RESET_FORMATTING & "\n\n"
|
||||
|
||||
result &= formatSectionIssueList(ctxIssues, innerWidth - 2, indent & " ", verbose)
|
||||
result &= "\n"
|
||||
@@ -160,11 +162,11 @@ proc formatSection(ctx: CliContext, issues: seq[Issue], state: IssueState,
|
||||
|
||||
|
||||
proc writeHeader*(ctx: CliContext, header: string) =
|
||||
stdout.setForegroundColor(fgRed, true)
|
||||
stdout.write(ansiEscSeq(fg = cBrightRed))
|
||||
stdout.writeLine('_'.repeat(adjustedTerminalWidth()))
|
||||
stdout.writeLine(header.center(adjustedTerminalWidth()))
|
||||
stdout.writeLine('~'.repeat(adjustedTerminalWidth()))
|
||||
stdout.resetAttributes
|
||||
stdout.write(RESET_FORMATTING)
|
||||
|
||||
|
||||
proc list*(
|
||||
|
||||
+24
-19
@@ -1,8 +1,8 @@
|
||||
import std/[json, logging, options, os, strformat, strutils, tables, times,
|
||||
unicode]
|
||||
import cliutils, docopt, langutils, uuids, zero_functional
|
||||
import cliutils/config, docopt, langutils, uuids, zero_functional
|
||||
|
||||
import nre except toSeq
|
||||
import regex
|
||||
import timeutils except `>`
|
||||
from sequtils import deduplicate, toSeq
|
||||
|
||||
@@ -25,7 +25,7 @@ type
|
||||
|
||||
IssueFilter* = ref object
|
||||
completedRange*: Option[tuple[b, e: DateTime]]
|
||||
fullMatch*, summaryMatch*: Option[Regex]
|
||||
fullMatch*, summaryMatch*: Option[Regex2]
|
||||
inclStates*: seq[IssueState]
|
||||
exclStates*: seq[IssueState]
|
||||
hasTags*: seq[string]
|
||||
@@ -61,8 +61,8 @@ const MATCH_ANY* = "<match-any>"
|
||||
const DONE_FOLDER_FORMAT* = "yyyy-MM"
|
||||
const ISO8601_MS = "yyyy-MM-dd'T'HH:mm:ss'.'fffzzz"
|
||||
|
||||
let ISSUE_FILE_PATTERN = re"[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}\.txt"
|
||||
let RECURRENCE_PATTERN = re"(every|after) ((\d+) )?((hour|day|week|month|year)s?)(, ([0-9a-fA-F]+))?"
|
||||
let ISSUE_FILE_PATTERN = re2"[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}\.txt"
|
||||
let RECURRENCE_PATTERN = re2"(every|after) ((\d+) )?((hour|day|week|month|year)s?)(, ([0-9a-fA-F]+))?"
|
||||
|
||||
let traceStartTime = cpuTime()
|
||||
var lastTraceTime = traceStartTime
|
||||
@@ -116,26 +116,31 @@ proc setDateTime*(issue: Issue, key: string, dt: DateTime) =
|
||||
proc getRecurrence*(issue: Issue): Option[Recurrence] =
|
||||
if not issue.hasProp("recurrence"): return none[Recurrence]()
|
||||
|
||||
let m = issue["recurrence"].match(RECURRENCE_PATTERN)
|
||||
let recurrence = issue["recurrence"]
|
||||
var m = RegexMatch2()
|
||||
|
||||
if not m.isSome:
|
||||
if not recurrence.match(RECURRENCE_PATTERN, m):
|
||||
warn "not a valid recurrence value: '" & issue["recurrence"] & "'"
|
||||
return none[Recurrence]()
|
||||
|
||||
let c = nre.toSeq(m.get.captures)
|
||||
let timeVal = if c[2].isSome: c[2].get.parseInt
|
||||
proc captured(i: int): Option[string] =
|
||||
let bounds = m.group(i)
|
||||
if bounds == reNonCapture: none(string)
|
||||
else: some(recurrence[bounds])
|
||||
|
||||
let timeVal = if captured(2).isSome: captured(2).get.parseInt
|
||||
else: 1
|
||||
return some(Recurrence(
|
||||
isFromCompletion: c[0].get == "after",
|
||||
isFromCompletion: captured(0).get == "after",
|
||||
interval:
|
||||
case c[4].get:
|
||||
case captured(4).get:
|
||||
of "hour": hours(timeVal)
|
||||
of "day": days(timeVal)
|
||||
of "week": weeks(timeVal)
|
||||
of "month": months(timeVal)
|
||||
of "year": years(timeVal)
|
||||
else: weeks(1),
|
||||
cloneId: c[6]))
|
||||
cloneId: captured(6)))
|
||||
|
||||
proc setPriority*(issue: Issue, priority: IssuePriority) =
|
||||
issue["priority"] = $priority
|
||||
@@ -149,8 +154,8 @@ proc getPriority*(issue: Issue): IssuePriority =
|
||||
proc initFilter*(): IssueFilter =
|
||||
result = IssueFilter(
|
||||
completedRange: none(tuple[b, e: DateTime]),
|
||||
fullMatch: none(Regex),
|
||||
summaryMatch: none(Regex),
|
||||
fullMatch: none(Regex2),
|
||||
summaryMatch: none(Regex2),
|
||||
inclStates: @[],
|
||||
exclStates: @[],
|
||||
exclHidden: true,
|
||||
@@ -173,11 +178,11 @@ proc dateFilter*(range: tuple[b, e: DateTime]): IssueFilter =
|
||||
|
||||
proc summaryMatchFilter*(pattern: string): IssueFilter =
|
||||
result = initFilter()
|
||||
result.summaryMatch = some(re("(?i)" & pattern))
|
||||
result.summaryMatch = some(re2("(?i)" & pattern))
|
||||
|
||||
proc fullMatchFilter*(pattern: string): IssueFilter =
|
||||
result = initFilter()
|
||||
result.fullMatch = some(re("(?i)" & pattern))
|
||||
result.fullMatch = some(re2("(?i)" & pattern))
|
||||
|
||||
proc hasTagsFilter*(tags: seq[string]): IssueFilter =
|
||||
result = initFilter()
|
||||
@@ -344,7 +349,7 @@ proc loadIssues*(path: string): seq[Issue] =
|
||||
var unorderedIssues: seq[TaggedIssue] = @[]
|
||||
|
||||
for path in walkDirRec(path):
|
||||
if extractFilename(path).match(ISSUE_FILE_PATTERN).isSome():
|
||||
if extractFilename(path).match(ISSUE_FILE_PATTERN):
|
||||
unorderedIssues.add((loadIssue(path), false))
|
||||
|
||||
trace "loaded " & $unorderedIssues.len & " issues", true
|
||||
@@ -451,12 +456,12 @@ proc filter*(issues: seq[Issue], filter: IssueFilter): seq[Issue] =
|
||||
|
||||
if filter.summaryMatch.isSome:
|
||||
let p = filter.summaryMatch.get
|
||||
f = f --> filter(it.summary.find(p).isSome)
|
||||
f = f --> filter(it.summary.contains(p))
|
||||
|
||||
if filter.fullMatch.isSome:
|
||||
let p = filter.fullMatch.get
|
||||
f = f -->
|
||||
filter(it.summary.find(p).isSome or it.details.find(p).isSome)
|
||||
filter(it.summary.contains(p) or it.details.contains(p))
|
||||
|
||||
for tagLent in filter.hasTags:
|
||||
let tag = tagLent
|
||||
|
||||
+31
-30
@@ -1,8 +1,8 @@
|
||||
import std/[algorithm, json, jsonutils, options, os, sets, strutils, tables,
|
||||
terminal, times, unicode]
|
||||
from std/sequtils import repeat, toSeq
|
||||
import cliutils, uuids, zero_functional
|
||||
import ./[formatting, libpit]
|
||||
import uuids, zero_functional
|
||||
import ./[ansiterm, formatting, libpit]
|
||||
|
||||
const NO_PROJECT* = "∅ No Project"
|
||||
const NO_MILESTONE* = "∅ No Milestone"
|
||||
@@ -152,9 +152,9 @@ proc listProjects*(ctx: CliContext, filter = none[IssueFilter]()) =
|
||||
|
||||
for (context, projects) in pairs(projectsByContext):
|
||||
|
||||
linesToPrint.add(withColor(
|
||||
linesToPrint.add(termFmt(
|
||||
ctx.getIssueContextDisplayName(context) & ":",
|
||||
fgYellow) & termReset)
|
||||
fg=cYellow))
|
||||
linesToPrint.add("")
|
||||
|
||||
var toList = toHashSet(toSeq(keys(projects)))
|
||||
@@ -203,10 +203,10 @@ proc listMilestones*(ctx: CliContext, filter = none[IssueFilter]()) =
|
||||
if values(project.milestones) --> all(it.len == 0):
|
||||
continue
|
||||
|
||||
linesToPrint.add(withColor(project.name, fgBlue, bold = true, bright=true))
|
||||
linesToPrint.add(withColor(
|
||||
linesToPrint.add(termFmt(project.name, cBrightBlue, style = { tsBold }))
|
||||
linesToPrint.add(termFmt(
|
||||
"─".repeat(runeLen(stripAnsi(project.name))),
|
||||
fgBlue, bold = true))
|
||||
cBrightBlue, style = { tsBold} ))
|
||||
|
||||
for milestone in project.milestoneOrder:
|
||||
if project.milestones.hasKey(milestone) and
|
||||
@@ -229,31 +229,31 @@ proc formatProjectIssue(
|
||||
|
||||
var firstLine = ""
|
||||
if issue.state == IssueState.Done:
|
||||
firstLine &= withColor(" ✔ ", fgBlack, bold=true, bright=true)
|
||||
firstLine &= termFmt(" ✔ ", fg = cBrightBlack, style = { tsBold })
|
||||
else:
|
||||
case issue.getPriority
|
||||
of IssuePriority.essential:
|
||||
firstLine &= withColor("❶ ", fgRed, bold=true, bright=true)
|
||||
firstLine &= termFmt("❶ ", fg=cBrightRed, style={ tsBold })
|
||||
of IssuePriority.vital:
|
||||
firstLine &= withColor("❷ ", fgYellow, bold=true, bright=true)
|
||||
firstLine &= termFmt("❷ ", fg=cBrightYellow, style={ tsBold })
|
||||
of IssuePriority.important:
|
||||
firstLine &= withColor("❸ ", fgBlue, bold=true, bright=true)
|
||||
firstLine &= termFmt("❸ ", fg=cBrightBlue, style={ tsBold })
|
||||
of IssuePriority.optional:
|
||||
firstLine &= withColor("❹ ", fgBlack, bold=false, bright=true)
|
||||
firstLine &= termFmt("❹ ", fg=cBrightBlack)
|
||||
|
||||
let summaryText = formatSectionIssue(issue, width - 3,
|
||||
bold = [Current, TodoToday].contains(issue.state)).splitLines
|
||||
firstLine &= summaryText[0]
|
||||
|
||||
if issue.state == IssueState.Done:
|
||||
firstLine = withColor(stripAnsi(firstLine), fgBlack, bright=true)
|
||||
firstLine = termFmt(stripAnsi(firstLine), fg=cBrightBlack)
|
||||
|
||||
result.add(firstLine)
|
||||
result.add(summaryText[1 .. ^1] --> map(" " & it))
|
||||
|
||||
if issue.state == IssueState.Done:
|
||||
let origLines = result
|
||||
result = origLines --> map(withColor(stripAnsi(it), fgBlack, bright=true))
|
||||
result = origLines --> map(termFmt(stripAnsi(it), fg = cBrightBlack))
|
||||
|
||||
proc formatParentIssue*(
|
||||
ctx: CliContext,
|
||||
@@ -265,7 +265,7 @@ proc formatParentIssue*(
|
||||
|
||||
for child in sorted(children, cmp):
|
||||
let childLines = ctx.formatProjectIssue(child, width - 3)
|
||||
result.add(childLines --> map(withColor(" │ ", fgBlack, bright=true) & it))
|
||||
result.add(childLines --> map(termFmt(" │ ", fg=cBrightBlack) & it))
|
||||
|
||||
result.add("")
|
||||
|
||||
@@ -277,8 +277,8 @@ proc formatMilestone*(
|
||||
availWidth: int): seq[string] =
|
||||
|
||||
result = @[""]
|
||||
result.add(withColor(milestone, fgWhite, bold=true))
|
||||
result.add(withColor("─".repeat(availWidth), fgWhite))
|
||||
result.add(termFmt(milestone, fg=cWhite, style={tsBold}))
|
||||
result.add(termFmt("─".repeat(availWidth), fg=cWhite))
|
||||
|
||||
var parentsToChildren = issues -->
|
||||
filter(it.hasProp("parent")).group(it["parent"])
|
||||
@@ -327,18 +327,19 @@ proc showProject*(ctx: CliContext, project: Project) =
|
||||
let numColumns = (fullWidth - 4) div (columnWidth + 2)
|
||||
|
||||
linesToPrint.add("")
|
||||
linesToPrint.add(withColor(
|
||||
linesToPrint.add(termFmt(
|
||||
"┌" & "─".repeat(project.name.runeLen + 2) &
|
||||
"┬" & "─".repeat(fullWidth - project.name.runeLen - 4) & "┐",
|
||||
fgBlue, bold=true))
|
||||
fg=cBlue, style={tsBold}))
|
||||
linesToPrint.add(
|
||||
withColor("│ ", fgBlue, bold=true) &
|
||||
withColor(project.name, fgBlue, bold=true, bright=true) &
|
||||
withColor(" │" & " ".repeat(fullWidth - project.name.runeLen - 4) & "│", fgBlue, bold=true))
|
||||
linesToPrint.add(withColor(
|
||||
termFmt("│ ", fg=cBlue, style={tsBold}) &
|
||||
termFmt(project.name, fg=cBrightBlue, style={tsBold}) &
|
||||
termFmt(" │" & " ".repeat(fullWidth - project.name.runeLen - 4) & "│",
|
||||
fg=cBlue, style={tsBold}))
|
||||
linesToPrint.add(termFmt(
|
||||
"├" & "─".repeat(project.name.runeLen + 2) &
|
||||
"┘" & " ".repeat(fullWidth - project.name.runeLen - 4) & "│",
|
||||
fgBlue, bold=true))
|
||||
fg=cBlue, style={tsBold}))
|
||||
|
||||
let milestoneTexts: seq[seq[string]] = project.milestoneOrder -->
|
||||
filter(project.milestones.hasKey(it) and project.milestones[it].len > 0).
|
||||
@@ -355,14 +356,14 @@ proc showProject*(ctx: CliContext, project: Project) =
|
||||
for line in joinedLines:
|
||||
let padLen = fullWidth - runeLen(stripAnsi(line)) - 3
|
||||
linesToPrint.add(
|
||||
withColor("│ ", fgBlue) &
|
||||
termFmt("│ ", fg=cBlue) &
|
||||
line &
|
||||
" ".repeat(padLen) &
|
||||
withColor(" │", fgBlue))
|
||||
termFmt(" │", fg=cBlue))
|
||||
|
||||
linesToPrint.add(withColor(
|
||||
linesToPrint.add(termFmt(
|
||||
"└" & "─".repeat(terminalWidth() - 2) & "┘",
|
||||
fgBlue, bold=true))
|
||||
fg=cBlue, style={tsBold}))
|
||||
|
||||
if isatty(stdout):
|
||||
stdout.writeLine(linesToPrint.join("\p"))
|
||||
@@ -389,9 +390,9 @@ proc showProjectBoard*(ctx: CliContext, filter = none[IssueFilter]()) =
|
||||
for (context, projects) in contextsAndProjects:
|
||||
if contextsAndProjects.len > 1:
|
||||
stdout.writeLine("")
|
||||
stdout.writeLine(withColor(
|
||||
stdout.writeLine(termFmt(
|
||||
ctx.getIssueContextDisplayName(context) & ":",
|
||||
fgYellow, bold=true))
|
||||
fg=cYellow, style={tsBold}))
|
||||
stdout.writeLine("")
|
||||
|
||||
for p in projects:
|
||||
|
||||
+13
-2
@@ -7,9 +7,10 @@
|
||||
# libpit directly rather than calling the pit cli executable. Unfortunately
|
||||
# this would require a non-trivial rewrite.
|
||||
|
||||
import asyncdispatch, cliutils, docopt, jester, json, logging, options, sequtils, strutils
|
||||
import nre except toSeq
|
||||
import asyncdispatch, docopt, jester, json, logging, options, sequtils, strutils
|
||||
import cliutils/procutil
|
||||
|
||||
import pit/ansiterm
|
||||
import pit/libpit
|
||||
import pit/cliconstants
|
||||
|
||||
@@ -23,6 +24,16 @@ const TXT = "text/plain"
|
||||
|
||||
proc raiseEx(reason: string): void = raise newException(Exception, reason)
|
||||
|
||||
proc queryParamsToCliArgs[T](queryParams: T): seq[string] =
|
||||
result = @[]
|
||||
for k, v in queryParams:
|
||||
if k.startsWith("arg"):
|
||||
result.add(v)
|
||||
else:
|
||||
result.add("--" & k)
|
||||
if v != "true":
|
||||
result.add(v)
|
||||
|
||||
template halt(code: HttpCode,
|
||||
headers: RawHeaders,
|
||||
content: string): void =
|
||||
|
||||
+29
-1
@@ -1 +1,29 @@
|
||||
doAssert(1 + 1 == 2)
|
||||
import std/[options, tables, times, unittest]
|
||||
|
||||
import pit/libpit
|
||||
|
||||
suite "regex-backed issue behavior":
|
||||
test "summary and full-text filters are case-insensitive":
|
||||
let issue = Issue(
|
||||
summary: "Fix the Widget",
|
||||
details: "Failure happens in the renderer",
|
||||
properties: newTable[string, string](),
|
||||
tags: @[])
|
||||
|
||||
check @[issue].filter(summaryMatchFilter("widget")).len == 1
|
||||
check @[issue].filter(summaryMatchFilter("missing")).len == 0
|
||||
check @[issue].filter(fullMatchFilter("RENDERER")).len == 1
|
||||
|
||||
test "recurrence values parse captures":
|
||||
let issue = Issue(
|
||||
summary: "repeating",
|
||||
properties: newTable[string, string](),
|
||||
tags: @[])
|
||||
|
||||
issue["recurrence"] = "after 2 weeks, abc123"
|
||||
|
||||
let recurrence = issue.getRecurrence()
|
||||
check recurrence.isSome
|
||||
check recurrence.get.isFromCompletion
|
||||
check recurrence.get.interval == weeks(2)
|
||||
check recurrence.get.cloneId == some("abc123")
|
||||
|
||||
Reference in New Issue
Block a user