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