-
Notifications
You must be signed in to change notification settings - Fork 0
/
fclear.py
45 lines (32 loc) · 985 Bytes
/
fclear.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# an animated clear terminal command
import random
import time
import sys
import os
import signal
def getClearCMD():
# for windows
if os.name == "nt":
return "cls"
# for mac and linux(here, os.name is 'posix')
else:
return "clear"
# set correct console clear command
clear = getClearCMD()
# handler for if ctrl+c is pressed to exit loop
def handler(signum, frame):
print("\n")
quit()
# set handler
signal.signal(signal.SIGINT, handler)
l = int(os.get_terminal_size()[1]) # terminal lines
w = int(os.get_terminal_size()[0]) # terminal columns
for i in range(max(l, w)+min(l,w)):
for k in range(min(l, w)):
if i-k > 0 and i-k <= max(l,w):
# print ////////////// on line in terminal
sys.stdout.write("\r\n" + f"{' '*(i-k)}\033[94m{'/'*14}\033[0m")
time.sleep(0.001)
os.system(
clear
) # clear terminal for new frame, "clear" is used for linux and "cls" for windows