具有象素抽象的终端I/O
termpixels的Python项目详细描述
术语像素
终端作为字符单元矩阵
得到它
或者,克隆此存储库并在根目录中pip install -e .
。
需要Python3和无依赖关系*!
*需要^{
目的
创建在终端内部运行的程序似乎很复杂。TermPixels的目标是将终端抽象为一个二维“像素”数组或字符单元格,每个单元格包含一个文本字符、一个前景色和一个背景色。TermPixels允许您随时随地修改屏幕内容,然后处理自动更新终端,以及简化复杂的终端输入处理。
最终,这个项目试图使终端更容易访问和更有趣。
限制
有很多很棒的库可以为终端输出着色。这是,专为完全控制屏幕内容的全屏应用程序设计。这意味着它,例如,自动保存和清除屏幕,重置光标位置,并接受CBREAK模式下的输入。
这不是简单地打印彩色文本的最佳解决方案,尽管you can do that if you want。
演示
fromtermpixelsimportApp,ColorfromtimeimporttimefrommathimportsinclassFunTextApp(App):defon_frame(self):self.screen.clear()# remove everything from the screentext="Hello world, from termpixels!"fori,cinenumerate(text):f=i/len(text)color=Color.hsl(f+time(),1,0.5)# create a color from a hue valuex=self.screen.w//2-len(text)//2# horizontally center the textoffset=sin(time()*3+f*5)*2# some arbitrary mathy=round(self.screen.h/2+offset)# vertical center with an offsetself.screen.print(c,x+i,y,fg=color)# draw the text to the screen bufferself.screen.update()# commit the changes to the screenif__name__=="__main__":FunTextApp().start()
更多演示
功能
- unix(和mac)使用terminfo进行终端功能检测(通过pythoncurses)
- windows通过win32控制台api支持
- 终端(re)大小检测
- 异步输入
- 键盘支持特殊键的输入,如箭头、功能键、转义键等。
- 鼠标在支持xterm鼠标的终端中单击、滚动和移动输入
- 16、256和真color输出(检测最佳支持模式)
- 在任何地方显示光标(或隐藏它!)
- 使用备用屏幕缓冲区保留用户终端的状态。
- 对fullwidth字符的基本支持。
- 除了terminfo查找之外,不依赖ncurses
- 100%Python
- 更多