Major refactor of ANSI terminal formatting and control logic.

This commit is contained in:
2025-12-17 20:02:01 -06:00
parent c0e96f99a8
commit c60f7e1576
3 changed files with 116 additions and 27 deletions

View File

@@ -1,40 +1,17 @@
import std/[nre, terminal, strtabs, tables, unicode]
import strutils except toUpper, toLower
import std/[strtabs, strutils, tables]
import ./cliutils/ansiterm
import ./cliutils/config
import ./cliutils/daemonize
import ./cliutils/procutil
import ./cliutils/queue_logger
export ansiterm
export config
export daemonize
export procutil
export queue_logger
type
TermColor = ForegroundColor or BackgroundColor
const termReset* = "\e[0;m"
proc termColor*(color: TermColor, bright, bold = false): string =
var colorVal = ord(color)
if bright: inc(colorVal, 60)
return "\e[" & $colorVal & (if bold: ";1" else: "") & "m"
proc termFmt*(str: string, color: TermColor, bright, bold, underline, skipReset = false): string =
result = termColor(color, bright, bold) & str
if underline: result = "\e[4m" & result
if not skipReset: result &= termReset
proc withColor*(str: string, color: TermColor, bright, bold, skipReset = false): string =
termFmt(str, color, bright, bold, false, skipReset)
proc stripAnsi*(str: string): string =
let STRIP_ANSI_REGEX = re"\x1B\[([0-9]{1,2}(;[0-9]{0,2})?)?[m|K]"
return str.replace(STRIP_ANSI_REGEX, "")
proc doParseQueryParams[T](queryParams: T): seq[string] =
result = @[]