ANSI ターミナルのエスケープシーケンスを簡単なライブラリにしてみました。
エスケープシーケンスをそのまま書くのはあまりにも判りづらいから、ニモニックにしていただけると幸いです。
全てはカバーしていませんが、よく使うであろうと思われる主要なものを関数化しています。
リファレンス:
escseq.py
#!/usr/bin/python3
ESC='\033['
def escup(n=1):
print(f"{ESC}{n}A",end='')
def escdown(n=1):
print(f"{ESC}{n}B",end='')
def escright(n=1):
print(f"{ESC}{n}C",end='')
def escleft(n=1):
print(f"{ESC}{n}D",end='')
def esclocate(x=0,y=0):
print(f"{ESC}{y+1};{x+1}H",end='',flush=True)
def escscrollup(n=1):
print(f"{ESC}{n}S",end='')
def escscrolldown(n=1):
print(f"{ESC}{n}T",end='')
def escclear():
print(f"{ESC}2J",end='')
esclocate()
def esccolor(col1=7,col2=0):
print(f"{ESC}3{col1}m{ESC}4{col2}m",end='')
def escresetcolor():
print(f"{ESC}0m",end='')
if __name__=="__main__":
escclear()
for i in range(8):
for j in range(8):
esccolor(j,i)
print("#",end='')
escresetcolor()