diff options
author | bptato <nincsnevem662@gmail.com> | 2021-01-23 14:20:41 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2021-01-23 14:20:41 +0100 |
commit | ed3886ab51a76f184d023d79e085f928427b8328 (patch) | |
tree | 1e95754cb83677fa278be4206f4876e3af835a84 /twtstr.nim | |
parent | 94d681b3935a3f9105dc60320230fa9657cbd7b5 (diff) | |
download | chawan-ed3886ab51a76f184d023d79e085f928427b8328.tar.gz |
unicode kinda broken otherwise better than ever
Diffstat (limited to 'twtstr.nim')
-rw-r--r-- | twtstr.nim | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/twtstr.nim b/twtstr.nim index 85035a61..5f762780 100644 --- a/twtstr.nim +++ b/twtstr.nim @@ -4,13 +4,25 @@ import unicode const runeSpace* = " ".runeAt(0) -func ansiStyle*(str: string, style: Style): string = - return ansiStyleCode(style) & str & "\e[0m" +func ansiStyle*(str: string, style: Style): seq[string] = + result &= ansiStyleCode(style) + result &= str -func ansiFgColor*(str: string, color: ForegroundColor): string = - return ansiForegroundColorCode(color) & str & ansiResetCode +func ansiFgColor*(str: string, color: ForegroundColor): seq[string] = + result &= ansiForegroundColorCode(color) + result &= str -func ansiReset*(str: string): string = +func ansiReset*(str: string): seq[string] = + result &= str + result &= ansiResetCode + +func ansiStyle*(str: seq[string], style: Style): seq[string] = + return ansiStyleCode(style) & str + +func ansiFgColor*(str: seq[string], color: ForegroundColor): seq[string] = + return ansiForegroundColorCode(color) & str + +func ansiReset*(str: seq[string]): seq[string] = return str & ansiResetCode func maxString*(str: string, max: int): string = @@ -23,7 +35,10 @@ func fitValueToSize*(str: string, size: int): string = return str & ' '.repeat(size - str.runeLen) return str.maxString(size) -func buttonFmt*(str: string): string = +func buttonFmt*(str: string): seq[string] = + return "[".ansiFgColor(fgRed) & str.ansiFgColor(fgRed).ansiReset() & "]".ansiFgColor(fgRed).ansiReset() + +func buttonFmt*(str: seq[string]): seq[string] = return "[".ansiFgColor(fgRed) & str.ansiFgColor(fgRed).ansiReset() & "]".ansiFgColor(fgRed).ansiReset() func buttonRaw*(str: string): string = @@ -51,3 +66,11 @@ func getControlLetter*(c: char): char = elif c == '\x7F': return '?' assert(false) + +func findChar*(str: string, c: char, start: int = 0): int = + var i = start + while i < str.len: + if str[i] == c: + return i + i += 1 + return -1 |