summaryrefslogtreecommitdiff
path: root/stdlib.py
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2023-07-31 23:56:15 +0800
committerlittleblack111 <littleblack11111@gmail.com>2023-07-31 23:56:15 +0800
commit582c097ced66f6dda7c69236222f59a37e2b2b91 (patch)
tree80c143176acb96d6ae9566173aab45617523bc11 /stdlib.py
parentdf3f4fe10ceb87122087dadb956c877257c2392e (diff)
more functions & fixes, updated
Diffstat (limited to 'stdlib.py')
-rw-r--r--stdlib.py30
1 files changed, 18 insertions, 12 deletions
diff --git a/stdlib.py b/stdlib.py
index 3d07bbe..2238c5f 100644
--- a/stdlib.py
+++ b/stdlib.py
@@ -44,17 +44,21 @@ class color:
lcyan = "\033[1;36m" # light-cyan
white = "\033[1;37m" # white
+# convert iterable into string
+def istr(value):
+ return str(''.join(map(str, value)))
+
# print but formatly without newline and will flush stream
def printf(*value: str):
- print(str(''.join(value)), end='', flush=True)
+ print(str(istr(value)), end='', flush=True)
# mixly(shuffle) join a list to another
def shufflejoin(str1: str, str2: str, *others):
from random import shuffle
tmpstr = str1 + str2
if others:
- for i in others:
- tmpstr += i
+ for o in others:
+ tmpstr += o
tmpstrlst = list(tmpstr)
shuffle(tmpstrlst)
@@ -71,10 +75,16 @@ def limitString(string: str, limit: int):
def aprintf(*value: str, end=None):
from time import sleep
waitime = 0.01
- value = list(value)
- for i in str(''.join(value)):
+ value = istr(list(value))
+ ani=True
+ if len(value) >= 8*16:
+ ani = ainputf("Print string is bigger, fast animation(Y/n: ")
+ if ani.lower() == 'y':
+ ani=False
+ for i in value:
printf(i)
- sleep(waitime)
+ if ani:
+ sleep(waitime)
if end == None:
printf('\n')
else:
@@ -93,7 +103,7 @@ def printerror(str: str, outputter=aprintf, ccolor=color.red):
outputter(f"{ccolor}[#] {str}{color.reset}")
def ainputf(str: str, end='', ccolor=color.purple):
- aprintf(f"{ccolor}{str}", f"{end}{color.reset}")
+ aprintf(f"{ccolor}{str}", f"{end}{color.reset}", end=end)
return input()
def askinput(str: str, inputter=ainputf, ccolor=color.blue):
@@ -105,7 +115,7 @@ def countdown(timeoutsec: int):
timeoutsec = timeoutsec
for _ in range(timeoutsec-1):
printf(timeoutsec)
- for _ in range(timeoutsec):
+ for _ in range(3):
printf('.')
sleep(0.8/3)
timeoutsec -= 1
@@ -137,7 +147,3 @@ def bgexec(func, arg=False, stop=False):
t = Thread(target=func, args=arg).start()
else:
t = Thread(target=func).start()
-
-# convert iterable into string
-def istr(value: iter):
- return str(''.join(value))