usability: WIP Friendly progress output #4

Merged
kamikazechaser merged 4 commits from lash/response into master 2022-01-21 12:11:23 +01:00
Showing only changes of commit 81233e8c53 - Show all commits

32
clicada/cli/notify.py Normal file
View File

@ -0,0 +1,32 @@
# standard imports
import os
import sys
class NotifyWriter:
def __init__(self, writer=sys.stdout):
(c, r) = os.get_terminal_size()
self.cols = c
self.fmt = "\r{:" + "<{}".format(c) + "}"
self.w = writer
self.notify_max = self.cols - 4
def notify(self, v):
if len(v) > self.notify_max:
v = v[:self.notify_max]
self.write('\x1b[0;36m... ' + v + '\x1b[0;39m')
def ouch(self, v):
if len(v) > self.notify_max:
v = v[:self.notify_max]
self.write('\x1b[0;91m!!! ' + v + '\x1b[0;39m')
def write(self, v):
s = str(v)
if len(s) > self.cols:
s = s[:self.cols]
self.w.write(self.fmt.format(s))