main
xenia 2023-10-12 12:32:32 +02:00
commit 37b5af8560
2 changed files with 99 additions and 0 deletions

74
ansicols.py 100644
View File

@ -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")

25
ansimove.py 100644
View File

@ -0,0 +1,25 @@
# Please don't try to understand this mess, it's not worth it.
# Colors:
# Headlines - 178 & Bold
# \033 - 122
# <line> - 125 & Bold
# <col> - 166
# <N> - 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<line>\033[0m\033[38;5;122m;\033[38;5;166m\033[1m<col>\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<line>\033[0m\033[38;5;122m;\033[38;5;166m\033[1m<col>\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<N>\033[0m\033[38;5;122mA")
print(" \033[38;5;201mDown:\t\033[38;5;122m\\033[\033[38;5;161m\033[1m<N>\033[0m\033[38;5;122mB")
print(" \033[38;5;201mRight:\t\033[38;5;122m\\033[\033[38;5;161m\033[1m<N>\033[0m\033[38;5;122mC")
print(" \033[38;5;201mLeft:\t\033[38;5;122m\\033[\033[38;5;161m\033[1m<N>\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")