Skip to content

Commit

Permalink
Main File
Browse files Browse the repository at this point in the history
  • Loading branch information
ibehii authored Sep 13, 2023
1 parent 19d8009 commit 654856c
Showing 1 changed file with 61 additions and 58 deletions.
119 changes: 61 additions & 58 deletions Rcolor/rcolor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,33 @@
# e-mail: Behii@tutanota.com
# ____________________________________________

# import part
# ======== # import built-in library # ======== #
from random import choice
from os import name
from json import load

# random color

def color (*user_input):
# ======== # random front color # ======== #
def color (*user_input) -> str:
''''''
try:
# Opening json file that contain colors code in windows and linux
if name == 'nt':
json_paths = __file__.replace('Rcolor.py', 'colors\colors.json')
# ====== # Opening json file that contain colors code in windows and linux # ====== #
if(name == 'nt'):
json_paths: str = __file__.replace('Rcolor.py', 'colors\\colors.json')
else:
json_paths = __file__.replace('Rcolor.py', 'colors/colors.json')
json_paths: str = __file__.replace('Rcolor.py', 'colors/colors.json')
with open(json_paths , 'r') as f:
colors = load(f).get("colors")
colors: list[str] = load(f).get("colors")
user_input = list(user_input)
# make all item in user_input list to string

# ======== # make all item in user_input list to string # ======== #
for i in user_input:
if type(i) == str:
pass
else:
user_input[user_input.index(i)] = str(i)

user_input = ''.join(user_input)
random_color = choice(colors)
random_color: str = choice(colors)

return random_color + user_input + '\033[0m'
except FileNotFoundError:
Expand All @@ -38,27 +39,27 @@ def color (*user_input):
pass
return('\33[31m' + f'Input type {type(i)} is not supported' + '\033[0m')

# random background color
def background (*user_input):
# ======== # random background color # ======== #
def background (*user_input) -> str:
try:
# Opening json file that contain colors code in windows and linux
# ====== # Opening json file that contain colors code in windows and linux # ====== #
if name == 'nt':
json_paths = __file__.replace('Rcolor.py', 'colors\background_color.json')
json_paths: str = __file__.replace('Rcolor.py', 'colors\background_color.json')
else:
json_paths = __file__.replace('Rcolor.py', 'colors/background_color.json')
json_paths: str = __file__.replace('Rcolor.py', 'colors/background_color.json')
with open(json_paths, 'r') as f:
background_color = load(f).get("background_color")
background_color: list[str] = load(f).get("background_color")
user_input = list(user_input)

# make all item in user_input list to string
# ======== # make all item in user_input list to string # ======== #
for i in user_input:
if type(i) == str:
pass
else:
user_input[user_input.index(i)] = str(i)

user_input = ''.join(user_input)
random_color = choice(background_color)
random_color: str = choice(background_color)
return random_color + user_input + '\033[0m'
except FileNotFoundError:
pass
Expand All @@ -67,19 +68,19 @@ def background (*user_input):
pass
return('\33[31m' + f'Input type {type(i)} is not supported' + '\033[0m')

# random Windows color
def windows_color(*user_input):
# ======== # Random Windows color # ======== #
def windows_color(*user_input) -> str:
try:
# Opening json file that contain colors code in windows and linux
# ====== # Opening json file that contain colors code in windows and linux # ====== #
if name == 'nt':
json_paths = __file__.replace('Rcolor.py', 'colors\Windows_color.json')
json_paths: str = __file__.replace('Rcolor.py', 'colors\\Windows_color.json')
else:
json_paths = __file__.replace('Rcolor.py', 'colors/Windows_color.json')
json_paths: str = __file__.replace('Rcolor.py', 'colors/Windows_color.json')
with open(json_paths, 'r') as f:
windows_color = load(f).get("Windows_color")
windows_color: list[str] = load(f).get("Windows_color")
user_input = list(user_input)

# make all item in user_input list to string
# ======== # make all item in user_input list to string # ======== #
for i in user_input:
if type(i) == str:
pass
Expand All @@ -88,7 +89,7 @@ def windows_color(*user_input):
from colorama import init
init()
user_input = ''.join(user_input)
random_color = choice(windows_color)
random_color: str = choice(windows_color)
return random_color + user_input + '\033[0m'
except FileNotFoundError:
pass
Expand All @@ -97,29 +98,29 @@ def windows_color(*user_input):
pass
return('\33[31m' + f'Input type {type(i)} is not supported' + '\033[0m')

