From d368e85e33f0c713bea75493c22bc43707374e90 Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Tue, 29 May 2018 14:18:14 -0500 Subject: [PATCH] Refactor color functions to provide a unified interface for fore/back ground. --- cliutils.nim | 14 +++++++------- cliutils.nimble | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cliutils.nim b/cliutils.nim index ca5fb39..5e331e6 100644 --- a/cliutils.nim +++ b/cliutils.nim @@ -8,6 +8,8 @@ type docopt*: Table[string, Value] json*: JsonNode + TermColor = ForegroundColor or BackgroundColor + proc getVal*(cfg: CombinedConfig, key, default: string): string = let argKey = "--" & key let envKey = key.replace('-', '_').toUpper @@ -172,14 +174,12 @@ proc daemonize*(pidfile, si, so, se: string, daemonMain: proc(): void): Pid = return pid1 -proc termFG*(color: ForegroundColor, bright, bold = false): string = +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 termBG*(color: BackgroundColor, bright, bold = false): string = - var colorVal = ord(color) - if bright: inc(colorVal, 60) - return "\e[" & $colorVal & "m" - -const termReset* = "\e[0;m" +proc withColor*(str: string, color: TermColor, bright, bold = false): string = + return termColor(color, bright, bold) & str diff --git a/cliutils.nimble b/cliutils.nimble index 0e26f44..5a9c9dd 100644 --- a/cliutils.nimble +++ b/cliutils.nimble @@ -1,6 +1,6 @@ # Package -version = "0.4.0" +version = "0.4.1" author = "Jonathan Bernard" description = "Helper functions for writing command line interfaces." license = "MIT"