|
1 | 1 |
|
| 2 | +import shutil |
| 3 | +from time import * |
| 4 | +import json |
| 5 | +import os |
| 6 | +import sys |
| 7 | +import random |
2 | 8 |
|
| 9 | +# Variable Glosarium |
| 10 | +MINIMUM_WIDTH = 16 |
| 11 | +MAXIMUM_WIDTH = 60 |
| 12 | +STANDARD_WIDTH = 37 |
| 13 | +user_width = STANDARD_WIDTH |
| 14 | +warning = True # button for terminal_warning() |
| 15 | +dot = "." # just in case |
| 16 | +nl = "\n" |
| 17 | +d = '-' |
3 | 18 |
|
4 |
| -import json |
| 19 | +lang = { |
| 20 | +'en':'English', |
| 21 | +'es':'Español', |
| 22 | +'fr':'Français', |
| 23 | +'gr':'Deutsch', |
| 24 | +'ina':'Indonesia', |
| 25 | +'jp':'日本語', |
| 26 | +'cn':'中国', |
| 27 | +'arb':'عربي', |
| 28 | +'ind':'भारत' |
| 29 | +} |
| 30 | + |
| 31 | +# =========== MAIN METHOD ============ |
| 32 | + |
| 33 | +# For clearing view |
| 34 | +def clear(): |
| 35 | + if os.name == 'nt': |
| 36 | + os.system('cls') |
| 37 | + else: |
| 38 | + os.system('clear') |
| 39 | + |
| 40 | + |
| 41 | +# Refresh width |
| 42 | +def refresh_width(debug=False): |
| 43 | + now = shutil.get_terminal_size().columns # Get current terminal width |
| 44 | + global warning |
| 45 | + |
| 46 | + |
| 47 | + if warning: |
| 48 | + width = now |
| 49 | + while True: # Loop until a valid response is given |
| 50 | + if width <= MINIMUM_WIDTH: |
| 51 | + c = input("Your\nscreen\nis\ntoo\nsmall,\nProceed?\n(y/n)\n(f = fix)\n: ").strip().lower() |
| 52 | + if c == 'y': |
| 53 | + warning = False |
| 54 | + break |
| 55 | + elif c == 'f': |
| 56 | + print("Please\nset\nyour\nterminal\nwidth\nto, or\nabove\n16pt\nand\nbelow\n36pt", flush=True) |
| 57 | + input("Press Enter when done...") |
| 58 | + warning = False |
| 59 | + break |
| 60 | + |
| 61 | + elif c == 'n': |
| 62 | + sys.exit('Thx\nFor\nPlay-\ning!\n:D') |
| 63 | + else: |
| 64 | + clear() # Clear screen for invalid input |
| 65 | + pass |
| 66 | + elif width >= MAXIMUM_WIDTH: |
| 67 | + c = input("Y O U R S C R E E N I S T O O B I G !\n\nP R O C E E D ( Y / N / F T O F I X) : ").strip().lower() |
| 68 | + if c == 'y': |
| 69 | + warning = False |
| 70 | + break |
| 71 | + elif c == 'f': |
| 72 | + print(f"{'P L E A S E S E T Y O U R T E R M I N A L W I D T H E Q U A L / A B O V E 1 2 P T A N D B E L O W 3 6 P T ':^{width}}", flush=True) |
| 73 | + input("Press Enter when done...") |
| 74 | + warning = False |
| 75 | + break |
| 76 | + elif c == 'n': |
| 77 | + sys.exit(f"{'T H A N K S F O R P L A Y I N G ! ! ! :D':^{width}}") |
| 78 | + else: |
| 79 | + clear() # Clear screen for invalid input |
| 80 | + |
| 81 | + else: |
| 82 | + break # Exit if width is within acceptable bounds |
| 83 | + |
| 84 | + now = shutil.get_terminal_size().columns |
| 85 | + if debug: |
| 86 | + print("Width refreshed to ", now) |
| 87 | + |
| 88 | + return now |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | +# Blank input to continue |
| 93 | +def confirm(): |
| 94 | + dash() |
| 95 | + print("Input apa saja untuk melanjutkan") |
| 96 | + dashn() |
| 97 | + input() |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | +# Open dash |
| 102 | +def dash(n=None, r=False, d="="): |
| 103 | + if n is None: |
| 104 | + n = refresh_width() |
| 105 | + if r: |
| 106 | + return d * n |
| 107 | + print(d * n, flush=True) |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | +# Close dash (with newline) |
| 112 | +def dashn(n=None, r=False, d="="): |
| 113 | + if n is None: |
| 114 | + n = refresh_width() |
| 115 | + if r: |
| 116 | + return d * n |
| 117 | + print(d * n, "\n", flush=True) |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | +# Loading animation |
| 122 | +def loading(duration=3): |
| 123 | + wide = refresh_width() # Call once |
| 124 | + end_time = time() + duration |
5 | 125 |
|
| 126 | + frames = [ |
| 127 | + "⠂⠄⠅","⠇⠆⠘","⠐⠠⠐", |
| 128 | + "⠄⠅⠇","⠆⠘⠐","⠠⠐⠘", |
| 129 | + "⠅⠇⠆","⠘⠐⠠","⠐⠘⠂", |
| 130 | + "⠇⠆⠘","⠐⠠⠐","⠘⠂⠄", |
| 131 | + "⠆⠘⠐","⠠⠐⠘","⠂⠄⠅", |
| 132 | + "⠘⠐⠠","⠐⠘⠂","⠄⠅⠇", |
| 133 | + "⠐⠠⠐","⠘⠂⠄","⠅⠇⠆", |
| 134 | + "⠠⠐⠘","⠂⠄⠅","⠇⠆⠘", |
| 135 | + "⠂⠄⠅","⠇⠆⠘","⠐⠠⠐" |
| 136 | + ] |
| 137 | + |
| 138 | + while time() < end_time: |
| 139 | + for frame in frames: |
| 140 | + if time() >= end_time: |
| 141 | + break |
| 142 | + sys.stdout.write(f'\r{frame * (wide // 3)}') |
| 143 | + sys.stdout.flush() |
| 144 | + sleep(0.05) |
| 145 | + clear() |
| 146 | + |
| 147 | + |
| 148 | +# printing (prettifier) |
| 149 | +# print(index,text) for num list |
| 150 | +# printf(text) for plain centered text |
| 151 | +def printf(index=None,text=None): |
| 152 | + if text == False: |
| 153 | + dash() |
| 154 | + print("This is a function i built because i get sick of repeating long format print :)") |
| 155 | + dashn() |
| 156 | + elif index: |
| 157 | + if type(index) == str: |
| 158 | + return f"{f'{index}':^{refresh_width()}}" |
| 159 | + return f"{f'{dash(20,1,d)}{nl}':^{refresh_width()}}\r{f'|{index} {text:<16}|':^{refresh_width()}}{nl}{dash(20,1,d):^{refresh_width()}}" |
| 160 | + |
| 161 | + else: |
| 162 | + dash() |
| 163 | + print("ERROR PRINTING, ARGS = ",text) |
| 164 | + dashn() |
| 165 | + |
| 166 | + |
| 167 | +# ====== TRANSLATION FUNCTION ===== |
6 | 168 | def load_translations(language="en"):
|
7 | 169 | try:
|
8 | 170 | with open(f"../translation/{language}.json", "r", encoding="utf-8") as file:
|
|
0 commit comments