# random Windows background color
def windows_background(*user_input):
# ======== # Random Windows background color # ======== #
def windows_background(*user_input) -> str :
try:
# Opening json file that contain colors code in windows and linux
# ====== # Opening json file that contain colors code in windows and linux # ====== #
if name == 'nt':
json_paths = __file__.replace('Rcolor.py', 'colors\Windows_background.json')
json_paths: str = __file__.replace('Rcolor.py', 'colors\\Windows_background.json')
else:
json_paths = __file__.replace('Rcolor.py', 'colors/Windows_background.json')
json_paths: str = __file__.replace('Rcolor.py', 'colors/Windows_background.json')
with open(json_paths, 'r') as f:
Windows_background = load(f).get("Windows_background")
Windows_background: list[str] = load(f).get("Windows_background")
from colorama import init
init()
user_input = list(user_input)

# make all item in user input_list to string
# ======== # make all item in user input_list to string # ======== #
for i in user_input:
if type(i) == str:
pass
else:
user_input[user_input.index(i)] = str(i)

user_input = ''.join(user_input)
random_color = choice(Windows_background)
random_color: str = choice(Windows_background)
return random_color + user_input + '\033[0m'
except FileNotFoundError:
pass
Expand All @@ -128,26 +129,28 @@ def windows_background(*user_input):
pass
return('\33[31m' + f'Input type {type(i)} is not supported' + '\033[0m')

# random style
def style(*user_input):
# Opening json file that contain colors code in windows and linux
if name == 'nt':
json_paths = __file__.replace('Rcolor.py', 'colors\style1.json')
else:
json_paths = __file__.replace('Rcolor.py', 'colors/style1.json')
try:
# ======== # Random style # ======== #
def style(*user_input) -> str:

try:
# ====== # Opening json file that contain colors code in windows and linux # ====== #
if name == 'nt':
json_paths: str = __file__.replace('Rcolor.py', 'colors\\style1.json')
else:
json_paths: str = __file__.replace('Rcolor.py', 'colors/style1.json')
with open(json_paths, 'r') as f:
style1 = load(f).get("style1")
style1: list[str] = load(f).get("style1")
user_input = list(user_input)
# make all item in user_input list to string

# ======== # make all item in user_input list to string # ======== #
for i in user_input:
if type(i) == str:
pass
else:
user_input[user_input.index(i)] = str(i)

user_input = ''.join(user_input)
random_color = choice(style1)
random_color: str = choice(style1)
return random_color + user_input + '\033[0m'
except FileNotFoundError:
pass
Expand All @@ -156,8 +159,8 @@ def style(*user_input):
pass
return('\33[31m' + f'Input type {type(i)} is not supported' + '\033[0m')

# Automatically detects the operating system and return the correct color
def auto_color(*user_input):
# ======== # Automatically detects the operating system and return the correct color # ======== #
def auto_color(*user_input) -> str:
user_input = list(user_input)
for i in user_input:
if type(i) == str:
Expand All @@ -171,8 +174,8 @@ def auto_color(*user_input):
else:
return color(user_input)

# Automatically detects the operating system and return the correct background color
def auto_background(*user_input):
# ======== # Automatically detects the operating system and return the correct background color # ======== #
def auto_background(*user_input) -> str:
user_input = list(user_input)
for i in user_input:
if type(i) == str:
Expand All @@ -186,8 +189,8 @@ def auto_background(*user_input):
else:
return background(user_input)

# return random color and background color
def color_background (*user_input):
# ======== # return random color and background color # ======== #
def color_background (*user_input) -> str:
user_input = list(user_input)
for i in user_input:
if type(i) == str:
Expand All @@ -198,8 +201,8 @@ def color_background (*user_input):
user_input = ''.join(user_input)
return auto_color(auto_background(user_input))

# return random color and style
def color_style (*user_input):
# ======== # return random color and style # ======== #
def color_style (*user_input) -> str:
user_input = list(user_input)
for i in user_input:
if type(i) == str:
Expand All @@ -210,8 +213,8 @@ def color_style (*user_input):
user_input = ''.join(user_input)
return auto_color(style(user_input))

# return random background color and style
def background_style (*user_input):
# ======== # return random background color and style # ======== #
def background_style (*user_input) -> str:
user_input = list(user_input)
for i in user_input:
if type(i) == str:
Expand All @@ -222,8 +225,8 @@ def background_style (*user_input):
user_input = ''.join(user_input)
return auto_background(style(user_input))

# return random color and background color and style
def color_background_style (*user_input):
# ======== # return random color and background color and style # ======== #
def color_background_style (*user_input) -> str:
user_input = list(user_input)
for i in user_input:
if type(i) == str:
Expand Down

0 comments on commit 654856c

Please sign in to comment.