2022-04-20 17:03:28 +01:00
|
|
|
#!/usr/bin/env python3
|
2020-08-26 02:04:10 +01:00
|
|
|
|
2022-04-20 15:01:36 +01:00
|
|
|
from argparse import ArgumentParser
|
2022-04-20 17:03:28 +01:00
|
|
|
from datetime import timedelta
|
2020-08-26 02:04:10 +01:00
|
|
|
from getpass import getuser
|
2022-04-20 17:03:28 +01:00
|
|
|
# from platform import machine as architecture
|
|
|
|
from platform import platform as system
|
|
|
|
from platform import release as kernel
|
|
|
|
from random import choice as random_choice
|
2020-08-26 02:04:10 +01:00
|
|
|
from socket import gethostname
|
2022-04-20 17:03:28 +01:00
|
|
|
from time import clock_gettime, CLOCK_BOOTTIME
|
2022-04-20 17:48:59 +01:00
|
|
|
|
2022-04-20 17:03:28 +01:00
|
|
|
from distro import name as distribution
|
2020-08-26 02:04:10 +01:00
|
|
|
|
2022-04-20 17:48:59 +01:00
|
|
|
from packages import get_num_packages as packages
|
|
|
|
|
2020-08-26 02:04:10 +01:00
|
|
|
# Define a dictionary of all the flags and their colors
|
|
|
|
# Each color is the color for an individual row in the flag
|
|
|
|
flags = {
|
2022-04-20 18:07:56 +01:00
|
|
|
"classic": [196, 208, 226, 28, 20, 90],
|
|
|
|
"gay": [23, 43, 115, 255, 117, 57, 55],
|
2022-04-20 15:01:36 +01:00
|
|
|
"bisexual": [198, 198, 97, 25, 25],
|
|
|
|
"lesbian": [202, 209, 255, 255, 168, 161],
|
2022-04-20 17:03:28 +01:00
|
|
|
"pansexual": [198, 220, 39],
|
2022-04-20 15:01:36 +01:00
|
|
|
"trans": [81, 211, 255, 211, 81],
|
2022-04-20 18:07:56 +01:00
|
|
|
"nonbinary": [226, 255, 98, 237],
|
2022-04-20 15:01:36 +01:00
|
|
|
"demiboy": [244, 249, 117, 255, 117, 249, 244],
|
|
|
|
"demigirl": [244, 249, 218, 255, 218, 249, 244],
|
|
|
|
"genderfluid": [211, 255, 128, 0, 63],
|
|
|
|
"aromantic": [71, 149, 255, 249, 0],
|
|
|
|
"agender": [0, 251, 255, 149, 255, 251, 0],
|
2022-04-20 17:03:28 +01:00
|
|
|
"asexual": [0, 242, 255, 54],
|
2022-04-20 15:01:36 +01:00
|
|
|
"graysexual": [54, 242, 255, 242, 54],
|
2020-08-26 02:04:10 +01:00
|
|
|
}
|
|
|
|
|
2022-04-20 15:01:36 +01:00
|
|
|
# When printed, reset will end the color of the row
|
|
|
|
reset = "\033[0m\033[39m"
|
|
|
|
|
|
|
|
|
|
|
|
def color256(col: int, bg_fg: str) -> str:
|
|
|
|
# Hacky alias around manually typing out escape codes every time
|
|
|
|
return f"\033[{48 if bg_fg == 'bg' else 38};5;{col}m"
|
2020-08-26 02:04:10 +01:00
|
|
|
|
|
|
|
|
2022-04-20 15:01:36 +01:00
|
|
|
def draw_fetch(flag_name: str, width: int = None):
|
2022-04-20 17:03:28 +01:00
|
|
|
# Load the flag from the dictionary of flags
|
2022-04-20 15:01:36 +01:00
|
|
|
flag = flags[flag_name]
|
2020-08-26 02:04:10 +01:00
|
|
|
|
|
|
|
# Make sure that the row color is different to the color of the hostname
|
|
|
|
row_color = color256(flag[1] if flag[0] != flag[1] else flag[2], "fg")
|
2022-04-20 17:03:28 +01:00
|
|
|
black = '\x1b[38;5;242m'
|
|
|
|
|
2022-04-20 18:09:55 +01:00
|
|
|
# The fetch data to be displayed
|
2022-04-20 17:03:28 +01:00
|
|
|
row_data = [
|
|
|
|
f"{color256(flag[0], 'fg') if row_color != black else color256(242, 'fg')}"
|
|
|
|
f"\033[1m{getuser()}@{gethostname()}{reset}",
|
|
|
|
f"{row_color}os {reset}{distribution() or system() or 'N/A'}",
|
|
|
|
# f"{row_color}arch {reset}{architecture() or 'N/A'}",
|
|
|
|
f"{row_color}pkgs {reset}{packages() or 'N/A'}",
|
|
|
|
f"{row_color}kernel {reset}{kernel() or system() or 'N/A'}",
|
|
|
|
f"{row_color}uptime {reset}{str(timedelta(seconds=clock_gettime(CLOCK_BOOTTIME))).split('.', 1)[0]}"
|
|
|
|
]
|
|
|
|
|
2022-04-20 18:09:55 +01:00
|
|
|
# Until the flag is a greater length than the data
|
2022-04-20 17:03:28 +01:00
|
|
|
while len(flag) < len(row_data):
|
2022-04-20 18:09:55 +01:00
|
|
|
# If the data is greater than the flag length then duplicate the length of the flag
|
2022-04-20 17:03:28 +01:00
|
|
|
flag = [element for element in flag for _ in (0, 1)]
|
|
|
|
|
2022-04-20 18:09:55 +01:00
|
|
|
# Set the width of the flag relative to its height (keep it in a nice ratio)
|
2022-04-20 17:03:28 +01:00
|
|
|
width = width or round(len(flag) * 1.5 * 3)
|
|
|
|
|
2022-04-20 17:04:23 +01:00
|
|
|
# Ensures nothing is printed for empty lines
|
2022-04-20 17:03:28 +01:00
|
|
|
row_data.append("")
|
2020-08-26 02:04:10 +01:00
|
|
|
|
2022-04-20 15:01:36 +01:00
|
|
|
# Print a blank line to separate the flag from the terminal prompt
|
2020-08-26 02:04:10 +01:00
|
|
|
print()
|
|
|
|
|
2022-04-20 17:03:28 +01:00
|
|
|
for index, row in enumerate(flag):
|
|
|
|
# Print out each row of the fetch
|
|
|
|
print(f" {color256(row, 'bg')}{' ' * width}\033[49m{reset} {row_data[min(index, len(row_data) - 1)]}{reset}")
|
2022-04-20 15:01:36 +01:00
|
|
|
|
|
|
|
# Print a blank line to separate the flag from the terminal prompt
|
2020-08-26 02:04:10 +01:00
|
|
|
print()
|
|
|
|
|
|
|
|
|
2022-04-20 15:01:36 +01:00
|
|
|
def main():
|
|
|
|
# Argument configuration
|
|
|
|
parser = ArgumentParser()
|
|
|
|
parser.add_argument("-f", "--flag", help="displays the chosen flag")
|
2022-04-20 17:03:28 +01:00
|
|
|
parser.add_argument("-r", "--random", help="randomly choose a flag from a list seperated by commas")
|
2022-04-20 15:01:36 +01:00
|
|
|
parser.add_argument("-w", "--width", help="choose a custom width for the flag", type=int)
|
|
|
|
parser.add_argument("-l", "--list", help="lists all the flags that can be displayed", action="store_true")
|
|
|
|
|
|
|
|
# Parse the arguments
|
2020-08-26 02:04:10 +01:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
if args.flag:
|
2022-04-20 17:03:28 +01:00
|
|
|
# Check if the flag exists in the dictionary of flags
|
|
|
|
assert args.flag in flags.keys(), f"flag '{args.flag}' is not a valid flag"
|
|
|
|
|
|
|
|
# Draw the chosen flag and system information
|
2022-04-20 15:01:36 +01:00
|
|
|
draw_fetch(args.flag, args.width)
|
|
|
|
|
2022-04-20 17:03:28 +01:00
|
|
|
if args.random:
|
2020-08-26 02:04:10 +01:00
|
|
|
# Choose a flag at random from a list of comma-seperated flags
|
2022-04-20 18:11:42 +01:00
|
|
|
flag_choices = args.random.split(",")
|
2022-04-20 18:13:09 +01:00
|
|
|
draw_fetch(random_choice(flag_choices), args.width)
|
2022-04-20 15:01:36 +01:00
|
|
|
|
2020-08-26 02:04:10 +01:00
|
|
|
if args.list:
|
|
|
|
# List out all the available flags
|
2022-04-20 15:01:36 +01:00
|
|
|
print(f"Available flags:\n{', '.join(flags)}")
|
2020-08-26 02:04:10 +01:00
|
|
|
|
|
|
|
|
2022-04-20 15:01:36 +01:00
|
|
|
if __name__ == "__main__":
|
2020-08-26 02:04:10 +01:00
|
|
|
main()
|