commit 37b5af8560c52b9ffa2ee0b2411bd763d62f8d49 Author: xenia Date: Thu Oct 12 12:32:32 2023 +0200 Programs diff --git a/ansicols.py b/ansicols.py new file mode 100644 index 0000000..709c330 --- /dev/null +++ b/ansicols.py @@ -0,0 +1,74 @@ +import os, random, math + +# From http://stackoverflow.com/a/566752/1753929 +def getTerminalSize(): + import os + env = os.environ + def ioctl_GWINSZ(fd): + try: + import fcntl, termios, struct, os + cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, + '1234')) + except: + return + return cr + cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2) + if not cr: + try: + fd = os.open(os.ctermid(), os.O_RDONLY) + cr = ioctl_GWINSZ(fd) + os.close(fd) + except: + pass + if not cr: + cr = (env.get('LINES', 25), env.get('COLUMNS', 80)) + + ### Use get(key[, default]) instead of a try/catch + #try: + # cr = (env['LINES'], env['COLUMNS']) + #except: + # cr = (25, 80) + return int(cr[1]), int(cr[0]) + + +os.system("clear") + +styles = { + "Bold & Bright": "1", + "Dim": "2", + "Underlined": "4", + "Blink": "5", + "Inverted": "7", + # "Hidden": "8", wont be visible :( + "Reset": "0" +} + +print("\033[1mStyles:\033[0m") + +styleSpace = max(list(map(len, styles))) + +print("|", end=' ') + +for style in sorted(styles): + text = "\033[" + styles[style] + "m" + style + "\033[0m" + " \\033[" + styles[style] + "m" + print(" " * int(math.floor((styleSpace - len(text)) / 2.0)) + text + " " * int(math.ceil((styleSpace - len(text)) / 2)) + " |", end=' ') +print() + + +print("\n") + +print("".join(["\033[38;5;" + str(random.randrange(0, 255)) + "m" + letter for letter in "Colors:"])) + +numsPerLine = getTerminalSize()[0] / 18 + +for colorType in [38, 48]: + currentNumsPerLine = 0 + for color in range(256): + esc = "[" + str(colorType) + ";5;" + str(color) + "m" + print("\033" + esc + "\\033" + esc + "\033[0m\t", end=' ') + currentNumsPerLine += 1 + if currentNumsPerLine > numsPerLine: + print() + currentNumsPerLine = 0 + + print("\033[0m\n") diff --git a/ansimove.py b/ansimove.py new file mode 100644 index 0000000..8779255 --- /dev/null +++ b/ansimove.py @@ -0,0 +1,25 @@ +# Please don't try to understand this mess, it's not worth it. +# Colors: +# Headlines - 178 & Bold +# \033 - 122 +# - 125 & Bold +# - 166 +# - 161 & Bold +# Other words - 201 +print("\033[1m\033[38;5;178mPosition the cursor:\033[0m") +print("\t\t\033[38;5;122m\\033[\033[38;5;125m\033[1m\033[0m\033[38;5;122m;\033[38;5;166m\033[1m\033[0m\033[38;5;122mH\033[0m") +print("\t\t\t\033[38;5;201mOr") +print("\t\t\033[38;5;122m\\033[\033[38;5;125m\033[1m\033[0m\033[38;5;122m;\033[38;5;166m\033[1m\033[0m\033[38;5;122mf\033[0m") + +print("\033[1m\033[38;5;178mMoving the cursor:\033[0m") +print(" \033[38;5;201mUp:\t\t\033[38;5;122m\\033[\033[38;5;161m\033[1m\033[0m\033[38;5;122mA") +print(" \033[38;5;201mDown:\t\033[38;5;122m\\033[\033[38;5;161m\033[1m\033[0m\033[38;5;122mB") +print(" \033[38;5;201mRight:\t\033[38;5;122m\\033[\033[38;5;161m\033[1m\033[0m\033[38;5;122mC") +print(" \033[38;5;201mLeft:\t\033[38;5;122m\\033[\033[38;5;161m\033[1m\033[0m\033[38;5;122mD") + +print("\033[1m\033[38;5;178mClear the screen, move cursor to (0,0):") +print("\t\t\033[38;5;122m\\033[2J") + +print("\033[1m\033[38;5;178mErase to end of line") +print("\t\t\033[38;5;122m\\033[K") +