withColor should reset the terminal color afterwards by default.
This commit is contained in:
11
cliutils.nim
11
cliutils.nim
@@ -21,14 +21,19 @@ proc termColor*(color: TermColor, bright, bold = false): string =
|
|||||||
if bright: inc(colorVal, 60)
|
if bright: inc(colorVal, 60)
|
||||||
return "\e[" & $colorVal & (if bold: ";1" else: "") & "m"
|
return "\e[" & $colorVal & (if bold: ";1" else: "") & "m"
|
||||||
|
|
||||||
proc withColor*(str: string, color: TermColor, bright, bold = false): string =
|
|
||||||
return termColor(color, bright, bold) & str
|
proc withColor*(str: string, color: TermColor, bright, bold, skipReset = false): string =
|
||||||
|
if skipReset:
|
||||||
|
return termColor(color, bright, bold) & str
|
||||||
|
else:
|
||||||
|
return termColor(color, bright, bold) & str & termReset
|
||||||
|
|
||||||
|
|
||||||
proc stripAnsi*(str: string): string =
|
proc stripAnsi*(str: string): string =
|
||||||
let STRIP_ANSI_REGEX = re"\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]"
|
let STRIP_ANSI_REGEX = re"\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]"
|
||||||
return str.replace(STRIP_ANSI_REGEX, "")
|
return str.replace(STRIP_ANSI_REGEX, "")
|
||||||
|
|
||||||
|
|
||||||
proc doParseQueryParams[T](queryParams: T): seq[string] =
|
proc doParseQueryParams[T](queryParams: T): seq[string] =
|
||||||
result = @[]
|
result = @[]
|
||||||
|
|
||||||
@@ -40,8 +45,10 @@ proc doParseQueryParams[T](queryParams: T): seq[string] =
|
|||||||
result.add("--" & k)
|
result.add("--" & k)
|
||||||
if v != "true": result.add(v) # support things like ?verbose=true -> cmd --verbose
|
if v != "true": result.add(v) # support things like ?verbose=true -> cmd --verbose
|
||||||
|
|
||||||
|
|
||||||
proc queryParamsToCliArgs*(queryParams: Table[string, string]): seq[string] =
|
proc queryParamsToCliArgs*(queryParams: Table[string, string]): seq[string] =
|
||||||
doParseQueryParams(queryParams)
|
doParseQueryParams(queryParams)
|
||||||
|
|
||||||
|
|
||||||
proc queryParamsToCliArgs*(queryParams: StringTableRef): seq[string] =
|
proc queryParamsToCliArgs*(queryParams: StringTableRef): seq[string] =
|
||||||
doParseQueryParams(queryParams)
|
doParseQueryParams(queryParams)
|
||||||
|
|||||||
Reference in New Issue
Block a user