0xh*_*hes 2 python bash terminal menu
我有一个广泛使用Python(2.*flavors)的项目,我想知道是否有终端菜单库或者那种效果?我希望通过使用箭头键高亮显示选项,某些颜色等简化一些选项来为我的脚本注入一些味道和生活.我隐约回想起有一种方法来制作一个bash shell终端菜单但我不在我确定如何将用户输入从bash传递给python脚本,也许有一个bash终端菜单用sysarggs推送脚本调用?如果可能的话,我想在python方面做点什么.有什么建议?
这也是一个随机的问题,因为我们讨论的是终端美学的主题,处理计数器的最佳方法是什么呢?我的脚本查找图像文件,然后当它找到一个它清除终端时,通过子进程调用清除然后打印出再次找到IE 10图像的总图像,找到一个,清除,打印"找到11个图像",有时我的脚本工作真快,我感觉到这种不利表现.思考?
非常感谢大家,我喜欢堆栈溢出;)
编辑 - 感谢所有快速回复!我有很多选择可以考虑.我给了每个人一个upvote,因为你的所有回复都很有帮助.当我回到家时,我会检查所有的图书馆并尝试根据最好的东西选择你们中的一个,但是我希望我能挑选你们,因为你们所有的答案都是相关的!非常感谢人们.我将在下班回家后报告,并有机会获得一些编码;)
编辑2 - 对计数器/进度显示的澄清,寻找一种方法来防止这种情况,当我的脚本在很短的时间内发现成千上万的图像时,这不会损害性能,这是真正的切碎python ...
for each item in list:
if item ends with .jpg
cnt=cnt+1
do stuff with image file
subprocess.call('clear')
print str(cnt)+" total images processed."
Run Code Online (Sandbox Code Playgroud)
再次感谢!
查看Clint(*C*ommand*L*ine*IN*terface*T*ools)!
示例颜色:
from clint.textui import colored
print 'I love ' + colored.yellow('pyt') + colored.blue('hon')
Run Code Online (Sandbox Code Playgroud)
和缩进:
from clint.textui import colored, indent, puts
with indent(3, quote=colored.red(' >')):
puts ('some random text')
puts ('another text')
with indent(3, quote=colored.green(' |')):
puts('some more nested identation')
puts('cool isn\'t?')
Run Code Online (Sandbox Code Playgroud)
PS同一位作者写了一个名为"requests"的类似的HTTP请求库:https://github.com/kennethreitz/requests
| 归档时间: |
|
| 查看次数: |
3740 次 |
| 最近记录: |