Use rich.console to color output
This commit is contained in:
parent
c50fc314c1
commit
c93d2d6140
62
fetchpy
62
fetchpy
@ -7,6 +7,9 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import subprocess as sp
|
import subprocess as sp
|
||||||
from termcolor import cprint
|
from termcolor import cprint
|
||||||
|
from rich.console import Console
|
||||||
|
from rich.traceback import install
|
||||||
|
install(show_locals=True)
|
||||||
|
|
||||||
|
|
||||||
def color_test():
|
def color_test():
|
||||||
@ -21,7 +24,11 @@ def color_test():
|
|||||||
|
|
||||||
|
|
||||||
def coloring(text):
|
def coloring(text):
|
||||||
ascii_art = 'cyan'
|
red = '#FF0018'
|
||||||
|
orange = '#FFA52C'
|
||||||
|
yellow = '#FFFF41'
|
||||||
|
green = '#008018'
|
||||||
|
blue = '#0000F9'
|
||||||
frame = 'red'
|
frame = 'red'
|
||||||
info = 'yellow'
|
info = 'yellow'
|
||||||
title = 'yellow'
|
title = 'yellow'
|
||||||
@ -46,28 +53,29 @@ def coloring(text):
|
|||||||
'UPT': info,
|
'UPT': info,
|
||||||
'ferit@navi': title,
|
'ferit@navi': title,
|
||||||
'Hardware': title,
|
'Hardware': title,
|
||||||
'-@\n': ascii_art,
|
'-@\n': red,
|
||||||
'.##@': ascii_art,
|
'.##@': red,
|
||||||
'.####@': ascii_art,
|
'.####@': red,
|
||||||
'@#####@': ascii_art,
|
'@#####@': orange,
|
||||||
'.**######@': ascii_art,
|
'.**######@': orange,
|
||||||
'.##@o@#####@': ascii_art,
|
'.##@o@#####@': orange,
|
||||||
'/############@': ascii_art,
|
'.############@': yellow,
|
||||||
'/##############@': ascii_art,
|
'.##############@': yellow,
|
||||||
'@######@**%######@': ascii_art,
|
'@######@**%######@': yellow,
|
||||||
'@######`': ascii_art,
|
'@######`': green,
|
||||||
'%#####o': ascii_art,
|
'%#####o': green,
|
||||||
'@######@': ascii_art,
|
'@######@': green,
|
||||||
'######%': ascii_art,
|
'######%': green,
|
||||||
'-@#######h': ascii_art,
|
'-@#######h': green,
|
||||||
'######@.`': ascii_art,
|
'######@.`': green,
|
||||||
'/#####h**``': ascii_art,
|
'.#####h**``': blue,
|
||||||
'`**%@####@': ascii_art,
|
'`**%@####@': blue,
|
||||||
'@H@*`': ascii_art,
|
'@H@*`': blue,
|
||||||
'*`': ascii_art,
|
'*`': blue,
|
||||||
'`*%#@': ascii_art,
|
'`*%#@': blue,
|
||||||
'`*': ascii_art,
|
'`*': blue,
|
||||||
}
|
}
|
||||||
|
c = Console()
|
||||||
iterator = 0
|
iterator = 0
|
||||||
while iterator < len(text):
|
while iterator < len(text):
|
||||||
character = text[iterator]
|
character = text[iterator]
|
||||||
@ -80,13 +88,13 @@ def coloring(text):
|
|||||||
print(' ', end='')
|
print(' ', end='')
|
||||||
word, jump_to = read_until_space(text, start_at=iterator + 1)
|
word, jump_to = read_until_space(text, start_at=iterator + 1)
|
||||||
if color_dictionary.__contains__(word):
|
if color_dictionary.__contains__(word):
|
||||||
cprint(word, color_dictionary[word], end='')
|
c.print(word, style=color_dictionary[word], end='')
|
||||||
else:
|
else:
|
||||||
print(word, end='')
|
print(word, end='')
|
||||||
iterator = jump_to
|
iterator = jump_to
|
||||||
print(' ', end='')
|
print(' ', end='')
|
||||||
elif color_dictionary.__contains__(character):
|
elif color_dictionary.__contains__(character):
|
||||||
cprint(character, color_dictionary[character], end='')
|
c.print(character, style=color_dictionary[character], end='')
|
||||||
else:
|
else:
|
||||||
print(character, end='')
|
print(character, end='')
|
||||||
iterator += 1
|
iterator += 1
|
||||||
@ -173,13 +181,13 @@ def main():
|
|||||||
@#####@ │ KERN {kernel_version}│
|
@#####@ │ KERN {kernel_version}│
|
||||||
.**######@ │ SHEL {shell_name}│
|
.**######@ │ SHEL {shell_name}│
|
||||||
.##@o@#####@ │ TERM {terminal_name}│
|
.##@o@#####@ │ TERM {terminal_name}│
|
||||||
/############@ │ PACK {package_count}│
|
.############@ │ PACK {package_count}│
|
||||||
/##############@ ├───────────── Hardware ─────────────┤
|
.##############@ ├───────────── Hardware ─────────────┤
|
||||||
@######@**%######@ │ CPU AMD Ryzen 7 5800H (16 Cores) │
|
@######@**%######@ │ CPU AMD Ryzen 7 5800H (16 Cores) │
|
||||||
@######` %#####o │ iGPU AMD Radeon™ Graphics (2 GHz) │
|
@######` %#####o │ iGPU AMD Radeon™ Graphics (2 GHz) │
|
||||||
@######@ ######% │ dGPU NVIDIA GeForce RTX 3050 Ti │
|
@######@ ######% │ dGPU NVIDIA GeForce RTX 3050 Ti │
|
||||||
-@#######h ######@.` │ MEM {memory_usage}│
|
-@#######h ######@.` │ MEM {memory_usage}│
|
||||||
/#####h**`` `**%@####@ │ UPT {uptime}│
|
.#####h**`` `**%@####@ │ UPT {uptime}│
|
||||||
@H@*` `*%#@ ╰────────────────────────────────────╯
|
@H@*` `*%#@ ╰────────────────────────────────────╯
|
||||||
*` `*
|
*` `*
|
||||||
'''
|
'''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user