纯python寻呼机(比如“更多”和“更少”)。

pypager的Python项目详细描述


a$纯python中的寻呼机

pip install pypager

pypager可以用作独立的应用程序,也可以用作库。

什么是寻呼机?

寻呼机是一种终端程序,可以用来查看文件的内容, 或者其他应用程序的输出流。

例如,当我们运行man vim时,实际内容显示在 寻呼机,根据$PAGER环境变量。

对于寻呼机来说,重要的是输入可以流式传输。例如当我们 执行find / | pypager;我们不想等待整个文件系统 在显示任何东西之前被遍历。只从输入中读取数据 管道,当它需要显示时。

常用的寻呼机应用程序有morelessmost

功能

  • 突出显示文本[0]。
  • 正在搜索。
  • 实现了来自less的许多键绑定。

[0]它理解手册页、ANSI转义代码的输出,而且 可以使用pygments突出显示任何文件。)

用法

# Install it.
pip install pypager

# Tell the environment to use this pager. Put the following line in
# ~/.bashrc if you like.
exportPAGER=pypager

# Following commands, and many others should pick up the pager.
man vim
git diff

# View a file, using this pager.
pypager some_source_code.py

作为库

frompypager.sourceimportGeneratorSourcefrompypager.pagerimportPagerfromprompt_toolkit.tokenimportTokendefgenerate_a_lot_of_content():"""
    This is a function that generates content on the fly.
    It's called when the pager needs to display more content.
    """counter=0whileTrue:yield[(Token,'line: %i\n'%counter)]counter+=1if__name__=='__main__':source=GeneratorSource(generate_a_lot_of_content())p=Pager(source)p.run()

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java FloatingAction按钮与RecyclerView中的CardView重叠   java如何计算CardLayout中的卡数   从远程系统上传MySQL数据库并访问Java应用程序   java调用堆栈如何处理带或不带返回类型的递归?   Springboot中的java组计数聚集   java如何在javafx textarea中使用richtextfx   获取与Mockito相关的错误时出现Java问题   java如何将JaxRS响应转换为Wiremock响应   Hadoop集群java。net ConnectionException:连接被拒绝错误   java如何加载文件私有文件类型是pem   java在元空间中的提升和加载的类   如何将系统属性传递给从HTML启动的Java小程序   java如何从网页中获取值并在主类中使用它?安卓应用   java在春天,advisor和aspect之间有什么区别?   java如何检测文件是否已重命名?   java消息驱动Bean何时使用