COLORFUL UPDATE
Make output more and more and more colorful! Change file structure and README.md
This commit is contained in:
@@ -67,3 +67,57 @@ class CompactBar(Bar):
|
||||
line = ''.join([message, suffix])[:display_length]+"..."
|
||||
shorten = len_abs(line)
|
||||
self.writeln(line, shorten=shorten)
|
||||
|
||||
|
||||
class CompactArrowBar(CompactBar):
|
||||
def update(self):
|
||||
"""
|
||||
覆写原有的update方法,自适应终端宽度
|
||||
支持中文
|
||||
"""
|
||||
filled_length = int(self.width * self.progress)
|
||||
empty_length = self.width - filled_length
|
||||
|
||||
message = self.message % self
|
||||
s = "=" * filled_length
|
||||
if s:
|
||||
s = s[:-1] + ">"
|
||||
bar = color(s, fg=self.color)
|
||||
empty = self.empty_fill * empty_length
|
||||
suffix = self.suffix % self
|
||||
line = ''.join([message, self.bar_prefix, bar, empty, self.bar_suffix,
|
||||
suffix])
|
||||
# 以上为原本update代码
|
||||
term_size = get_terminal_size().columns
|
||||
shorten = False
|
||||
if len_abs(line) > term_size: # 检测完整长度是否小于终端长度
|
||||
if len_abs(line) - len_abs(''.join([bar, empty])) <= term_size: # 检测无进度条时是否小于终端长度
|
||||
width = term_size - (len_abs(line) - len_abs("".join([bar, empty]))) - 1
|
||||
filled_length = int(width * self.progress)
|
||||
empty_length = width - filled_length
|
||||
s = "=" * filled_length
|
||||
if s:
|
||||
s = s[:-1] + ">"
|
||||
bar = color(s, fg=self.color)
|
||||
empty = self.empty_fill * empty_length
|
||||
line = ''.join([message, self.bar_prefix, bar, empty, self.bar_suffix,
|
||||
suffix])
|
||||
shorten = len_abs(line)
|
||||
elif len_abs(''.join([message, suffix])) <= term_size: # 检测仅有前缀后缀时是否小于终端长度
|
||||
line = ''.join([message, suffix])
|
||||
shorten = len_abs(line)
|
||||
else: # 全部不符合时,以仅有前缀后缀的模式,直接截断
|
||||
display_length = term_size - get_more_length(''.join([message, suffix])[:term_size]) - 3
|
||||
if display_length < 0:
|
||||
display_length = 0
|
||||
line = ''.join([message, suffix])[:display_length] + "..."
|
||||
shorten = len_abs(line)
|
||||
self.writeln(line, shorten=shorten)
|
||||
|
||||
|
||||
def bprint(content, bar: CompactBar = None):
|
||||
"""添加对进度条的支持的print, 若传入bar参数, 则使用print_onto_bar参数来打印内容"""
|
||||
if bar:
|
||||
bar.print_onto_bar(content)
|
||||
else:
|
||||
print(content)
|
||||
|
@@ -1,4 +1,4 @@
|
||||
"""包含一个函数,用来清空命令行的信息,自动判别系统"""
|
||||
"""用来清空命令行的信息,自动判别系统"""
|
||||
import os
|
||||
|
||||
|
||||
@@ -9,4 +9,11 @@ def clear():
|
||||
elif name == "posix":
|
||||
os.system("clear")
|
||||
else:
|
||||
os.system("clear")
|
||||
os.system("clear")
|
||||
|
||||
|
||||
def cls_stay(self, custom=""):
|
||||
"""保留版本号清除屏幕"""
|
||||
clear()
|
||||
print(f"[NeteaseMusicLyricDownloader] {self.version}")
|
||||
print(custom)
|
Reference in New Issue
Block a user