#๐ Blinking text acting weirdly
9 messages ยท Page 1 of 1 (latest)
@jolly nexus
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
whaaat my original message was deleted agh let me write it out again:
the blinking text in my code seems to be being written in a weird location; both in the write spot and at the start of the wrong line, this currently only works in vs code, not in the generic python terminal (for some reason) id greatly appriciate any help :}
oh shoot u'll probably need this, I'm assuming this is why my first message was removed:
import os, sys, time, threading
def get_folder():
if getattr(sys, 'frozen', False):
script_path = os.path.dirname(sys.executable)
else:
script_path = os.path.dirname(os.path.abspath(sys.modules['__main__'].__file__))
os.chdir(script_path)
def write(text):
sys.stdout.write(text)
sys.stdout.flush()
def colour_font(R: int, G: int, B: int):
return f"\033[38;2;{R};{G};{B}m"
def colour_background(R: int, G: int, B: int):
return f"\033[48;2;{R};{G};{B}m"
def cursor_position(line: int, collum: int):
write(f"\033[{line};{collum}f")
def cursor_up(N: int):
write(f"\033[{N}A")
def cursor_down(N: int):
write(f"\033[{N}B")
def cursor_forward(N: int):
write(f"\033[{N}C")
def cursor_backward(N: int):
write(f"\033[{N}D")
def clear_screen():
if os.name == 'nt': _ = os.system('cls')
elif os.name == 'posix': _ = os.system('clear')
WASH_COLOUR = "\033[49m"
SAVE_CURSOR = "\033[s"
LOAD_CURSOR = "\033[u"
CLEAR_LINE = "\033[2K"
CLEAR_TO_END = "\033[K"
RESET = "\033[0m"
BOLD = "\033[1m"
ITALIC = "\033[3m"
UNDERLINE = "\033[4m"
INVERT = "\033[7m"
CROSS = "\033[9m"
BOLD_OFF = "\033[21m"
ITALIC_OFF = "\033[23m"
UNDERLINE_OFF = "\033[24m"
INVERT_OFF = "\033[27m"
CROSS_OFF = "\033[29m"```
def style(text: str, *formats: str):
format_string = "".join(formats)
write(f"{format_string}{text}{RESET}\n")
class Hidden_Text():
def __init__(self):
self.concealed: list[str] = []
def conceal(self, text: str, *formats: str) -> str: # Modify return type to str
format_string = "".join(formats)
concealed_text = f"{format_string}{text}{RESET}\n" # Store concealed text
self.concealed.append(concealed_text)
write("\033[8m" + concealed_text)
return concealed_text # Return concealed text
def reveal(self, item: int = 0):
revealed_text = self.concealed[item]
self.concealed.pop(0)
write(revealed_text)```
class Blinking_Text():
def __init__(self):
self.blinking: list[str] = []
self.line: list[int] = []
self.collum: list[int] = []
def create_blink(self, text: str, line: int, collum: int, *formats: str):
print("")
format_string = "".join(formats)
self.blinking.append(f"{format_string}{text}{RESET}\n")
self.line.append(line)
self.collum.append(collum)
def blink_on(self):
write(SAVE_CURSOR)
for index, _ in enumerate(self.blinking):
cursor_position(self.line[index], self.collum[index])
write(self.blinking[index])
write(LOAD_CURSOR)
def blink_off(self):
write(SAVE_CURSOR)
for index, _ in enumerate(self.blinking):
cursor_position(self.line[index], self.collum[index])
write(HT.conceal(self.blinking[index]))
write(LOAD_CURSOR)
HT = Hidden_Text()
BT = Blinking_Text()
blink_speed = 0.5
def blink_loop():
while True:
if BT.blinking:
BT.blink_on()
time.sleep(blink_speed)
BT.blink_off()
time.sleep(blink_speed)
else:
time.sleep(blink_speed)
BLINK_THREAD = threading.Thread(target = blink_loop)
def main():
style("Red Coloured Font", colour_font(255, 0, 0))
style("Red Coloured Background", colour_background(255, 0, 0))
style("Bold Text", BOLD)
style("Italic Text", ITALIC)
style("Underlined Text", UNDERLINE)
style("Inverted Text", INVERT)
HT.conceal("Concealed Text")
HT.conceal("Concealed Blue Text", colour_font(0, 0, 255))
style("Crossed-out Text", CROSS)
style("Bold & Italic Text\n", BOLD, ITALIC)
BT.create_blink("Blinking Text", 11, 0)```
BLINK_THREAD.start()
input("Reveal Concealed Text: ")
cursor_up(1)
write(CLEAR_LINE)
cursor_up(6)
HT.reveal()
HT.reveal()
cursor_down(4)
if __name__ == "__main__":
clear_screen()
main()```
@jolly nexus
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.
๐ Blinking text acting weirdly