mirror of
https://github.com/borgbackup/borg.git
synced 2025-02-24 15:12:00 +00:00
do not justify if we're not outputing to a terminal
This commit is contained in:
parent
3232769ffc
commit
af925d2723
1 changed files with 15 additions and 9 deletions
|
@ -1258,18 +1258,24 @@ def show(self, current=None, increase=1, info=None):
|
||||||
if pct is not None:
|
if pct is not None:
|
||||||
# truncate the last argument, if no space is available
|
# truncate the last argument, if no space is available
|
||||||
if info is not None:
|
if info is not None:
|
||||||
msg = self.msg % tuple([pct] + info[:-1] + [''])
|
# no need to truncate if we're not outputing to a terminal
|
||||||
space = get_terminal_size()[0] - len(msg)
|
terminal_space = get_terminal_size(fallback=(-1, -1))[0]
|
||||||
|
if terminal_space != -1:
|
||||||
|
space = terminal_space - len(self.msg % tuple([pct] + info[:-1] + ['']))
|
||||||
if space < 8:
|
if space < 8:
|
||||||
info[-1] = ''
|
info[-1] = ' ' * space
|
||||||
else:
|
else:
|
||||||
info[-1] = ellipsis_truncate(info[-1], space)
|
info[-1] = ellipsis_truncate(info[-1], space)
|
||||||
return self.output(self.msg % tuple([pct] + info))
|
return self.output(self.msg % tuple([pct] + info), justify=False)
|
||||||
|
|
||||||
return self.output(self.msg % pct)
|
return self.output(self.msg % pct)
|
||||||
|
|
||||||
def output(self, message):
|
def output(self, message, justify=True):
|
||||||
message = message.ljust(get_terminal_size(fallback=(4, 1))[0])
|
if justify:
|
||||||
|
terminal_space = get_terminal_size(fallback=(-1, -1))[0]
|
||||||
|
# no need to ljust if we're not outputing to a terminal
|
||||||
|
if terminal_space != -1:
|
||||||
|
message = message.ljust(terminal_space)
|
||||||
self.logger.info(message)
|
self.logger.info(message)
|
||||||
|
|
||||||
def finish(self):
|
def finish(self):
|
||||||
|
|
Loading…
Reference in a new issue