Changed ascii art and added theming capability

This commit is contained in:
Ferit Yiğit BALABAN 2022-04-28 02:25:32 +03:00
parent a40fac5771
commit d02d69c690

151
fetchpy
View File

@ -4,21 +4,36 @@
# #
# fetchpy, fetch script alternative to neofetch # fetchpy, fetch script alternative to neofetch
import os import os
import subprocess as sp from subprocess import run
from rich.console import Console from rich.console import Console
from rich.traceback import install from rich.traceback import install
install(show_locals=True) install(show_locals=True)
COLOR1 = '#75FDFF'
COLOR2 = '#FFE252'
COLOR3 = '#D66565'
COLOR4 = '#FFAB3D'
def read_theme():
with open('/home/ferit/scripts/fetch.theme', 'r') as f:
l = f.readlines()
f.close()
global COLOR1
global COLOR2
global COLOR3
global COLOR4
COLOR1 = l[0]
COLOR2 = l[1]
COLOR3 = l[2]
COLOR4 = l[3]
def coloring(text): def coloring(text):
color1 = '#' + '5BCEFA' frame = COLOR2
color2 = '#' + 'F5A9B8' info = COLOR3
color3 = '#' + 'FFFFFF' title = COLOR1
color4 = color2
color5 = color1
frame = color2
info = color3
title = color5
color_dictionary = { color_dictionary = {
'╭': frame, '╭': frame,
'╰': frame, '╰': frame,
@ -28,39 +43,31 @@ def coloring(text):
'┤': frame, '┤': frame,
'│': frame, '│': frame,
'├': frame, '├': frame,
'DIST': info, 'DST': info,
'KERN': info, 'KRN': info,
'SHEL': info, 'SHL': info,
'TERM': info, 'PCK': info,
'PACK': info,
'CPU': info, 'CPU': info,
'iGPU': info, 'GPU': info,
'dGPU': info,
'MEM': info, 'MEM': info,
'UPT': info, 'UPT': info,
'ferit@navi': title, 'ferit@navi': title,
'Hardware': title, 'Hardware': title,
'-@\n': color1, 'O': COLOR1,
'.##@': color1, 'o': COLOR1,
'.####@': color1, ':': COLOR2,
'@#####@': color2, ';': COLOR2,
'.**######@': color2, '>': COLOR3,
'.##@o@#####@': color2, ',': COLOR4,
'.############@': color3, '.:/': COLOR4,
'.##############@': color3, '/': COLOR4,
'@######@**%######@': color3, '\\\\\\': COLOR4,
'@######`': color4, '\\': COLOR4,
'%#####o': color4, ',,///;,': COLOR4,
'@######@': color4, '\';\\': COLOR4,
'######%': color4, '\';\\\\': COLOR4,
'-@#######h': color4, ',;/': COLOR4,
'######@.`': color4, '\'\'\\\\\\\\\\\'"': COLOR4
'.#####h**``': color5,
'`**%@####@': color5,
'@H@*`': color5,
'*`': color5,
'`*%#@': color5,
'`*': color5,
} }
c = Console() c = Console()
iterator = 0 iterator = 0
@ -74,13 +81,21 @@ 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):
c.print(word, style=color_dictionary[word], end='') if '\\' in word:
word_style = color_dictionary[word]
for character in word:
c.print(character, style=word_style, end='')
else:
c.print(f'[{color_dictionary[word]}]{word}[/{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):
c.print(character, style=color_dictionary[character], end='') if character == '\\':
c.print(character, style=color_dictionary[character], end='')
else:
c.print(f'[{color_dictionary[character]}]{character}[/{color_dictionary[character]}]', end='')
else: else:
print(character, end='') print(character, end='')
iterator += 1 iterator += 1
@ -98,34 +113,24 @@ def read_until_space(text, start_at):
def main(): def main():
padding_count = 29 read_theme()
padding_count = 23
distro_name = 'Arch GNU/Linux x86_64' distro_name = 'Arch GNU/Linux'
distro_name = distro_name.ljust(padding_count, ' ') distro_name = distro_name.ljust(padding_count, ' ')
kernel_version = str(os.uname().release) kernel_version = str(os.uname().release)
kernel_version = kernel_version.ljust(padding_count, ' ') kernel_version = kernel_version.ljust(padding_count, ' ')
installed_packages = run(['pacman', '-Q'], text=True, capture_output=True).stdout.splitlines()
shell_name = 'fish' shell_name = 'fish'
query_pacman = sp.Popen(['pacman', '-Q'], stdout=sp.PIPE) for _ in installed_packages:
grep_paclist = sp.Popen(['grep', f'{shell_name}'], stdin=query_pacman.stdout, stdout=sp.PIPE) if shell_name in _:
query_pacman.stdout.close() shell_name = _.removesuffix('\n').ljust(padding_count, ' ')
shell_name, err = grep_paclist.communicate() package_count = str(len(installed_packages)).ljust(padding_count, ' ')
shell_name = str(shell_name).removeprefix('b\'').removesuffix('\\n\'').ljust(padding_count, ' ')
terminal_name = 'kitty' total_memory, used_memory, free_memory, d1, d2, d3 = map(int, os.popen('free -g --si').readlines()[1].split()[1:])
terminal_name = terminal_name.ljust(padding_count, ' ') memory_usage = f'{used_memory} GB / {total_memory} GB'.ljust(padding_count, ' ')
query_pacman = sp.Popen(['pacman', '-Q'], stdout=sp.PIPE)
count_output = sp.Popen(['wc', '-l'], stdin=query_pacman.stdout, stdout=sp.PIPE)
output, err = count_output.communicate()
package_count = str(output).removeprefix('b\'').removesuffix('\\n\'').ljust(padding_count, ' ')
total_memory, used_memory, free_memory, d1, d2, d3 = map(int, os.popen('free -m').readlines()[1].split()[1:])
mem_percentage = round((used_memory / total_memory) * 100, 2)
used_memory = round((used_memory / 1024), 1)
total_memory = round((total_memory / 1024), 1)
memory_usage = f'{used_memory} GiB / {total_memory} GiB ({mem_percentage}%)'.ljust(padding_count, ' ')
with open('/proc/uptime', 'r') as f: with open('/proc/uptime', 'r') as f:
uptime_seconds = float(f.readline().split()[0]) uptime_seconds = float(f.readline().split()[0])
@ -141,21 +146,19 @@ def main():
uptime = uptime.ljust(padding_count, ' ') uptime = uptime.ljust(padding_count, ' ')
txt = f''' txt = f'''
-@
.##@ ╭──────────── ferit@navi ────────────╮ ╭──────── ferit@navi ────────╮
.####@ │ DIST {distro_name}│ │ DST {distro_name}│
@#####@ │ KERN {kernel_version}│ O O , │ KRN {kernel_version}│
.**######@ │ SHEL {shell_name}│ o o .:/ │ SHL {shell_name}│
.##@o@#####@ │ TERM {terminal_name}│ o ,,///;, ,;/ │ PCK {package_count}│
.############@ │ PACK {package_count}│ o o)::::::;;/// ├───────── Hardware ─────────┤
.##############@ ├───────────── Hardware ─────────────┤ >::::::::;;\\\\\\ │ CPU AMD Ryzen 7 5800H │
@######@**%######@ │ CPU AMD Ryzen 7 5800H (16 Cores) │ ''\\\\\\\\\\'" ';\\ │ GPU NV GeForce RTX3050 Ti │
@######` %#####o │ iGPU AMD Radeon™ Graphics (2 GHz) │ ';\\ │ MEM {memory_usage}│
@######@ ######% │ dGPU NVIDIA GeForce RTX 3050 Ti │ │ UPT {uptime}│
-@#######h ######@.` │ MEM {memory_usage}│ ╰────────────────────────────╯
.#####h**`` `**%@####@ │ UPT {uptime}│
@H@*` `*%#@ ╰────────────────────────────────────╯
*` `*
''' '''
coloring(txt) coloring(txt)