Add missing notify

This commit is contained in:
lash 2022-01-21 10:15:59 +00:00
parent f17e31d801
commit 81233e8c53
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
1 changed files with 32 additions and 0 deletions

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))