[英]tput cup in python on the commandline
是否有一個優雅的解決方案可以在不導入操作系統的情況下在 Python 中執行此 shell 腳本?
tput cup 14 15; echo -ne "\033[1;32mtest\033[0m" ; tput cup 50 0
這已經在我腦海中縈繞了一段時間:)
謝謝
感謝 Ignacio Vazquez-Abrams 的投入,這是朝着正確方向邁出的一大步。 最后我想出了這個小代碼,它將幫助我征服世界:)
from curses import *
setupterm()
#cols = tigetnum("cols")
#lines = tigetnum("lines")
#print str(cols) + "x" + str(lines)
place_begin = tparm(tigetstr("cup"), 15, 14)
place_end = tparm(tigetstr("cup"), 50, 0)
print place_begin + "-- some text --" + place_end
@TZ.TZIOY,謝謝,我認為使用 stdout 而不是使用 print 確實是一個更好的解決方案。
所有 terminfo 功能都可以通過curses
訪問。 初始化它並使用curses.tiget*()
來獲取您關心的功能。
鑒於
tput cup 14 15 | cat -v
tput cup 14 15 | cat -v
顯示^[[15;16H
整個建議的腳本導致以下 Python 腳本:
import sys
sys.stdout.write("\033[15;16H\033[1;32mtest\033[m\033[51;1H")
# and a possible sys.stdout.flush() here, depending on your needs
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.