diff options
author | bptato <nincsnevem662@gmail.com> | 2021-01-20 13:26:00 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2021-01-20 13:26:00 +0100 |
commit | 5268aada71dd554dca29c5bc273702d39d14bb5c (patch) | |
tree | 18b4a41ffaf464a8c0df0222a248f29bc570e369 /twtstr.nim | |
download | chawan-5268aada71dd554dca29c5bc273702d39d14bb5c.tar.gz |
Some things work, most things don't
Diffstat (limited to 'twtstr.nim')
-rw-r--r-- | twtstr.nim | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/twtstr.nim b/twtstr.nim new file mode 100644 index 00000000..5a41f3e3 --- /dev/null +++ b/twtstr.nim @@ -0,0 +1,28 @@ +import terminal +import strutils + +func stripNewline*(str: string): string = + if str.len == 0: + result = str + return + + case str[^1] + of '\n': + result = str.substr(0, str.len - 2) + else: discard + +func addAnsiStyle*(str: string, style: Style): string = + return ansiStyleCode(style) & str & "\e[0m" + +func addAnsiFgColor*(str: string, color: ForegroundColor): string = + return ansiForegroundColorCode(color) & str & "\e[0m" + +func maxString*(str: string, max: int): string = + if max < str.len: + return str.substr(0, max - 2) & "$" + return str + +func fitValueToSize*(str: string, size: int): string = + if str.len < size: + return str & ' '.repeat(size - str.len) + return str.maxString(size) |